Bot Connector
using Microsoft.Bot.Connector;
[BotAuthentication]
public class MessagesController : ApiController
{
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
var replyMSG = $"You said {activity.Text}.");
Activity reply = activity.CreateReply(replyMSG);
await connector.Conversations.ReplyToActivityAsync(reply);
}
else
HandleSystemMessage(activity);
return Request.CreateResponse(HttpStatusCode.OK);
}
}
}
var restify = require('restify');
var builder = require('../../core/');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector, function (session) {
var replyMSG = "You said: %s", session.message.text;
session.send(replyMSG);
}); https://github.com/Microsoft/BotBuilder/blob/master/Node/examples/hello-ChatConnector
Wanne learn
more?
http://botframework.com
Wanne know it
all?
http://github.com/Microsoft/botbuilder
Augment intelligence with Cognitive Services
API: “INVITE GUEST FOR TOMORROW”
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/
<subscription>?subscription-
key=<key>&timezoneOffset=0&verbose=true&
q=register%20guest%20for%20tomorrow
{
"query": "register a guest for tomorrow",
"topScoringIntent": {
"intent": "MSFTNLBot.RegisterGuest",
"score": 0.9989265,
"actions": [
{
"triggered": true,
"name": "MSFTNLBot.RegisterGuest",
"parameters": []
}
]
},
"intents": [
...
{
"intent": "MSFTNLBot.ParkingPlaces",
"score": 0.0008436582
},
},
...
],
"entities": [
{
"entity": "tomorrow",
"type": "builtin.datetime.date",
"startIndex": 21,
"endIndex": 28,
"resolution": {
"date": "2017-05-17"
}
}
]
}
http://luis.ai
Config & Train:
Outcome:
Detect
Language
Store
Language
in bot
state
Translate
to English
Do
actions
based on
English
Create
Response
Translate
to original
language
Respond
translate
response
{
await SendTyping(activity);
var translator = new Translator();
var lang = translator.Detect(activity.Text);
//set User in State
StateClient stateClient = activity.GetStateClient();
BotData userData = await stateClient.BotState.
GetUserDataAsync(activity.ChannelId, activity.From.Id);
userData.SetProperty<string>("originalLanguage", lang);
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id,
userData);
activity.Text = translator.Translate(activity.Text, lang, "en");
var dialog = new CustomLuisDialogML();
await Conversation.SendAsync(activity, () => dialog);
}
[LuisIntent("Greeting")]
public async Task Greeting(IDialogContext context, LuisResult result)
{
var lang = OriginalLanguage;
context.UserData.TryGetValue<string>("originalLanguage", out lang);
string msg = "Hi, nice that you contacted the PA of Sander. What can I do for you?n";
string speakmsg = msg;
msg += "You can ask me where Sander is and how the weather is at his location.";
var translatedMsg = Translator.GetTransMsg(msg, lang);
await context.SayAsync(translatedMsg, speakmsg);
context.Wait(MessageReceived);
}
string msg = "";
var sentimentScore = await Psychologist.GetSentiment(result.Query);
if (sentimentScore > 0.7) //Positive
{
msg = $"That's great to hear!";
}
else if (sentimentScore < 0.3) //Negative
{
msg = $"I'm sorry to hear that. I hope that we can improve.";
}
else //No opinion
{
msg = $"I see, Will to try to get better.";
}
I want to book room
for tomorrow at 9
Room 123 is available.
Shall I book it?
Yes
Room is booked for
you
Show my VMs
You have the following
5 VMs …
… [time passes]
VM ‘Linux01’ runs out of Mem.
Shall I increase Mem size to 8 GB?
Yes
VM ‘Linux01’ is upgraded and runs
smoothly again.
Bot
I want to book my
time for this week Ok, What hours for
Monday?
8 for Project X
Booked. What hours
for Monday?
6 for Project X, 2
for Meetings Your new PC has arrived, do
you want to pick it up?
Huh %-)?
Proactive
Message
Message
Handler
Chat Conversation
BotUser
Dialog
Stack
Proactive
Bot
Random Message "hi"
Error "Start Dialog"
"Start TimeSheet" Start Dialog
"Add 8 hour for today"
Sent Reply "Hours Added"
Reply "Dialog Started"
Check if dialog exist
Return True
Check if dialog exist
Return False
Sent Normal Notification "Your coffee is ready?"
Stack Notification 1
Sent Interrupt Notification "Building is on Fire"
Stack Notification "Fire"
"Stop"
Remove Dialog
loop while notifications
Get Paused Notification
Notification
Sent Notification
Get Paused Notification
Notification
You need a dialog
manager
http://github.com/microsoft/botbuilder
http://developer.microsoft.com/cortana
https://github.com/alyssaong1/Bot-Framework-HOL
Detect
Language
Store
Language
in bot
state
Translate
to English
Do
actions
based on
English
Create
Response
en
Translate
to original
language
Respond
translate
response
Create
Respons
e
nl
Respond
Create
Respons
e
es
Respond

Building multi lingual and empatic bots - Sander van den Hoven - Codemotion Amsterdam 2017

  • 6.
  • 7.
    using Microsoft.Bot.Connector; [BotAuthentication] public classMessagesController : ApiController { public async Task<HttpResponseMessage> Post([FromBody]Activity activity) { if (activity.Type == ActivityTypes.Message) { ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); var replyMSG = $"You said {activity.Text}."); Activity reply = activity.CreateReply(replyMSG); await connector.Conversations.ReplyToActivityAsync(reply); } else HandleSystemMessage(activity); return Request.CreateResponse(HttpStatusCode.OK); } } }
  • 8.
    var restify =require('restify'); var builder = require('../../core/'); // Setup Restify Server var server = restify.createServer(); server.listen(process.env.port || process.env.PORT || 3978, function () { console.log('%s listening to %s', server.name, server.url); }); // Create chat connector for communicating with the Bot Framework Service var connector = new builder.ChatConnector({appId: process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD }); // Listen for messages from users server.post('/api/messages', connector.listen()); // Create your bot with a function to receive messages from the user var bot = new builder.UniversalBot(connector, function (session) { var replyMSG = "You said: %s", session.message.text; session.send(replyMSG); }); https://github.com/Microsoft/BotBuilder/blob/master/Node/examples/hello-ChatConnector
  • 9.
  • 10.
  • 12.
    Augment intelligence withCognitive Services
  • 13.
    API: “INVITE GUESTFOR TOMORROW” https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/ <subscription>?subscription- key=<key>&timezoneOffset=0&verbose=true& q=register%20guest%20for%20tomorrow { "query": "register a guest for tomorrow", "topScoringIntent": { "intent": "MSFTNLBot.RegisterGuest", "score": 0.9989265, "actions": [ { "triggered": true, "name": "MSFTNLBot.RegisterGuest", "parameters": [] } ] }, "intents": [ ... { "intent": "MSFTNLBot.ParkingPlaces", "score": 0.0008436582 }, }, ... ], "entities": [ { "entity": "tomorrow", "type": "builtin.datetime.date", "startIndex": 21, "endIndex": 28, "resolution": { "date": "2017-05-17" } } ] } http://luis.ai Config & Train: Outcome:
  • 14.
    Detect Language Store Language in bot state Translate to English Do actions basedon English Create Response Translate to original language Respond translate response
  • 15.
    { await SendTyping(activity); var translator= new Translator(); var lang = translator.Detect(activity.Text); //set User in State StateClient stateClient = activity.GetStateClient(); BotData userData = await stateClient.BotState. GetUserDataAsync(activity.ChannelId, activity.From.Id); userData.SetProperty<string>("originalLanguage", lang); await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); activity.Text = translator.Translate(activity.Text, lang, "en"); var dialog = new CustomLuisDialogML(); await Conversation.SendAsync(activity, () => dialog); }
  • 16.
    [LuisIntent("Greeting")] public async TaskGreeting(IDialogContext context, LuisResult result) { var lang = OriginalLanguage; context.UserData.TryGetValue<string>("originalLanguage", out lang); string msg = "Hi, nice that you contacted the PA of Sander. What can I do for you?n"; string speakmsg = msg; msg += "You can ask me where Sander is and how the weather is at his location."; var translatedMsg = Translator.GetTransMsg(msg, lang); await context.SayAsync(translatedMsg, speakmsg); context.Wait(MessageReceived); }
  • 18.
    string msg =""; var sentimentScore = await Psychologist.GetSentiment(result.Query); if (sentimentScore > 0.7) //Positive { msg = $"That's great to hear!"; } else if (sentimentScore < 0.3) //Negative { msg = $"I'm sorry to hear that. I hope that we can improve."; } else //No opinion { msg = $"I see, Will to try to get better."; }
  • 20.
    I want tobook room for tomorrow at 9 Room 123 is available. Shall I book it? Yes Room is booked for you Show my VMs You have the following 5 VMs … … [time passes] VM ‘Linux01’ runs out of Mem. Shall I increase Mem size to 8 GB? Yes VM ‘Linux01’ is upgraded and runs smoothly again.
  • 21.
    Bot I want tobook my time for this week Ok, What hours for Monday? 8 for Project X Booked. What hours for Monday? 6 for Project X, 2 for Meetings Your new PC has arrived, do you want to pick it up? Huh %-)? Proactive Message Message Handler Chat Conversation
  • 22.
    BotUser Dialog Stack Proactive Bot Random Message "hi" Error"Start Dialog" "Start TimeSheet" Start Dialog "Add 8 hour for today" Sent Reply "Hours Added" Reply "Dialog Started" Check if dialog exist Return True Check if dialog exist Return False Sent Normal Notification "Your coffee is ready?" Stack Notification 1 Sent Interrupt Notification "Building is on Fire" Stack Notification "Fire" "Stop" Remove Dialog loop while notifications Get Paused Notification Notification Sent Notification Get Paused Notification Notification You need a dialog manager
  • 24.
  • 26.
    Detect Language Store Language in bot state Translate to English Do actions basedon English Create Response en Translate to original language Respond translate response Create Respons e nl Respond Create Respons e es Respond

Editor's Notes

  • #4 Note: Present the Personal PA What is meaning of Life, Universe and Everything (T-Shirts)? Answer I do now know why 42 (in slack , cortana) Ask Where is Sander, what is the weather Skype, Messenger, Web Chat, Cortana Present the Parking Bot Can I Park , How is the Weather Do it with Skype, Messenger, Web Chat, Cortana Present the Office Bot Show that a form is possible Invite a Guest Show interaction to webapp
  • #7 Go to the bot connector Botframework.com as svandenhoven@Hotmail.com Show the channels Show the settings and the endpoint
  • #13 Vision Computer Vision API: Distill actionable information from images Emotion API: Personalize experiences with emotion recognition Face API: Detect, identify, analyze, organize, and tag faces in photos Video API: Analyze, edit, and process videos within your app Speech Bing Speech API: Convert speech to text and back again, and understand its intent Custom Recognition Intelligent Service (CRIS): Fine-tune speech recognition for anyone, anywhere Speaker Recognition API: Give your app the ability to know who’s talking Language: Bing Spell Check API: Detect and correct spelling mistakes within your app Language Understanding Intelligent Service (LUIS): Teach your apps to understand commands from your users Linguistic Analysis API: Easily parse complex text with language analysis Text Analytics API: Detect sentiment, key phrases, topics, and language from your text Web Language Model API: Leverage the power of language models trained on web-scale data Knowledge Academic Knowledge API: Explore relationships among academic papers, journals, and authors Entity Linking Intelligence Service: Contextually extend knowledge of people, locations, and events Knowledge Exploration Service: Add interactive search over structured data to your project Recommendations API: Provide personalized product recommendations for your customers Search: Bing Autosuggest API: Give your app intelligent autosuggest options for searches Bing Image Search API: Bing advanced image and metadata search to your app. Bing News Search API: Link your users to robust and timeline news searches Bing Video Search API: Trending videos, detailed metadata, and rich results Bing Web Search: Connect powerful search to your apps
  • #14 Do demo: https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/5980d54c-9bbe-4006-8cc2-a2a8bcc37a65?subscription-key=72f7e023d7e94cef8a5684a777504659&timezoneOffset=0&verbose=true&q=register a guest for tomorrow
  • #15 Demo the personal PA bot and translate hi in multiple languages: Hi Hei Ola Merhaba 你好
  • #17 Demo Hi: Hoi, Hei, Ola, 你好, Merhaba How is the weather:
  • #19 Show this with Digital Assistant on Cortana / Messenger
  • #24 Show in Skype Say Hi Sent a message via commandline “your pizza has arrived, high” Sent a message via commandline “your PC in ready, low” Make dialog /Start Pretent to fill in hours : Day 1, Day2 Sent a message via commandline “your PC in ready, low” Continue filling in hours Stop dialog and show that paused message is received