Creating a Microsoft Teams IVR Bot Part 4 – Debugging when things go wrong
This is the last in a series of blog posts which are designed to introduce you to IVR Bots in Microsoft Teams. IVR Bots are bots that user can place audio calls to and communicate with via their keypads. They open up a whole new world of different app possibilities, and they’re pretty easy to build too!
IVR Bots are made possible with the release (in Preview) of the Calls & Meeting API, announced at Ignite 2018. There are a number of steps to follow in order to create and configure your bot, as well as some code to write to get it to do what you want it to. For links to all the posts in the series (and a video showing an IVR bot in action) have a look at the post: Creating a Microsoft Teams IVR Bot – a 5 part series
If you’ve been following along with the previous blog posts then all the setup steps are now complete, but if you’re having problems then it’s useful to know how to peel back the covers and figure out what’s happening. Or perhaps everything works fine, but now you want to modify the sample code and turn it into something else.
It’s possible to run all the code for the IVR Bot locally, yet still make calls from the Teams client! Here’s how:
ngrok is a tunneling service. Teams is an online-only service, which requires your code to run from a publically addressable URL so that the different Teams services can access it when a user calls your bot. ngrok enables your code to run locally but still present itself with a public URL. Download it from ngrok.com and read more on my blog here)
Run the TeamsIVRBotSample project locally, which will open a browser window.
There’s no page to display, but the code is all running (waiting for the Teams service to call the API endpoint). Make a note of the port number being used (in this case 4213) and then close the browser and stop debugging (for now).
Open a command window and navigate to where the ngrok code is. Use the following command, making sure you use the right port number:
ngrok http 3979 –host-header=localhost
This will create a tunnel to your localhost:3979 which is where your code will be running. ngrok will display the public URLs which represent the “public end” of the tunnel:
In this screenshot, you can see there is a both a http and https version, plus a history of requests that have been called. Make a note of the https version (in this case https://899624a2.ngrok.io)
Update Bot Registration
We need to change the URL that the Bot Registration uses as a webhook. Navigate to the Bot Registration, then select the Channels section. Edit the Microsoft Teams channel, then choose the Calling tab. Update the Calling Webhook with the ngrok one, making sure to keep the /callback/calling suffix on the end of the URL:
Save your changes. It can take a few moments for this change to propagate, which is why it’s worth doing first.
Update Your Code
The code also has a reference to the URL. In the appsettings.json file, update the BotBaseUrl with the new URL. This time, you don’t need anything appended to the domain.
Remember to start debugging your code again, and to make sure that your local code is definitely what’s being used, why not set a break-point somewhere in the IncomingCallHandler.cs file.
Now, when you make a call from your Teams client, Teams will call the ngrok URL, which will tunnel to your machine, and your code.
A real Teams call, from the Teams client, with debug and breakpoints on your local code!
(be aware that this will be true for anyone that calls your bot in Teams, so this approach is only really any good with a bot that’s not yet live!)
I hope you’ve found this series of posts interesting and useful. If you liked this content, why not signup to the newsletter, subscribe to the RSS, or follow me on Twitter. You can also subscribe my weekly updates on YouTube, or podcast.