As a Software or DevOps Engineer, you often want to share automated notifications of critical updates, release status, or any other info on a Microsoft Teams channel.
For example, I have previously automated the release information so stakeholders like Product Owners, Operations, and Management were able to follow on a Microsoft Teams channel a web release status notification on or post-critical system issues.
In this short article, I will show you how to achieve this in a simple way. Just follow 4 steps to send message notifications to your channels:
1- In your teams, right-click on your channel. And search for Incoming Webhook
.
2- Installing/Adding Incoming Webhook
if not added yet.
3- Configure Incoming Webhook
, by providing a webhook name. Click on Create
It will generate you a link with unique GUIDs, copy the link
curl.exe -H "Content-Type:application/json" -d "{'text':'Servers x is started.'}" https://example.webhook.office.com/webhookb2/4dee1c26-036c-4bd2-af75-eb1abd901d18@3c69a296-d747-4ef3-9cc5-e94ee78db030/IncomingWebhook/87557542b42d8d3b04453c4a606f2b92/b852b3d0-84b6-4d98-a547-ae5f53452235
The URL in the command line contains some faked guid numbers, but you need to replace it with the one you get from webhooks.
You can either call this line in power shell or incorporated it in C# as this simple example or other programming languages:
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://example.webhook.office.com/webhookb2/4dee1c26-036c-4bd2-af75-eb1abd901d18@3c69a296-d747-4ef3-9cc5-e94ee78db030/IncomingWebhook/87557542b42d8d3b04453c4a606f2b92/b852b3d0-84b6-4d98-a547-ae5f53452235"))
{
request.Content = new StringContent("{'text':'Servers x is started.'}");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await httpClient.SendAsync(request);
}
}
Now when I run the command or C# code I get a message in that channel:
In case you need to remove the hook that you have added, click on Configured then Configure. And Manage the webhook:
And remove
Conclusion
As you can see, with a few steps you will be able to create a Microsoft Teams automated channel notification.
The use of this notification is not limited to my mentioned example, it can be used for a lot, like automated reminders, certificate expiration notifications, etc.
You can of course dig deeper in Microsoft Teams API and use Graph API to do a lot more, including sending notifications for other members, check Microsoft Teams API overview – Microsoft Graph | Microsoft Docs.
I have also another example of mentioning in a channel on StackOverflow java – Mention channel using ms graph api – Stack Overflow. that can be applied for c# as well. This article is also used to answer a question on StackOverflow as well java – Mention channel using ms graph api – Stack Overflow