Have you ever had an idea to ask a bot to perform a simple interaction? Then this article is for you.
A simple interaction could be an answer to a question you asked:
You could achieve this (and more) by building a bot using tools such as Power Virtual Agents or Bot Framework, but that is a little overkill for a simple interaction.
Instead, let's use Webhooks to achieve this.
Before we begin, let's fictionalise a use case. The idea is that users need to quickly be able to check the current and forecasted for any location from within a Team.
The solution is a Webhook in Teams and a Bot (surprised?). This works as follows:
Let's break this down by component.
A Webhook is a way for two applications that can communicate with each other. In our case, a simple bot and Teams.
Teams supports two types of Webhooks:
For this solution, it is an Outgoing Webhook.
There are some limitations to using a Webhook in Teams, so bear these in mind when choosing Webhooks for your own idea:
To get the weather information, OpenWeatherMap API will be used. You can register for an API key.
The bot is where the magic happens. It is code hosted externally to Teams that can be called over HTTP (via the Webhook). What that code does, where it is hosted, is all up to you. For this scenario, there is an Azure Function HTTP Trigger (written in TypeScript), which can be found here.
You are free to use the linked code as a basis for your own idea, or create your own code in your choice of programming language. The basic construct of a bot behaviour needs to be as follows:
The setup of this solution comprises of two parts:
A Azure Function HTTP Trigger hosting the code is created. The URL of the trigger needs to be copied for the next step
Disregard the trailing question mark and any other text past this
To add an Outgoing Webhook, the following is done:
Find the Team to host the Webhook
Click the ellipsis (...) on the Team and choose Manage team
Under the Apps tab, at the bottom right of the page, there will be an option to Create an outgoing webhook
Provide the following:
Name: A short name that will be used to @ mention the Webhook. Keep it to one word if you can e.g. Weather
Callback URL: This is where the URL of the bot is entered (e.g. URL of the Azure Functions HTTP Trigger)
Description: A description of the purpose and functionality of the webhook e.g. Provides current and forecasted weather for any location
Icon: Image that will appear next to the Webhook
Once the Webhook is created, take a note of the Security token of the Webhook as it will only be shown once and will be required for authentication to the bot
With the bot and webhook created, one final step is to configure the bot. In this case, the following is added under Configuration on the Azure Function:
To simplify this example, I have stored these in application settings. In a production environment, please ensure this is held somewhere more secure, such as Azure KeyVault references that can be accessed using Managed Identity
With everything in place, all that is left is to try it! Simply mention the Webhook and enter a location, and the weather is returned!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.