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.
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.
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).
Click on Connect. Your bot should be ready for chatting.
You can now add breakpoints in Visual Studio and they will allow you to step through your code and inspect variables.
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.
Notice the address, cardsbot20170417084626.azurewebsites.net. Add /api/messages to it to get the full messaging endpoint: https://cardsbot20170417084626.azurewebsites.net/api/messages. Use https for remote debugging.
Type in your messaging endpoint address into the Bot Framework developer portal and save your changes.
Test your bot in the portal to see that it is working.
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.
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.