DEV Community

Harshad Ranganathan
Harshad Ranganathan

Posted on • Updated on • Originally published at rharshad.com

Microsoft Teams Webhook Integration

Originally published at rharshad.com

Microsoft Team's Incoming webhook connector allows you to publish messages to teams channel.

You can even add actions to the content so that users can complete tasks within the channel.

Adding Webhook Connector to a Channel

In Microsoft Teams, choose the More options (⋯) button next to the channel name in the list of channels and then choose Connectors.

Add Incoming webhook connector to the channel.

Now choose configure button next to the Incoming Webhook connector.

Provide a name and upload an image for the connector. Now select Create button.

Copy the webhook URL for later reference.

We have now set up the webhook for the channel.

Sending Messages to Webhook

To send a message to the webhook connector we have to send it as a JSON payload. Refer message card template on how the payload needs to be structured.

Note: Adaptive cards are the recommended card type for new Teams development. They are the new cross product specification for cards in Microsoft products including Bots, Cortana, Outlook, and Windows. However, they are not supported yet in teams connectors.

You can experiment your card design at Card Playground.

We will send below sample payload to the connector and check if it works.

Send this JSON payload as a POST request to the Webhook URL.

You can either use Send via WebHook option available in the Card Playground (or) Postman to send the message to the webhook.

There is a python library which you can make use of for building the messages dynamically.

https://pypi.org/project/ms-teams/

Sending Messages to Webhook from Jenkins Build

You can make use of the office 365 connector plugin to send build messages to the webhook.

However, if you want to send a custom message as part of your jenkins job then we can't make use of this plugin.

Below is a sample which sends a custom card message to the webhook using httpRequest step in jenkins pipeline code.

This card shows the build parameter values with an action button to view the build job.

References:

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/connectors

https://docs.microsoft.com/en-us/outlook/actionable-messages/actionable-messages-via-connectors

Top comments (1)

Collapse
 
vishwasmahadev profile image
Vishwas Mahadev • Edited

Hi Harshad,

I hope you are familiar to this topic on which I am asking you the question on.

I am currently working on message cards/Actionable messages in email. I am trying to send Actionable Message, like the email contains Approve or Reject buttons in it. As soon a user clicks on Approve I will have send (POST/PATCH) a payload to App client.

I am get till the sending of emails using python. But when I click on Approve button it showing me 401 error. I tried to pass bearer token but no luck. What headers should I include in the request?

Any inputs pls.