You can send custom messages to a Microsoft Teams channel by using the Workflow Action API Call and a customized Payload using Workflow Variables. This functionality can be practical when using Microsoft Teams as a shared notification channel for a team of IT technicians, giving detailed information about monitoring notifications and Workflow Action results.
Create a Webhook URL in a Microsoft Teams Channel
To do these actions, you need to be a full Administrator of the selected Team Channel.
In Microsoft Teams, select a Teams Channel, click on the three dots, and select Connectors.
Select Incoming Webhook by pressing Configure.
Customize the name of the Webhook (this will show as the person sending the Teams Message) and press Create. Copy and save the Webhook URL as it can only be accessed once for security reasons.
Create the Workflow API Call action
To send a message to Microsoft Teams we will use the API Call Workflow Action which can be used in any new or existing Notification, Ad-Hoc, or Scheduled context-based workflows. There is a 4th option to use a Deviceless Context, but that is not applied here and is part of another knowledge base article.
Configure the API Call for Microsoft Teams message
Start by finding the API Call in the list of Workflow Actions in any of your existing workflows. You can also choose to create a new Workflow and start from there.
The API Call Workflow Action consists of 4 configurable items.
URL: This is where you enter the Microsoft Teams Webhook URL created earlier. It will be masked once the Workflow is saved.
Content type: Use Application/JSON
Payload: This is where the custom JSON message is going to be added. More on that below.
Timeout: Keep the 3 seconds default.
Customize the Microsoft Teams message in the payload field
You can customize how the Microsoft Teams message should look and behave by using the rich features of Microsoft Adaptive Cards templates. To further explore Adaptive Cards capabilities, visit Adaprivecards.io/samples. This knowledge base article will provide you with templates for 3 different scenarios: Low HDD Space, Service Stopped, and System Registered. They all have various properties and layouts and each Notification-based trigger has its own set of unique Workflow Variables. Be sure to replace (browse available variables by typing #) with the proper Workflow Variables you want to expose in the messages.
Low HDD Space Teams Message
Create a Notification-based Workflow and select Low HDD Space.
Add the API Call Workflow Action.
In the URL, paste the Microsoft Teams Webhook URL you created above.
Select Content type Application/JSON.
In the Payload field, paste this sample below.
section as you have done with "Low HDD Space Teams Message" for "Service Stopped Teams Message" and "System Registered Teams Message.
Copy text below this line:
{
"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": "RichTextBlock",
"inlines": [
{
"type": "TextRun",
"text": "Low HDD on drive (browse available variables by typing #)! There is (browse available variables by typing #) space available",
"weight": "bolder",
"size": "large"
}
]
},
{
"type": "FactSet",
"spacing": "large",
"separator": "true",
"facts": [
{
"title": "System Name:",
"value": "(browse available variables by typing #)"
},
{
"title": "Organization:",
"value": "(browse available variables by typing #)"
},
{
"title": "Site:",
"value": "(browse available variables by typing #)"
},
{
"title": "Agent Group:",
"value": "(browse available variables by typing #)"
},
{
"title": "Operating System:",
"value": "(browse available variables by typing #)"
},
{
"title": "Partition Name:",
"value": "(browse available variables by typing #)"
},
{
"title": "Free Space:",
"value": "(browse available variables by typing #)"
}
]
}
]
}
}
]
}
Stop copying text above this line.
Service Stopped Teams Message
Create a Notification based Workflow and select Service Stopped.
Add the API Call Workflow Action.
In the URL, paste the Microsoft Teams Webhook URL you created above.
Select Content type Application/JSON.
In the Payload field, paste this sample below.
Copy text below this line:
{
"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": "RichTextBlock",
"inlines":[
{
"type": "TextRun",
"text": "
Service Name (browse available variables by typing #) stopped on System Name (browse available variables by typing #)",
"weight": "bolder",
"size": "large"
}
]
},
{
"type": "FactSet",
"spacing": "large",
"separator": "true",
"facts": [
{
"title": "System Name:",
"value": "(browse available variables by typing #)"
},
{
"title": "Organization:",
"value": "(browse available variables by typing #)"
},
{
"title": "Site:",
"value": "(browse available variables by typing #)"
},
{
"title": "Service Name:",
"value": "(browse available variables by typing #)"
},
{
"title": "Service Description:",
"value": "(browse available variables by typing #)"
}
]
}
]
}
}
]
}
Stop copying text above this line.
System Registered Teams Message
Create a Notification based Workflow and select Service Stopped.
Add the API Call Workflow Action.
In the URL, paste the Microsoft Teams Webhook URL you created above.
Select Content type Application/JSON.
In the Payload field, paste this sample below
Copy text below this line:
{
"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": "RichTextBlock",
"inlines":[
{
"type": "TextRun",
"text": "New System (browse available variables by typing #) registered",
"weight": "bolder",
"size": "large"
}
]
},
{
"type": "FactSet",
"spacing": "large",
"separator": "true",
"facts": [
{
"title": "System Name:",
"value": "(browse available variables by typing #)"
},
{
"title": "Organization:",
"value": "(browse available variables by typing #)"
},
{
"title": "Site:",
"value": “(browse available variables by typing #)"
},
{
"title": "Agent Group:",
"value": “(browse available variables by typing #)"
},
{
"title": "Operating System:",
"value": "(browse available variables by typing #)"
}
]
}
]
}
}
]
}
Stop copy text above this line: