Office 365: Using Incoming Webhooks in Microsoft Teams

Incoming webhooks are a great way to get nicely presented information to your teams. While software and service providers have the ability to create connectors for teams, the current list of connectors not huge, though it does contain most of the big services such as Twitter, GitHub, JIRA, Trello etc. I have no doubt that the list will grow over time, but for now, the ability to integrate other sources of data via webhooks makes it relatively easy to bring timely information into your messaging environment.

Creating a new webhook

First, we need to create a new webhook endpoint. In the Teams app:

  1. Click on the on the team you want to add the webhook to
  2. Choose Connectors
  3. Search for Webhook and click Configure next to Incoming Webhook
  4. Give the webhook a name and, optionally, a custom image and click Create
  5. On the next page you are given a URL. You need to copy this or you won’t be able to send requests to your new webhook.

Using the webhook

Now that we have the endpoint, we can start to utilise it by sending POST requests. To do this, I will be using PowerShell, but you should be able to use any language you like as long as you can create a JSON string.

$uri = 'Your webhook URL here'
$body = @"
{
    "@type": "MessageCard",
    "@context": "http://schema.org/extensions",
    "themeColor": "ff0000",
    "title": "My First Webhook",
    "text":"That wasn't so hard!",
    "sections": [{
        "activityTitle": "Something happened!",
        "activitySubtitle": "Here are the details",
        "facts": [{
            "name": "Fact 1",
            "value": "Details"
        }, {
            "name": "Fact 2",
            "value": "Details"
        }, {
            "name": "Fact 3",
            "value": "Details"
        }],
        "markdown": true
    }]
}
"@

invoke-webrequest -method Post -uri $uri -contenttype 'application/json' -body $body

This script will send a card that looks like this.

That is all you need to do to send a message card to your team. You can add many more features to your card, including comments, avatars and images, action buttons. I will cover these when I have had more time to experiment with them. In my next post, I’ll show you how to use this in conjunction with the Windows Event log and Task Scheduler to provide almost instant notifications when a particular event occurs.

One thought on “Office 365: Using Incoming Webhooks in Microsoft Teams

  1. Do you know how if it’s possible to search for text inside these cards?. Ex., searching for “That wasn’t so hard”

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s