Building a Conversational Bot: From 0 to...
Transcript of Building a Conversational Bot: From 0 to...
![Page 1: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/1.jpg)
![Page 2: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/2.jpg)
![Page 3: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/3.jpg)
![Page 4: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/4.jpg)
![Page 5: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/5.jpg)
![Page 6: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/6.jpg)
![Page 8: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/8.jpg)
Skype,
Web, email, Facebook, GroupMe,
Kik,
Slack,
Telegram,
Twilio,
direct line app integration.
MS Bot Framework
![Page 9: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/9.jpg)
Overview http://docs.botframework.com
Options:
• Connector
• Builder
• Directory
![Page 10: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/10.jpg)
Chat Bot
(Bot Framework) CONNECTOR
Connector Service Flow.Channels
Routes messages
manages state
bot registration
Tracking
services (such as translation) and
per-user and per-bot storage
Web Service
HTTPS only
ASP.NET or Node.js
![Page 11: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/11.jpg)
▪
http://www.visualstudio.com
▪
http://aka.ms/bf-bc-vstemplate
▪
https://download.botframework.com/botconnector/tools/emulator/publish.htm
Installing Tools
![Page 12: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/12.jpg)
자세한내용은 Github
![Page 13: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/13.jpg)
Connector, Activities & Messages
Connector The Connector (or Connector Service) handles all
communication, conversations, state, and
authorization for all activities between a Bot and Users.
Activity An Activity is a specific event that occurs between a
Bot and Users, such as an actual message, or
conversation notification.
Message A Message is an overt (typically visible)
communication between a Bot and Users, such as a
User asking a question, or a Bot responding with a
reply.
![Page 14: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/14.jpg)
Chat Bot
(Bot Framework) CONNECTOR
Connector Service Flow.Channels
Routes messages
manages state
bot registration
Tracking
services (such as translation) and
per-user and per-bot storage
Web Service
HTTPS only
ASP.NET or Node.js
HTTPS
JSON
![Page 15: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/15.jpg)
Your bot
{"type": "Message","id": "68YrxgtB53Y","conversationId": "DphPaFQrDuZDKyCez4AFGcT4vy5aQDje1lLGIjB8v18MFtb","language": "en","text": "You can say \"/order\" to order!","attachments": [ ],"from": {
"name": "+12065551212","channelId": "sms","address": "+12065551212","id": "Ro52hKN287","isBot": false
},"channelData": { SMS data here },"botUserData": { your data here },...
}
Bot Connector
![Page 16: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/16.jpg)
Connector
Namespace: Microsoft.Bot.Connector
ConnectorClient connector = new ConnectorClient(
new Uri(activity.ServiceUrl));
string message = string.Format("{0}을 주문 받았습니다. 감사합니다.",
activity.Text);
// return our reply to the user
Activity reply = activity.CreateReply(message);
await connector.Conversations.ReplyToActivityAsync(reply);
![Page 17: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/17.jpg)
Activity Type Description
Message Sent when general content is passed to or from a user
and a bot
Conversation Update Sent when the conversation's properties change, for
example the topic name, or when user joins or leaves
the group
Contact Relation Update Sent when bot added or removed to contact list
Delete User Data Send when user is removed from a conversation
Typing Sent when a user is typing
Ping Send when a keep-alive is needed
Types of Activities
![Page 18: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/18.jpg)
Activities Types
switch (activity.GetActivityType())
{
case ActivityTypes.Message:
message = string.Format("{0}을 주문 받았습니다. 감사합니다
reply = activity.CreateReply(message);
await connector.Conversations.ReplyToActivityAsync(reply);
break;
case ActivityTypes.ConversationUpdate:
message = string.Format("안녕하세요 만리장성 봇 입니다. 주문하실
reply = activity.CreateReply(message);
![Page 19: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/19.jpg)
case ActivityTypes.ConversationUpdate:
message = string.Format("안녕하세요 만리장성 봇 입니다. 주문하실 메뉴를
reply = activity.CreateReply(message);
await connector.Conversations.ReplyToActivityAsync(reply);
break;
case ActivityTypes.ContactRelationUpdate:
case ActivityTypes.Typing:
case ActivityTypes.DeleteUserData:
default:
break;
}
![Page 20: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/20.jpg)
Not all Bots require state management outside of what the Connector provides inherently, however if you need to manage state, there are
various methods.
Managing State
![Page 21: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/21.jpg)
Chat Bot
(Bot Framework) CONNECTOR
Connector Service Flow.
Channel ID
State
자장면짬뽕탕수육
.
.
.
Web Service
HTTPS only
ASP.NET or Node.js
User ID
StateClient
MENU
![Page 22: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/22.jpg)
StateClient
StateClient stateClient = activity.GetStateClient();
BotData userData = await stateClient.BotState.GetUserDataAsync(
activity.ChannelId, activity.From.Id);
string menu = activity.Text;
menu += userData.GetProperty<string>("MENU") + ",";
userData.SetProperty<string>("MENU", menu);
await stateClient.BotState.SetUserDataAsync(
activity.ChannelId, activity.From.Id, userData);
reply = activity.CreateReply("주문내역:" + menu);
await connector.Conversations.ReplyToActivityAsync(reply);
![Page 23: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/23.jpg)
StateClient
case ActivityTypes.DeleteUserData:
await stateClient.BotState.DeleteStateForUserAsync
(activity.ChannelId, activity.From.Id);
break;
![Page 24: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/24.jpg)
Dialogs are a way of wrapping an entire “experience” into an easily managed
interaction based on a “chained” and “conversational” paradigm.
Using Dialogs
![Page 25: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/25.jpg)
Chat Bot
(Bot Framework) CONNECTOR
Connector Service Flow.
State
자장면짬뽕탕수육
.
.
.
Web Service
HTTPS only
ASP.NET or Node.js
Dialog
![Page 26: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/26.jpg)
Dialog
Namespace: Microsoft.Bot.Builder.Dialogs
[Serializable]
public class EchoDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable
{
context.Wait(MessageReceivedAsync);
}
![Page 27: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/27.jpg)
Dialog
Namespace: Microsoft.Bot.Builder.Dialogs
[Serializable]
public class EchoDialog : IDialog<object>
{
public async Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
}
public async Task MessageReceivedAsync(IDialogContext context, IAwaitable
{
context.Wait(MessageReceivedAsync);
}
![Page 28: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/28.jpg)
Although Dialogs are the basic building block of a conversation, it’s difficult to
create a “guided” conversation. FormFlow creates Dialogs and guides a User
through filling in a “form” while providing help and guidance along the way.
Using Forms with FormFlow
![Page 29: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/29.jpg)
Chat Bot
(Bot Framework) CONNECTOR
Connector Service Flow.
State
자장면짬뽕탕수육
.
.
.
Web Service
HTTPS only
ASP.NET or Node.js
FormFlow
![Page 30: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/30.jpg)
FormFlowNamespace: Microsoft.Bot.Builder.FormFlow
[Serializable]
public class FoodOrder
{
public FooldOptions? Food;
public LengthOptions? Length;
public static IForm<FoodOrder> BuildForm()
{
return new FormBuilder<FoodOrder>()
.Message("만리장성에 오신 여러분을 환영합니다.")
.Build();
}
![Page 31: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/31.jpg)
FormFlowNamespace: Microsoft.Bot.Builder.FormFlow
public enum FooldOptions
{
자장면, 짬뽕, 탕수육, 기스면, 란자완스
};
public enum LengthOptions { 보통, 곱배기};
![Page 32: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/32.jpg)
Azure Function
![Page 33: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/33.jpg)
Azure Search
![Page 34: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/34.jpg)
LUIS is part of Microsoft Cognitive Services offering and can be used for any device, on any platform, and any application scenario.
Integrating Language Understanding Intelligence Services
![Page 35: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/35.jpg)
Language
Speech
Search
Machine Learning
Knowledge Vision
Spell check
Speech API
Entity linking
Recommendation API
Bing autosuggest
Computer vision
Emotion
Forecasting
Text to speech
Thumbnail generation
Anomalydetection
Custom recognition (CRIS)
Bing image search
Web language model
Customer feedback analysis
Academic knowledge
OCR, tagging, captioning
Sentiment scoring
Bingnews search
Bingweb search
Text analytics
Cognitive Services APIs
![Page 36: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/36.jpg)
Your conversation logic
Logic
Web service
LUIS
![Page 38: Building a Conversational Bot: From 0 to 60download.microsoft.com/download/1/5/D/15DC2FA2-8B98-4F20-9ED8-4B99E68FD67D/2-1...Activity Type Description Message Sent when general content](https://reader030.fdocuments.in/reader030/viewer/2022041019/5ecd3ff9c59797419458506b/html5/thumbnails/38.jpg)