- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 12:54 PM
How to handle the Microsoft Teams Connector Deprecation in ServiceNow
If you utilize Microsoft Teams Connector webhooks for posting messages to channels you may have noticed that this warning message concerning their deprecation.
The Teams Connectors were initially scheduled for deprecation on [?]. On July 23rd, Microsoft announced that they would be extending the retirement time line for existing Teams Connectors through December 2025 and Connector usage after December 31, 2024, existing Connectors will require additional action for them to work (you have to change the respective webhook URLs). Teams Connectors will be replaced by “Workflows”.
For those that are using the ServiceNow Microsoft Teams “Post a Message” Flow action from the Microsoft Teams Spoke for IntegrationHub and want to refactor their ServiceNow/MS Teams message posting pipeline using Workflows, below is a simple guide to achieve this, pending an update to the Spoke.
- Set up workflow
- In your desired Teams Channel, open the channel settings and select Workflow
b. Select Post to a channel when a webhook request is received
c. In the workflow, open the first flow step and look at the HTTP POST URL (it should look something like https://prod-XXX...) and copy it for later. This is the endpoint we will be using in our ServiceNow Flow
2. Refactor ServiceNow “Post a Message” Microsoft Teams Flow Action
Before running to simply replace the webhook URL input in the existing Flow Action, let’s take a look deeper look at it. we see that the action makes use of a script include called “MSTeamsMessageBuilder(). We see that it utilizes the generateBasicPayload method. In that function, we can see the structure of the payload.
If we compare this payload to the payload shown in the Webhooks documentation, we see that they are not the same.
{
"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": "Submitted response:"+ response
}
]
}
}
]
}
Note: More advanced Adaptive Cards can be created be utilizing the Adaptive Card Designer and replacing the “content” property with the generated JSON in the Card Payload Editor in the Designer linked above.
In other words, the existing ServiceNow “Post a Message” Microsoft Teams flow action will not work in its current state. Not to worry!
In Flow Designer, let’s create a custom Flow Action called “Post a Message to Microsoft Teams” (or whatever you’d like to call it.
Set up the following Action Inputs
Add a new “Script” (or Payload Builder) step and call it “Build Payload” and set up the following input variables
Use the code below for the “Script” field:
(function execute(inputs, outputs) {
var 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.3",
"body": [],
"actions": []
}
}
]
};
if (inputs.messageTitle != null) {
payload.attachments[0].content.body.push({
"type": "TextBlock",
"text": inputs.messageTitle,
"wrap": true,
"size": "Large",
"weight": "Bolder"
});
}
if (inputs.message != null) {
payload.attachments[0].content.body.push({
"type": "TextBlock",
"text": inputs.message
});
}
if (inputs.actionURL != null) {
payload.attachments[0].content.actions.push({
"type": "Action.OpenUrl",
"url": inputs.actionURL
});
if (inputs.actionName != null) {
payload.attachments[0].content.actions[0].title = inputs.actionName;
}
}
outputs.payload = JSON.stringify(payload);
})(inputs, outputs);
Set up the following Output Variable
Add a new “REST” step and configure using details below
Additionally, you can add error handling to this Flow Action if you’d like
Hope this helps!