標籤:
微軟在Build2016大會上表示,未來將是一個充滿聊天機器人的世界,為此他們推出了微軟Bot Framework,能夠允許任何人製作自己的聊天機器人,微軟則提供“cognitive microservices”(認知微服務),該工具能夠理解自然語言或者對圖片進行分析,初期開放22個API,可用於整合到應用中。
微軟Bot Framework允許開發人員將自己開發的機器人整合到一系列平台中,例如Skype、Slack、Telegram、電子郵件和網頁等,微軟稱希望所有的開發人員能夠將自己的應用變得更加智能。
打算將BotFramework的學習過程記錄下來。
1、安裝需求
- vs2015(update2以上)
- 更新vs到最新版本
2、下載安裝BotFramework模板
- 下載模板檔案(下載)
- 儲存下載的zip模板檔案到vs2015的模板目錄下(%USERPROFILE%\Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#)
3、開啟vs2015,使用Bot Application 模板建立一個C#項目
4、代碼
[BotAuthentication] public class MessagesController : ApiController { /// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task<Message> Post([FromBody]Message message) { if (message.Type == "Message") { // calculate something for us to return int length = (message.Text ?? string.Empty).Length; // return our reply to the user return message.CreateReplyMessage($"You sent {length} characters"); } else { return HandleSystemMessage(message); } } private Message HandleSystemMessage(Message message) { if (message.Type == "Ping") { Message reply = message.CreateReplyMessage(); reply.Type = "Ping"; return reply; } else if (message.Type == "DeleteUserData") { // Implement user deletion here // If we handle user deletion, return a real message } else if (message.Type == "BotAddedToConversation") { } else if (message.Type == "BotRemovedFromConversation") { } else if (message.Type == "UserAddedToConversation") { } else if (message.Type == "UserRemovedFromConversation") { } else if (message.Type == "EndOfConversation") { } return null; } }View Code
BotFramework學習-01