Building a great conversationalist with Microsoft Bot Framework – part 2

By | April 17, 2017

This is part 2 in my blog series about Bot Framework. It will describe how to test and debug your bots. If you haven’t already, I recommend reading part 1 before reading this blog post.

Microsoft Bot Framework helps you build interactive chat bots that interact with your users on websites, Skype, Slack, and many more places. These bots can run completely in the cloud and be enhanced with cognitive features such as language understanding, sentiment analysis, image analysis, and much more.

The Bot Framework Emulator

Having a local test environment is very helpful for debugging and testing. It also helps learning how the Bot Framework actually works.

The Bot Framework Emulator (also called The Bot Framework Channel Emulator) enables you to do local testing and debugging. It is available for download here.

Bot Framework Channel emulator

Note that it uses Squirrel for installing. There will be no program group or shortcuts created. I recommend pinning it to the task bar so you easily can find it.

Note that the Bot Framework Emulator can be used for debugging both local bots (running in Visual Studio) and remote bots (using ngrok, a tunneling service).

Debugging a local bot

For demo purposes, I will be using the StateBot from the GitHub samples, but you could use any bot. Click on Debug in Visual Studio to start your bot.

Bot Framework debugging step 1

Notice the address, localhost:3979. Add /api/messages to it to get the full messaging endpoint: http://localhost:3979/api/messages. Use http for local debugging.

Type in the messaging endpoint at the top of the window. Then enter your App ID and password. These must be the same as in your bot configuration (usually in the Web.config file).

Bot Framework debugging step 2

Click on Connect. Your bot should be ready for chatting.

Bot Framework debugging step 3

You can now add breakpoints in Visual Studio and they will allow you to step through your code and inspect variables.

Bot Framework debugging step 4

Debugging a remote bot

You can also debug bots that are running remotely in Azure. However, I suggest that if possible you should debug them locally first with the Bot Framework Emulator, since that is faster and easier.

Make sure that you are deploying a Debug configuration. Click on Settings… to switch between a Release and Debug configuration.

Bot Framework debugging step 5

Notice the address, Add /api/messages to it to get the full messaging endpoint: Use https for remote debugging.

Bot Framework debugging step 6

Type in your messaging endpoint address into the Bot Framework developer portal and save your changes.

Bot Framework debugging step 7

Test your bot in the portal to see that it is working.

Bot Framework debugging step 8

Now you can open the Cloud Explorer in Visual Studio and from there right-click on your deployed bot (CardsBot in my example) and choose Attach Debugger.

Bot Framework debugging step 9

After successfully attaching to Azure for debugging, you should be able to add breakpoints in Visual Studio that will allow you to step through your code and inspect variables. Try typing in some messages in the developer portal to trigger your breakpoints.

Bot Framework debugging step 10