How to build a simple conversation bot with Microsoft Bot Framework

Lets build a simple conversation bot who will decode our emotions & will try to cheer us.

Basic Idea is to get, how the user is feeling now, then pass the feelings to Cognitive services & get the sentiment score.
If the sentiment score is high or neutral then pop a joke to the user.
If the sentiment score is low, try to show a motivational message.

Hope everyone has the environment setup for the bot app, else just check my earlier blog post

First we need to create a new bot project. Choose Bot Application


Give it a name & lets start exploring.

The project will create a controller - MessagesController.cs which is the starting point for our bot.
Controller consists of a task Post which handles the messages received by the bot.
It should look like below.
I am just trying to pass the flow to a RootDialog which is bot framework dialog.



The RootDialog looks like this



RootDialog welcomes the user & asks about how he/she is feeling now.
Those feelings get passed to cognitive services in GetUserFeelings task.
Once the SentimentScore is received, depending on the score we will popup Happy, Neutral or Sad dialogs.

HappyDialog will look like this.



Here I am popping up a question to user if he/she wants to read a Joke? (using PromptDialog restricting user inputs to Yes or No).
If answer is Yes, i read a local JSON file containing jokes & present a random one.
We then ask user if he/she want to read another & the cycle will go on.
User can disengage by choosing No.

Same process will happen for Neutral & Sad Dialogs.

To Test the bot, run your project from Visual Studio. It will fire up IISExpress & host the bot locally.
Use Bot Framework Emulator to connect to the running bot.
The url to connect the bot should look like below, change could be the port.

http://localhost:3979/api/messages

Try saying Hi to the Bot & enjoy.

You can try this with my Bot Emo.
Add him to your Skype Contacts.


or chat with him on Bing
Try on Bing


Happy Coding,
Parshuram


Comments

Popular posts from this blog

6000 KM Road Trip

Export MS Access report to Excel..Font Problem

Testing AWS Rekognition from POSTMAN