BotFramework學習-01

來源:互聯網
上載者:User

標籤:

微軟在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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.