You can use the Bot Framework to build and connect bots to interact with your users in apps (or communication channels) such as your website, Skype, Facebook Messenger, and Office 365 mail. Before or after deploying and publishing bots, you can use the Bot Framework Emulator to test them. In the post I will share a few tips on how to use the emulator correctly.
Install and use the latest version of the emulator
You can download the latest version (currently 3.5.23) at github. (At the time of writing the post the other download link didn’t seem to be working.) If you have the older version, 184.108.40.206, on your Windows computer, you should replace it.
Test a Bot Connected to Azure Bot Service in the Emulator
With an Azure subscription, you can create a bot through the Azure portal by following the instructions here. You can test the bot directly through the portal chat channel as shown below.
To test the same bot in the emulator, you will need to find the end point, application ID and password for the bot service. The Settings tab only provides the partial message endpoint (ending with three dots). Therefore you will need to go to the developer site, https://dev.botframework.com/. Click on the Edit link. You will find the message endpoint there. Copy the entire URL and enter it in the emulator. Also, copy and paste the application ID and password from the bot developer portal.
You will also need to download free utility, ngrok, which creates a tunnel between the bot hosted remotely (in this case on Azure) and your computer behind the firewall. Click App Settings in the emulator. Browse to the location where ngrok.exe is located. Save the setting. The utility will be launched automatically from the emulator. At this point, the emulator is ready. Click “Connect” or the refresh icon. Type something in the input box. You’ll see a response.
Test a Bot Connected to localhost in the Emulator
You can use Visual Studio to create a bot using the Bot Framework Connector SDK .NET template. See detailed instructions here.
Note that the documentation is a bit outdated. It still shows the old emulator interface. It refers the portal to 3978. Your bot app actually uses port 3979. It says you can leave the application ID and application password blank, but the emulator (version 3.5.23) asks you for application ID and password.
If you just want to test the bot locally with the emulator, without registering the bot and publishing it to Azure, you can supply the application ID and password in your Visual Studio project code. Interestingly, you have to provide a valid application ID and password, not something random.
- If you leave the values of MicrosoftAppId and MicrosoftAppPassword blank, you will receive an error: “The bot's MSA appId or passsword is incorrect. Click here to edit your bot's MSA info.”
- If you set the value of MicrosoftAppId to “MyApp” and MicrosoftAppPassword to “12345”, you will received an errror: “Refresh access token failed with status code: 400”
I used the same application ID and password from the bot I created from the Azure portal. And it worked. Note that ngrok is not required for local message service.