Automating Teams Notifications
Recently, my team transitioned from using Slack to using Microsoft Teams. It's fair to say that the team had a lot of love for Slack. Teams is a poorer product from the perspective of UI / UX. Maybe as you read this in the future that's all changed. But here on December 18th 2019, Teams is a solid 2 stars out of 5.
However, we are where we are, and the purpose of this post is not to complain. Because our team is now effectively using Microsoft Teams. And one of the things that's helped us make the move is automating various Teams notifications in a similar fashion to how we used to with Slack.
This post will explain the following:
- How you can automate the sending of notifications using Teams.
- How Teams supports MarkDown in notifications.
- How you can use ASP.Net Core to automate sending notifications.
#
Notifications via WebhooksNow, it's not obvious from Teams that there is a simple webhooks integration for Teams, but there is. It's tucked away under "Connectors". If you want to create a webhook of your own, find your team, your channel, click on the menu, then connectors and create a hook. Like so:
With the URL you've just obtained, you are now free to send notifications to that channel via a simple curl
:
#
MarkDownLet's see if we can make this more interesting. It turns out that the the webhook can receive JSON as the body of the payload. And there's 3 properties we'd like our JSON to contain:
title
- this is optional and is the title of your notification if supplied.textFormat
- provide the value"markdown"
and then...text
- provide your markdown notification content!
So if we have a notification payload file called down.json
:
We can trigger it with this curl
:
As you can see from the example above, you can use all the qualities of MarkDown that you know and love. Text, bold text, italics, links and even images too. It's great!
#
ASP.Net CoreFinally, I wanted to illustrate just how simple the WebHooks API makes plugging notifications into an existing app. In our case we're going to use ASP.Net Core, but really there's nothing particular about how we're going to do this.
Here's a class called TeamsNotificationService
. It exposes 2 methods:
SendNotification
which allows the consumer to just provide atitle
and amessage
- you could consume this from anywhere in your app and use it to publish the notification of your choice.SendExcitingNotification
which actually usesSendNotification
and illustrates how you might provide an exciting notification to publish out.
It's as simple as that :-)