Leveraging Microsoft Teams webhooks to create a Tines chatbot

Written by Shaun Finn Solutions Engineer, Tines

Published on October 12, 2022

This article was posted more than 18 months ago.

Microsoft requires users to leverage the Microsoft Developer Portal to create new Teams applications, such as chatbots. At Tines, we thought it might be helpful to provide instructions for alternative options if you don't want to create a chatbot in the portal.

For those who would prefer to send messages directly to a Teams channel instead of configuring a chatbot, Microsoft Teams can receive messages in a channel via a webhook. To do this, you must first create a webhook URL for the channel you would like to send messages. Teams currently only offer this capability in a channel; it is not available for direct messages to an end user.

To configure the channel to accept webhook messages, open Microsoft Teams. In the channel, select Connectors.

Once you have selected Connectors, search for Incoming WebHook and select Add.

By default, Teams will allow any communication over the webhook to have permission to send, chat, or meet in a channel. Additional permissions can be granted or removed by clicking the permissions tab (next to overview).

The process for creating a webhook in Teams and turning it on is two-step. First, add the Incoming Webhook option. Then, navigate back to Connectors and select Configure.

A name is required for the webhook. Additionally, you can upload an image to associate with it. Remember to select Create when you are done. If you skip this step, then the webhook URL will not be generated by Teams.

Next, copy the automatically generated URL that is displayed at the bottom of this screen. This is the URL that will be used later on in the Tines platform to make an HTTP Request Action call.

To confirm the connector is available, go back to Connectors and select Configured. You should now see that this Incoming Webhook is running and available.

NOTE: It appears that Teams currently only allows one webhook per channel.

To call the new webhook URL within Tines, drag an HTTP Request Action onto your Storyboard and paste the webhook URL into the Action's URL field. To format the Action appropriately, follow this Microsoft documentation on how to create a message being sent to webhook.

Example Action:

{"agents":[{"disabled":false,"name":"Send Message to Teams Webhook","options":"{\"url\":\"<<RESOURCE.msteams_webhook>>\",\"content_type\":\"json\",\"method\":\"post\",\"payload\":{\"text\":\"Hello World \"}}","position":{"x":1335,"y":-90},"type":"httpRequest","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null}],"links":[],"diagramNotes":[]}

When you run the Action, a message will be sent to the channel's chat from the corresponding Action in Tines.

Actions can also be created for Teams messages like adaptive cards.

Example Adaptive Card Action:

{"agents":[{"disabled":false,"name":"Send Message to Teams Webhook","options":"{\"url\":\"<<RESOURCE.msteams_webhook>>\",\"content_type\":\"json\",\"method\":\"post\",\"payload\":{\"type\":\"message\",\"attachments\":[{\"contentType\":\"application/vnd.microsoft.card.adaptive\",\"contentUrl\":null,\"content\":{\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"type\":\"AdaptiveCard\",\"version\":\"1.2\",\"body\":[{\"type\":\"TextBlock\",\"text\":\"For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)\"}]}}]}}","position":{"x":1785,"y":-105},"type":"httpRequest","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null}],"links":[],"diagramNotes":[]}

More advanced adaptive cards similar to CrowdStrike alerts can be sent via webhook.

Example card with buttons:

{"agents":[{"disabled":false,"name":"Send Adaptive Message","options":"{\"url\":\"<<RESOURCE.msteams_webhook>>\",\"content_type\":\"json\",\"method\":\"post\",\"payload\":{\"type\":\"message\",\"attachments\":[{\"contentType\":\"application/vnd.microsoft.card.thumbnail\",\"content\":{\"title\":\"Security Alert\",\"subtitle\":\"A new alert has just been created in Jira\",\"text\":\"A new alert has just been created in Jira with the JIRA ID: <<create_issue_in_jira.body.key>>.<<NEWLINE_TO_BR(\\\"\\\\n\\\")>>\\nCrowdStrike severity is <<explode_individual_detections.individual_detection.max_severity_displayname>>.<<NEWLINE_TO_BR(\\\"\\\\n\\\")>>\",\"images\":[{\"url\":\"https://logo.clearbit.com/tines.com\",\"alt\":\"Tines\"}],\"buttons\":[{\"type\":\"openUrl\",\"title\":\"View Detection in CrowdStrike\",\"value\":\"https://falcon.us-2.crowdstrike.com/activity/detections/detail/<<REPLACE(REMOVE(explode_individual_detections.individual_detection.detection_id, \\\"ldt:\\\"),\\\":\\\",\\\"/\\\")>>\"},{\"type\":\"openUrl\",\"title\":\"View Jira Incident\",\"value\":\"https://tinesio.atlassian.net/browse/<<create_issue_in_jira.body.key>>\"},{\"type\":\"openUrl\",\"title\":\"Escalate to On Call\",\"value\":\"<<PROMPT(\\\"escalate\\\")>>\"},{\"type\":\"openUrl\",\"title\":\"Mark False Positive\",\"value\":\"<<PROMPT(\\\"falsepositive\\\")>>\"}]}}]}}","position":{"x":1875,"y":0},"type":"httpRequest","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null}],"links":[],"diagramNotes":[]}
{"agents":[{"disabled":false,"name":"Send Message Card","options":"{\"url\":\"<<RESOURCE.msteams_webhook>>\",\"content_type\":\"json\",\"method\":\"post\",\"payload\":{\"@type\":\"MessageCard\",\"@context\":\"http://schema.org/extensions\",\"themeColor\":\"0076D7\",\"summary\":\"Larry Bryant created a new task\",\"sections\":[{\"activityTitle\":\"Larry Bryant created a new task\",\"activitySubtitle\":\"On Project Tango\",\"activityImage\":\"https://teamsnodesample.azurewebsites.net/static/img/image5.png\",\"facts\":[{\"name\":\"Assigned to\",\"value\":\"Unassigned\"},{\"name\":\"Due date\",\"value\":\"Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)\"},{\"name\":\"Status\",\"value\":\"Not started\"}],\"markdown\":true}],\"potentialAction\":[{\"@type\":\"ActionCard\",\"name\":\"Add a comment\",\"inputs\":[{\"@type\":\"TextInput\",\"id\":\"comment\",\"isMultiline\":false,\"title\":\"Add a comment here for this task\"}],\"actions\":[{\"@type\":\"HttpPOST\",\"name\":\"Add comment\",\"target\":\"https://docs.microsoft.com/outlook/actionable-messages\"}]},{\"@type\":\"ActionCard\",\"name\":\"Set due date\",\"inputs\":[{\"@type\":\"DateInput\",\"id\":\"dueDate\",\"title\":\"Enter a due date for this task\"}],\"actions\":[{\"@type\":\"HttpPOST\",\"name\":\"Save\",\"target\":\"https://docs.microsoft.com/outlook/actionable-messages\"}]},{\"@type\":\"OpenUri\",\"name\":\"Learn More\",\"targets\":[{\"os\":\"default\",\"uri\":\"https://docs.microsoft.com/outlook/actionable-messages\"}]},{\"@type\":\"ActionCard\",\"name\":\"Change status\",\"inputs\":[{\"@type\":\"MultichoiceInput\",\"id\":\"list\",\"title\":\"Select a status\",\"isMultiSelect\":\"false\",\"choices\":[{\"display\":\"In Progress\",\"value\":\"1\"},{\"display\":\"Active\",\"value\":\"2\"},{\"display\":\"Closed\",\"value\":\"3\"}]}],\"actions\":[{\"@type\":\"HttpPOST\",\"name\":\"Save\",\"target\":\"https://docs.microsoft.com/outlook/actionable-messages\"}]}]}}","position":{"x":1875,"y":0},"type":"httpRequest","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null}],"links":[],"diagramNotes":[]}

It is also possible to send from MS Teams to a webhook per channel instead of using a chatbot.

For more inspiration on how to use Tines to automate Microsoft Teams workflows, visit the Tines Story Library, where you can use and customize prebuilt automation Stories.

Additional resources: 

How to create an incoming webhook

Create message for webhook

Outbound message to webhook

Built by you,
powered by Tines

Already have an account? Log in.