Webhooks Cookbook - Microsoft Teams

The webhook use cases for Microsoft Teams that are referred to on this page are in regards to Approvals completed in the Microsoft Teams UI.

Adding Webhooks in Microsoft Teams

See the Teams plugin configuration pages for information on how to set up FlexDeploy and Microsoft Teams. 

Configuring FlexDeploy for Teams Webhook Operations

and

Configuring FlexDeploy for Teams Operations using User Credentials

Incoming

Provider Match Script

This provider match script for Microsoft Teams validates that it is a message from a card that FlexDeploy created.

Additional security checks are performed after match and before completing processing of approval tasks. These checks are in regards to the security that Microsoft provides on the incoming message, and the users and groups setup in FlexDeploy.

return HTTP_HEADERS.containsKey("flex-sync-webhook") && "TeamsTask".equals(HTTP_HEADERS.get("flex-sync-webhook"));

Function Script - Update Tasks from Teams Messages

Microsoft Teams Incoming Webhooks are validated and processed Synchronously. Behind the scenes, the JWT token is validated and the message is checked for unauthorized modification. The user that clicked the button is matched to a FlexDeploy user account behind the scenes using the JWT Token found in the HTTP Headers. If the matched user is authorized to approve/reject the linked FlexDeploy task, the task is approved or rejected and the card is updated to indicate that the task was processed. 

 

MICROSOFTTEAMS.updateTask(QUERY_PARAMS,HTTP_HEADERS,"<Teams Messaging Integration Account Code>");

Outgoing

Create Teams Approval Tasks

This sample sends an interactive message to a Microsoft Teams channel that allows members of the channel to approve or reject an associated FlexDeploy task. As shown in this script, you can add conditions to handle sending to multiple different channels in one listener depending on some condition. (e.g. environment, pipeline, release, etc.) You could also apply similar logic to the webhook listener filter to customize when and where the Teams message should be sent.

See the incoming samples also. An incoming webhook is needed to capture the button clicks that users perform on the Teams messages and ultimately approve/reject the task in FlexDeploy.

// Function Script - Create Approvable Tasks in Teams Channels (Outgoing Webhook) String message = MICROSOFTTEAMS.makeTaskCreatedMessageForWebhook(EVENT.payload,"https://<urlToYourFlexDeployServerOrExternalProxy>/flexdeploy/webhooks/v1/<uri setup in Incoming Webhook>"); String webhookUrlBI = "https://flexagon.webhook.office.com/webhookb2/cb7f2430-...9ee6-98a7eae43f9f"; String webhookUrlMule = "https://flexagon.webhook.office.com/webhookb2/cb7f2430-9...-98a7eae43f9f"; String webhookUrlSF = "https://flexagon.webhook.office.com/webhookb2/cb7f2430-96dc-4....-98a7eae43f9f"; if(condition for BI Approval){ MICROSOFTTEAMS.sendTeamsWebhookMessage(webhookUrlBI,message); } else if(condition for Mule Approval){ MICROSOFTTEAMS.sendTeamsWebhookMessage(webhookUrlMule,message); } else if(condition for SF Approval){ MICROSOFTTEAMS.sendTeamsWebhookMessage(webhookUrlSF,message); }



The following macros are not currently supported in the footer:
  • style