Check out the exciting world of Conversation as a Platform (CaaP) and what Microsoft tools are allowing you to create, build and innovate! This tutorial will guide you through making a C# chatbot using the Microsoft Bot Framework SDK and Language Understanding Intelligence Service (LUIS).
2. Kevin Leung
Microsoft Bot Framework
Cognitive Services + LUIS.ai
ASP.NETCore
Internet ofThings
MicrosoftTechnical Evangelist
Follow Me: @KSLHacks
3. Road Map
Why Bots
RealWorld Demo
Microsoft Bot Framework
Building our own bot
Adding Intelligence
Deploying!
4. Why Conversation as a Platform?
“Bots are the new apps,” said Nadella during a
nearly three-hour keynote here that sketched a vision for the
way humans will interact with machines. “People-to-
people conversations, people-to-digital
assistants, people-to-bots and even digital
assistants-to-bots. That’s the world
you’re going to get to see in the
years to come.”
- USATODAY
“Microsoft CEO Satya Nadella says future belongs to bots”
6. Microsoft Bot Framework
■ Supports NodeJS and C# .NET
■ Lead users through conversation
– Prompts, Choices, Media, Rich Cards (Displays)
■ Bot Emulator provided for local development/testing
■ Easy to incorporate Natural Language Processing (Cognitive Services)
■ Easily deploy to Azure Cloud Services
7. Connectors and Benefits
■ Connector to Platform Channels
– One Bot : Many Channels and endpoints
■ Why restrict yourself to one platform?
– Hit them all
■ Half the battle is getting users to download your app.
– They already have these installed
9. Getting Started
1. Download the Bot ApplicationTemplate here: http://aka.ms/bf-bc-vstemplate
2. Save zip file toVisual Studio templates directory
3. OpenVisual Studio
4. Create newVisual C# project using the Bot ApplicationTemplate
10. Testing out theTemplate
1. Download the Bot Framework Emulator here: https://emulator.botframework.com/
1. More info: https://docs.botframework.com/en-us/tools/bot-framework-emulator/
2. Run the project inVisual Studio
3. Check the localhost in the browser that opens
4. Enter the same local host PORT and press Connect
13. RootDialog.cs
1. Inherit from IDialog<object>
2. Implement StartAsync() method
1. Welcome our users
3. Create a new method to display a prompt after the greeting message
14. RootDialog.cs - Prompting Choice
1. Add strings which will become your option choices for the user
2. PromptDialog.Choice will present option buttons to the user
17. LUIS.ai
■ Language Understanding Intelligence Service (LUIS)
■ Natural Language Processing (NLP)
– Using artificial intelligence to process natural language
■ Extract Intents (meaning of the utterance)
■ Extract Entities (items in the utterance that are of value)
■ This is a huge problem developers working with AI or human speech encounter
– Cognitive Services: LUIS abstracts this into a training model
19. Creating a LUIS model
1. Head over to luis.ai
2. Log in with your Microsoft live account
3. Create a new model
1. You will need an Azure account to create a ‘Cognitive Service’ service
2. This will provide you with a Key. (free, but need to get it through Azure Portal)
23. Add new Intent + Entity
1. Created new Intent ‘UpdateTwitter’
2. Clicked on the ‘@’ and ‘kslhacks’, entered a new entity name and press ‘create’
24. Training Intent and Entity
1. Select all other entities and label them accordingly..
2. You can now select from the created entity
25. Training Intent and Entity
■ Continue creating intents and entities in the portal
■ Make sure to add sufficient utterances, label entities and save!
■ For this demo we will create ‘Greeting’, ‘UpdateTwitter’, ‘UpdateName’ and ‘None’
– None is always created in every model
– LUIS passes back ‘None’ intent when it does not match any other intent
– Think of ‘None’ as a fall through
– If LUIS doesn’t know how to handle an utterance ‘None’ is returned
26. Train model
■ Navigate to ‘Train &Test’ (left menu)
– Press ‘Train Application’
■ You can always go back to the intents and train the utterances
– This makes your LUIS model smarter!
– It should start identifying entities correctly
■ You can test the confidence level under the ‘Test &Train’
– Confidence for each intent is shown
– Entities are displayed here
27. Publish model
1. Navigate to ‘Publish App’ (left menu)
2. Press ‘Publish’
3. Make note of the model ID and model Key from the ‘Endpoint url’
28. LUIS JSON
■ If we click on the endpoint and add an utterance
– Add after ‘&q=‘ at end of url
■ We can see the JSON LUIS returns back to us
■ This is what we consume in our bot
30. Adding LuisDialog
1. Using Microsoft.Bot.Builder.Luis;
2. Change IDialog<> to LuisDialog<>
3. [LuisModel(“<model ID>”,”<model Key>”]
31. LUIS models and Intents
1. Create a method for each Intent, passing in IDialogContext, and LuisResult
2. Add [LuisIntent] attribute above each method
3. User input will be passed to LUIS endpoint and JSON will be returned
4. The bot will handle the LUIS JSON and execute the correct method base don the
intent
35. Publish Project to Azure
■ Must be signed into yourVisual Studio
■ Must have activatedAzure Cloud on your
account
1. Right click on your project
2. Click ‘Publish’ option from the menu
3. Click ‘MicrosoftAzure App Service’
4. Crate new Resource Group to Host
38. Register Bot
1. Head over to https://dev.botframework.com/bots/new to register your bot
2. Add a Name, bot handle and description
3. Add the Message endpoint
1. This is the azurewebsites.net endpoint you just made!
2. Few things to add.. Mine was demobot.azurewebsites.net
3. I will enter: https://demobot.azurewebsites.net/api/messages
4. Click ‘Crate MicrosoftApp ID and password
1. Remember these!
5. Register your bot!
39. Add your ID and Password
■ Since we have registered our bot’s end point with an ID and Password, we need to add
these credentials to our bot.
1. Navigate to Web.config (under Solution Explorer on the right side)
2. You should see a empty spot for our “MicrosoftAppID & Password” values.
1. Paste these here!
41. SetupWeb Chat Channel
Once you have registered your
bot, go to the Channels
section of the portal.
Click ‘Edit’ forWeb Chat
■ You will be brought to a
new page.
■ Click ‘Add new site’
■ Name your site (reference
only)
■ Click ‘Done’
42. Get your secret key and embed code
1. Click ‘Show’, you will need to put this key in the ‘YOUR_SECRET_HERE’ embed code
2. Copy the embed code
43. Add your embed code
■ Under Solution Explorer (on the right), find ‘default.htm’
■ Paste the embed codeWITH your secret here.
44. Re-Publish to Azure!
1. Right click your project Publish
2. Now we should be able to navigate to our demobot.azurewebsites.net and see our
bot!