Microsoft Teams notifications with Knock
In this guide you'll learn how to use Knock to send notifications to Microsoft Teams.
Here's what we'll cover in this guide.
- The different methods of sending notifications to Microsoft Teams
- How to add a Microsoft Teams channel to your Knock instance
- How to store Microsoft Teams connection data in Knock using channel data
- How to design notification templates for Teams
Supported notification methods
Today, Knock supports sending notifications to Microsoft Teams using two different methods:
- Using an incoming webhook URL. This is suitable for internal or one-off integrations.
- As a Microsoft Teams bot, via Microsoft Bot Framework. This is suitable for multi-tenant integrations, and supports both sending notifications to channels and sending direct messages to users.
How you configure your Microsoft Teams channel in Knock depends on the method you choose.
How to connect to Teams with Knock
Prerequisites
If you're using an incoming webhook URL, there are no prerequisites.
If you're using a Microsoft Teams bot, make sure your bot has been registered with Microsoft Bot Framework and is deployed to Azure. Knock does not manage deploying and configuring your bot. To set up Knock to send notifications as your bot, you'll need your bot's ID and password. These are sometimes called the App ID and App Password, and were provided to you when you registered your bot with Microsoft Bot Framework.
Add Teams to Knock as a channel
First you'll need to add Teams as a channel in Knock. Navigate to the “Channels” page within Knock and click “Create channel” to add Microsoft Teams.
If you're using an incoming webhook URL, no additional environment configuration is required.
If you're using a Microsoft Teams bot, click “Manage configuration”, scroll down to “Provider settings”, and enter the ID and password associated with your bot.
Add a Teams channel step to a workflow
Next, navigate to a workflow in Knock that you want to notify Teams and add a chat channel step. Select the Teams channel you just configured and create a notification template for the channel.
You can learn more about how to write basic and advanced templates for Teams in the designing notifications templates section of this guide.
Trigger the workflow
Now you're ready to notify Teams. Trigger the workflow that you added your Teams channel to. You'll need to include the user or object that has your Teams channel data as a recipient
on the workflow trigger call.
Your Teams channel should have received a notification. If you need to debug your integration, you can view the logs page in the Knock dashboard.
How to set channel data for a Microsoft Teams integration in Knock
In Knock, the ChannelData
concept provides you a way of storing recipient-specific connection data for a given integration. If you reference the channel data requirements for Microsoft Teams, you'll see that there are two different schemas for an MsTeamsConnection
stored on a User
or an Object
in Knock.
Here's an example of setting channel data on an Object
in Knock.
KNOCK_TEAMS_CHANNEL_ID
variable is the id of the Knock channel you've created to represent your Microsoft Teams integration within the Knock dashboard. You can find it by going to Integrations > Channels in the Knock dashboard and then copying the ID of your Microsoft Teams channel.Channel data requirements
Here's an overview of the data requirements for setting recipient channel data for either an incoming webhook URL or a Microsoft Teams bot connection. Both will need to live under the connections
key.
Property | Type | Description |
---|---|---|
connections | MsTeamsConnection[] | One or more connections to Microsoft Teams |
An MsTeamsConnection
can have one of two schemas, depending on whether you're using a Microsoft Teams bot or an incoming webhook.
Setting channel data: users vs. objects
Depending on the Microsoft Teams integration you build into your product, you'll store the connection data you receive from Microsoft Teams as channel_data
on either a User
or an Object
in Knock.
Designing notification templates for Teams
When you add a new Teams channel step to a workflow in Knock, you'll need to configure a template for that step so Knock knows how to format the message to Teams.
By default, we provide a basic markdown editor that you can use for sending simple messages to Teams. Just write in Markdown and we'll handle the rest. (Note: As of February 2022, Teams only supports the following markdown styles: bold, italic, unordered lists, ordered lists, hyperlinks. All other markdown styles are not supported.)
Advanced Teams notifications
If you find yourself wanting to send notifications that include more advanced formatting and interactivity, such as buttons, data layouts, and so on, you'll need to use Microsoft's adaptive card format to build your notification templates in Knock. This is essentially a JSON block language you use to lay out your Teams message.
To switch to the JSON editor in the Knock template designer, look for the "Switch to JSON editor" button at the bottom of the template editor page. When you're in JSON editing mode, you can provide adaptive card JSON and we'll pass it to Teams on your behalf.
What did you think of this guide? Did we miss any key steps? Did you run into a blocker? Let us know using the feedback component at the top of this page. 🙏