{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/teams-notification-webhooks",
  "description": "Learn how to automate notifications using Microsoft Teams and Markdown webhooks, and discover how to use ASP.Net Core to send notifications.",
  "path": "/posts/teams-notification-webhooks",
  "publishedAt": "2019-12-18T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "textContent": "Teams notifications are mighty useful. You can send them using Markdown via a webhook.\n\n\n\nThis post will explain the following:\n\n1. How you can automate the sending of notifications using Teams.\n2. How Teams supports Markdown in notifications.\n3. How you can use ASP.Net Core to automate sending notifications.\n\nNotifications via Webhooks\n\nNow, 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:\n\nWith the URL you've just obtained, you are now free to send notifications to that channel via a simple curl:\n\nMarkdown\n\nLet'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:\n\n1. title - this is optional and is the title of your notification if supplied.\n2. textFormat - provide the value \"markdown\" and then...\n3. text - provide your markdown notification content!\n\nSo if we have a notification payload file called down.json:\n\nWe can trigger it with this curl:\n\nAs 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_!\n\nASP.Net Core\n\nFinally, 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.\n\nHere's a class called TeamsNotificationService. It exposes 2 methods:\n\n- SendNotification which allows the consumer to just provide a title and a message - you could consume this from anywhere in your app and use it to publish the notification of your choice.\n- SendExcitingNotification which actually uses SendNotification and illustrates how you might provide an exciting notification to publish out.\n\nIt's as simple as that 😄",
  "title": "Teams notification webhooks"
}