Interacting with your Bot Service's API
Who needs an SDK?
Last updated
Who needs an SDK?
Last updated
With the configuration done, we can now test out our Bot Service. We'll need to connect a messaging endpoint to receive the messages and send a response. For the sake of testing, we'll use the awesome tool https://webhook.site. This will allow us to generate a webhook and capture any data sent to it for inspection. Copy your custom webhook URL
Go back to your Bot Service and click on Configuration in the left navigation bar. Enter your webhook URL into the Messaging Endpoint field and apply the settings
Go back to the Channels tab in the left navigation bar, and click "Open in Teams" under Actions for your Teams channel connector
Teams will now open a conversation with your bot! Send it a message so it can send data to Webhook.Site
Back in our Webhook.Site tab after we sent something to our bot chat, you'll find data that was sent as a POST to our webhook. This includes information on what the message says, where it came from, who sent it, and how to reply to it
To respond to our message, we'll need to send a POST back to the bot service. There's a variety of apps that can help with this, the most common being Insomnia and Postman. I'll be using Insomnia, but the steps on other API tools should be similar. I'll also include curl
commands for those who prefer a command line.
Before we start sending requests, we need to collect some data from the POST to our webhook:
serviceUrl
conversation.id
recipient.id
recipient.name
We'll start by getting our authorization token to respond to this message. With your Client ID and Secret, send the following request
In Insomnia, it looks like this:
To send in curl
, format it as:
When sent, the response should look like this:
Note the access_token
value for later use. We now have all the information we need to send our response!
First, we need to know where to send the reply to. Since Microsoft has several regions for Teams, the message to our endpoint with the message details also contains a serviceUrl
. This will be formed to make the base URL. The base URL will be the service URL, plus /v3/
, plus the API endpoint.
The endpoint we need to reply to a chat message is conversations/{conversationId}/activities
. Therefore, with the serviceURL
of https://smba.trafficmanager.net/amer/
, our reply URL should be https://smba.trafficmanager.net/amer/v3/conversations/{conversationId}/activities
The body for the reply to a chat message should be in JSON and at minimum contain:
Putting this all together, in our case this would look like the following in Insomnia
In curl
, this would be:
When successfully sent, you'll get a 201
success code for the request and the response body of an ID for your message
Your message is then sent to the user!