1. Microsoft Bot Framework
.NET Edition
Jens Siebert (@jens_siebert)
.NET User Group Paderborn, 16. Januar 2018
https://www.slideshare.net/JensSiebert1
2. Chatbots
A chatbot is an application, often available via messaging platforms and
using some form of intelligence, that interacts with a user via a
conversational user interface (CUI).
(Joe Mayo, Programming the Microsoft Bot Framework)
7. Warum sollte ich mich damit beschäftigen?
[…] as messaging apps have grown to dominate both phones and
workplaces, we see conversations with other humans being
supplemented by intelligent chatbots. As these platforms improve, they
will learn to understand the context and intent of conversations,
making interactions more lifelike and therefore more compelling.
The explosion of interest in the marketplace and mainstream media
leads to a corresponding rise in developer interest […]
(ThoughtWorks Technology Radar, Volume 16)
8. Warum sollte ich mich damit beschäftigen?
http://www.businessinsider.de/the-messaging-app-report-2015-11
9. Warum sollte ich mich damit beschäftigen?
https://www.twilio.com/learn/commerce-communications/how-consumers-use-messaging
10. Warum sollte ich mich damit beschäftigen?
https://www.twilio.com/learn/commerce-communications/how-consumers-use-messaging
11. Warum sollte ich mich damit beschäftigen?
https://www.gartner.com/smarterwithgartner/top-trends-in-the-gartner-hype-cycle-for-emerging-technologies-2017/
13. Vorteile und Nachteile
• Konversation: CUIs bieten, durch Nutzung geschriebener oder gesprochener Sprache,
einen natürlicheren Zugang zu Informationen.
• Kontext: Es finden keine Kontextwechsel (z.B. unterschiedliche Bedienparadigmen bei
mobilen Apps) statt.
• Bereitstellung: Die Bereitstellung eines Chatbots ist für den Anwender transparent. Keine
Installation, keine Updates, immer aktuell.
• Geräte-unabhängig: Die Interaktion mit dem Chatbot kann mit allen Geräten erfolgen,
die von einer Messaging-Plattform unterstützt werden.
• Plattform-unabhängig: Die Interaktion mit dem Chatbot kann mit allen Plattformen
erfolgen, die von einer Messaging-Plattform unterstützt werden.
• Notwendigkeit: Es gibt bereits eine erfolgreiche mobile App für einen Service. Welche
Vorteile bringt ein zusätzlicher Chatbot?
• Angemessenheit: Ist ein CUI die angemessene Benutzerschnittstelle für einen Service?
• Kritikalität: Bietet ein Chatbot die richtige Form der Interaktion für einen Service?
14. Bot Builder SDK
Das Microsoft Bot Framework
Bot Builder
.NET
Bot Builder
NodeJS
Bot
Connector
Channels
Azure Bot Service
Chatbot
(ASP.NET/NodeJS)
Backend
Services
AI Services
(LUIS)
15. Das Microsoft Bot Framework
Bot
Connector
Channel Chatbot
Backend
Service
AI Service
Activity
Route
Message
Query
Query
Response
Response
Response
Route
Response
16. Das Microsoft Bot Framework
• Bot Connector Client
• Messages/Activities
• Dialog-Management
• Dialog-Framework (FormFlow)
• State-Management
• GUI-Elemente
• Anbindung an AI-Services (LUIS, Cognitive Services)
19. Quickstart
• Template: ASP.NET MVC Projekt
• NuGet-Pakete: Microsoft.Bot.Builder, Microsoft.Bot.Connector
• Es gibt auch NuGet-Pakete für ASP.NET Core (Projekt manuell anlegen)
20. MessagesController-Klasse
public class MessagesController : ApiController
{
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity,
() => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
[…]
}
ActivityTypes.Message
ActivityTypes.ConversationUpdate
ActivityTypes.ContactRelationUpdate
ActivityTypes.Typing
ActivityTypes.Ping
ActivityTypes.EndOfConversation
ActivityTypes.Trigger
ActivityTypes.Event
ActivityTypes.Invoke
ActivityTypes.DeleteUserData
ActivityTypes.InstallationUpdate
ActivityTypes.MessageReaction
23. RootDialog-Klasse
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
int length = (activity.Text ?? string.Empty).Length;
await context.PostAsync($"You sent {activity.Text} which was {length} characters");
context.Wait(MessageReceivedAsync);
}
}
24. Dialog-basierte Interaktion
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
[…]
}
private async Task MessageReceivedAsync(IDialogContext ctx, IAwaitable<object> result)
{
var activity = await result as Activity;
[…]
IDialogContext
IDialogStackIBotContext
Suspended
Resumed
StartedStartAsync() ctx.Wait()
ctx.Wait()
await result as Activity
ctx.Done()
30. Deklarative Dialog-Programmierung
Enter first name
Enter last name
Enter e-mail
Enter company
name
back()
back()
back()
quit()
quit()
quit()
quit()
help()
reset()
status()
switch()
?
31. FormFlow
[Serializable]
public class ProfileDialogFormFlow
{
[Prompt("Please enter your {&}.")]
public string FirstName { get; set; }
[Prompt("Please enter your {&}.")]
public string LastName { get; set; }
[Describe("E-Mail")]
[Prompt("Please enter your {&}.")]
[Pattern(@".+@.+..+")]
public string EMail { get; set; }
[Describe("Company Name")]
[Prompt("Please enter your {&}. (Current value: "{}")")]
[Optional]
public string Company { get; set; }
public IForm<ProfileDialogFormFlow> BuildForm()
{
return new FormBuilder<ProfileDialogFormFlow>()
.Message("Create a new profile...")
.OnCompletion(ResumeAfterProfileCreationAsync)
.Build();
}
[…]
}
reflection
36. Language Understanding Intelligent Service
https://www.luis.ai
Utterances
„Show me a list of upcoming events“
Intents
„Search“
Entities
SearchOptions
45. Weitere Themen
• State Data Management
• Advanced Message Handling
• Channel-specific Functionality
• Localization
• Hand-off to Human
• Cortana Skills