In this post, we are going to build a bot using Microsoft Bot framework and add intelligence to it to extract meanings from the conversation with users utilising Microsoft cognitive service named LUIS. The last post discussed details about LUIS, give it a read before you continue on reading. This post assumes you have a basic understanding of Language Understanding Intelligent Service (LUIS) and Bot Framework, further details can be read about them at LUIS and Bot Framework.
You need to download few items to start your quick bot development, please get all of them before you jump on to the next section.
- Bot template is available at URL (this will help you in scaffolding your solution)
- Bot SDK is available at NuGet (this is mandatory to build a Bot)
- Bot emulator is available at GitHub (this helps you in testing your bot during development)
Building a Bot
- Create an empty solution in your Visual Studio and add a Bot template project as an existing solution.
- Your solution directory should like the one below:
- Replace parameters $safeprojectname$ and $guid1$ with some meaningful name for your project and set a unique GUID
- Next step is to restore and update NuGet packages and ensure all dependencies are resolved.
- Run the application from Visual Studio and you should see bot application up and running
- Now open Bot emulator and connect to your Bot as follows:
- Once connected, you can send a test text message to see if Bot is responding
- At this point, your bot is up and running and in this step you will add Luis dialogue to it. Add a new class named RootLuisDialog under Dialogs folder and add methods as shown below against each intent that you have defined under your LUIS app. Ensure you have your LUIS app id and a key to decorate your class as shown below:
- Let’s implement a basic response from LUIS against intent ‘boot’ as shown in the code below.
- Open up an emulator, and try to use any utterance we have trained our LUIS application with. A sample bot response should be received as we have implemented in the code above. LUIS will identify intent ‘boot’ from a user message as shown below.
- And now we will be implementing a bit advanced response from LUIS against our intent ‘status’ as shown in the code below.
- And now you can send a bit complex message to your bot and it will send a message to LUIS to extract entity and intent from the utterance and respond to the user accordingly as per your implementation.
And the list of intent implementation goes on and on, you can customise behaviour as per your needs as your LUIS framework is ready to rock and roll within your bot and users can take advantage of it to issue specific commands or inquire about entities using your Bot. Happy Botting 🙂