microsoft bot framework introduction
TRANSCRIPT
HOW CHATBOTS CAN FEED YOU!
Introduction to Microsoft Bot Framework & LUIS.ai
Kevin Leung
Microsoft Bot Framework Cognitive Services +
LUIS.ai ASP.NET Core Internet of Things
Microsoft Technical Evangelist
Follow Me: @KSLHacks
Road Map Why Bots Real World Demo Microsoft Bot
Framework Building our own bot Adding Intelligence Deploying!
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.”
- USA TODAY
“Microsoft CEO Satya Nadella says future belongs to bots”
FRIDGEBOT DEMO
Try it yourself: aka.ms/fridgechatbot
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
Connectors and Benefits
Your Bot(C# or
Node.js)
■ 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
OUR FIRST BOTVisual Studio Community
Getting Started
1. Download the Bot Application Template here: http://aka.ms/bf-bc-vstemplate
2. Save zip file to Visual Studio templates directory3. Open Visual Studio4. Create new Visual C# project using the Bot Application Template
Testing out the Template
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 in Visual Studio3. Check the localhost in the browser that opens 4. Enter the same local host PORT and press Connect
Adding a new RootDialog
RootDialog.cs
1. Inherit from IDialog<object>2. Implement StartAsync() method
1. Welcome our users3. Create a new method to display a prompt after the greeting message
RootDialog.cs - Prompting Choice
1. Add strings which will become your option choices for the user2. PromptDialog.Choice will present option buttons to the user
RootDialog.cs - OnOptionSelect
■ This method runs when the user selects an option– Arguement result holds the user’s response
RootDialog.cs – PromptDialog.Text()
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
CREATING INTELLIGENCE!
LUIS.ai
Creating a LUIS model
1. Head over to luis.ai2. Log in with your Microsoft live account3. 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)
Creating a LUIS model
Add Intent
Train the model
Add new Intent + Entity
1. Created new Intent ‘UpdateTwitter’2. Clicked on the ‘@’ and ‘kslhacks’, entered a new entity name and
press ‘create’
Training Intent and Entity
1. Select all other entities and label them accordingly..2. You can now select from the created entity
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
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
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’
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
ADDING INTELLIGENCE!
LUIS Intent Dialogs C#
Adding LuisDialog
1. Using Microsoft.Bot.Builder.Luis;2. Change IDialog<> to LuisDialog<>3. [LuisModel(“<model ID>”,”<model Key>”]
LUIS models and Intents
1. Create a method for each Intent, passing in IDialogContext, and LuisResult
2. Add [LuisIntent] attribute above each method3. User input will be passed to LUIS endpoint and JSON will be returned4. The bot will handle the LUIS JSON and execute the correct method
base don the intent
LUIS models and Intents
LUIS models and Intents
DEPLOY TO AZURE
Web App Services
Publish Project to Azure
■ Must be signed into your Visual Studio■ Must have activated Azure Cloud on
your account
1. Right click on your project2. Click ‘Publish’ option from the menu3. Click ‘Microsoft Azure App Service’4. Crate new Resource Group to Host
Publish Project to Azure
REGISTER YOUR BOT
Dev.botframework.com
Register Bot
1. Head over to https://dev.botframework.com/bots/new to register your bot2. Add a Name, bot handle and description3. Add the Message endpoint
1. This is the azurewebsites.net endpoint you just made!2. Few things to add.. Mine was demobot.azurewebsites.net3. I will enter: https://demobot.azurewebsites.net/api/messages
4. Click ‘Crate Microsoft App ID and password1. Remember these!
5. Register your bot!
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!
SETUP CHANNELWeb Chat
Setup Web Chat ChannelOnce you have registered your bot, go to the Channels section of the portal.Click ‘Edit’ for Web Chat
■ You will be brought to a new page.
■ Click ‘Add new site’■ Name your site
(reference only)■ Click ‘Done’
Get your secret key and embed code1. Click ‘Show’, you will need to put this key in the
‘YOUR_SECRET_HERE’ embed code2. Copy the embed code
Add your embed code
■ Under Solution Explorer (on the right), find ‘default.htm’■ Paste the embed code WITH your secret here.
Re-Publish to Azure!
1. Right click your project Publish2. Now we should be able to navigate to our demobot.azurewebsites.net
and see our bot!
Ready for the world to use
Thanks!
■ github.com/KSLHacks/FridgeChatBot■ dev.botframework.com■ luis.ai■ azure.microsoft.com/free ($200 credits)
// Kevin Leung// Microsoft Technical Evangelist// Twitter: @KSLHacks (send questions here)// Github: KSLHacks