Most Popular
Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.
Sign-up
There are ways to integrate cross-channel notifications via individual APIs, but we’re here to provide you with a quick guide to send across your preferred channels in one single API call. This guide will focus on sending and automating messages via Slack, MS Teams, and any other channel of your choice from your Node.js applications.
You can also automate Slack and Microsoft Teams notifications using Python.
This blog is a comprehensive setup guide. If you would like to get started quickly, checkout the code in this GitHub repository.
npm install @trycourier/courier
commandStep 1: Add the Slack integration to Courier
First, head to the Slack channel in Courier https://app.courier.com/channels/slack and click "Install Provider". If you only want to send with Teams, you can skip to the “Send with Microsoft Teams” section.
Step 2: Create a Slack App
Navigate to the Slack Apps page and log into Slack. Click the Create an App button and provide your App Name as depicted below.
Step 3: Add OAuth Permission and Scopes
Define the permissions that your Slack App is authorized to do.
To do so, navigate to the OAuth & Permissions page in the sidebar menu and select the following options from the Scopes section:
Afterward, click the Install App to Workspace or Reinstall App button at the top of the page. This will generate an output -"Bot User OAuth Token" as depicted below, which will be needed later.
Step 4: Send a Slack DM with Node.js
Add the code snippet below to your codebase (e.g. index.js
) and update the following properties:
auth-token
with your Courier API keyslack_access_token
with the Bot User OAuth Tokenexample@email.com
with your user's email address (this is the email associated with the recipient's Slack Account)1const { CourierClient } = require("@trycourier/courier");23const courier = CourierClient({ authorizationToken: "auth_token" });45async function send_message() {6const { requestId } = await courier.send({7message: {8to: {9slack: {10access_token: "slack_access_token",11email: "example@email.com"12}13},14content: {15title: "Important Survey Reminder",16body: "This is a reminder to fill out your survey by the end of this week.",17},18routing: {19method: "single",20channels: ["direct_message"]21}22},23});24console.log(requestId)25}2627send_message()
Run the Node.js program to see your notification popup in the user's Slack direct message!
Check your Courier logs for errors if your user did not receive the message.
We can now try sending the same message via Teams. If you only want to send with Slack, you can skip to the “Routing to multiple channels” section.
Step 1: Sign up for a Microsoft 365 Developer Account
If you do not have a Microsoft 365 developer account, follow the instructions from this guideline to create an account. If you already have an account, you can skip this step.
Step 2: Create a Teams App
Create a new App in Teams. You will need to install the Developer Portal from the Team Apps.
After installing the Developer Portal, navigate to the Apps tab and click the New App button. Then, you will get prompted to enter the application name.
After clicking the Add button, you will be redirected to a new window where you can see the App ID. Make sure to copy the App ID for later use.
Then, click App features from the left menu and click on the tile named Bot. It will open a new window for selecting a bot and bot scopes.
If you do not have a bot created already, follow these steps to create a new one. Also, make sure to save the password generated during the process. Keep the Messaging endpoint blank for the moment.
Step 3: Deploy the bot
Now you need to deploy the App to create the messaging endpoint. For that, open the Microsoft Teams Bot Starter Repo and click the Deploy to Netlify button. There, you will have to connect to your GitHub account and enter your App ID (Bot ID), App Password, Courier Auth Token, and a name for the repo.
Once the site is deployed, copy your site URL since you need it to finish installing the bot.
Step 4: Install the bot
Now, go back to the Tools > Bot Management tab in Developer Portal and select the created bot to finalize the installation process. There, select the Configure option and copy the site URL to the Bot endpoint address field.
Then, select the Channels option from the left menu and tick the Microsoft Teams option.
Step 5: Add the Teams integration to Courier
Now, you need to create a Teams integration in Courier. For that, navigate to the Channels tab and select Microsoft Teams from the options. Then, it will show a window like the one below. Enter the App ID, App Password and click the Install Provider button.
Step 6: Sending a Simple Teams Notification with Node.js
Add the code snippet below to your codebase (e.g. index.js ) and update the following properties:
auth-token
with your Courier API keyconversation_id
: get the conversation id from threadId query parameter from the URL after opening Microsoft Teams in the browserservice_url
: the service URL associated with that Microsoft Teams tenant (if you are located in the Americas Region, the service url is https://smba.trafficmanager.net/amer)tenant_id
: go to https://teams.microsoft.com/?tenantId and copying the value from the redirected URL tenantId query parameter, or click the three dots next to your Team and click Get link to team to find a link with the tenantId parameter1const { CourierClient } = require("@trycourier/courier");23const courier = CourierClient({ authorizationToken: "auth_token" });45async function send_message() {6const { requestId } = await courier.send({7message: {8to: {9ms_teams: {10conversation_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",11tenant_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",12service_url: "https://smba.trafficmanager.net/amer"13}14},15content: {16title: "Important Survey Reminder",17body: "This is a reminder to fill out your survey by the end of this week.",18},19routing: {20method: "single",21channels: ["direct_message"]22}23},24});25console.log(requestId)26}2728send_message()
Finally, you can run the Node.js program, and you will see a notification in your Team channel.
Microsoft Teams Resources
Courier's multi-channel functionality allows you to send notifications across multiple channels, including email, SMS, push notifications, voice, chatbots, and social media platforms, using a single API.
For example, if you want to send an urgent alert to your team, you would use Courier to send this alert as both Slack and Teams notifications.
1const { CourierClient } = require("@trycourier/courier");23const courier = CourierClient({ authorizationToken: "auth_token" });45async function send_message() {6const { requestId } = await courier.send({7message: {8to: {9slack: {10access_token: "access_token",11email: "example@email.com"12},13ms_teams: {14conversation_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",15tenant_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",16service_url: "https://smba.trafficmanager.net/amer"17}18},19content: {20title: "Important Survey Reminder",21body: "This is a reminder to fill out your survey by the end of this week.",22},23routing: {24method: "all",25channels: ["direct_message"]26}27},28});29console.log(requestId)30}3132send_message()
As you can see below, Courier supports a large selection of Email, SMS, chat, and push notification providers.
We can also send this as an email by adding the email
property within the to
object and adding the ”email”
channel to the channels array in the routing
object.
1const { CourierClient } = require("@trycourier/courier");23const courier = CourierClient({ authorizationToken: "auth_token" });45async function send_message() {6const { requestId } = await courier.send({7message: {8to: {9slack: {10access_token: "access_token",11email: "example@email.com"12},13ms_teams: {14conversation_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",15tenant_id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",16service_url: "https://smba.trafficmanager.net/amer"17},18email: "example@email.com"19},20// template: "template_id",21content: {22title: "Important Survey Reminder",23body: "This is a reminder to fill out your survey by the end of this week.",24},25routing: {26method: "all",27channels: ["direct_message", "email"]28}29},30});31console.log(requestId)32}3334send_message()
If you only want to send to the best of these three channels, you can simply change the method
type from all
to single
in the routing
object. This will send a Slack message. If that fails, it will send a Teams message. If that fails as well, it will send an email.
If you prefer a visual workflow, you can create an automation template within Courier.
Head over to the Notification Designer and create a new notification. Once you have created the notification, you will be able to select your channels. Here you can add Slack, Teams, and/or any other channels you would like to send with.
Click on any of the channels to customize your message. Once you have created your message, you can use the drag-and-drop "Library" on the left side to recreate the message for the remaining channels.
Click on the settings (gear) icon next to the template name (top right) to access the Notification ID, which you will need later to send this message.
The notification template will automatically send to selected channels (based on your template’s channel settings).
Create a new Automation, select a schedule Trigger, and add a Send step for your notification. We will update the Type to "Date" and Date to the specific date/time this message should be sent.
In the Send step, select JSON and use the Editor to add the recipient information. In the editor, click "+ Add field" and add slack
as an Object. Then click "+Add nested field" and add access_token
and email
with the appropriate values from the code above.
For Teams, click "+ Add field" again and add ms_teams
as an Object. Then click "+Add nested field" and add conversation_id
, tenant_id
, and service_id
, with the appropriate values from the code above.
This automation will now have the required user profile data to send to both Slack and MS Teams. If you also want to send an email or SMS, edit the JSON object to add a field for "email"
and "phone_number"
with the appropriate values.
Automating notifications in team communication platforms such as Slack and Teams can significantly improve team productivity and communication. However, building automated notifications from scratch can be complex and time-consuming. That's where Courier comes in with its easy-to-use Node.js SDK that allows developers to send notifications to multiple channels with just a few lines of code.
By following the steps outlined in this article, you can set up notification automation with Courier and Node.js for both Slack and Teams. Additionally, you can leverage Courier's multi-channel functionality to integrate other applications and channels into your notification system.
1. What is Courier?
Courier connects communication APIs, data, and development tools that your team already uses to deliver a best-in-class notification system that will trigger messages from your app at just the right time, using just the right channel. It provides powerful API primitives and reusable UI components for building, plus no-code tools for designing templates and communication sequences.
2. What is Slack?
Slack is a cloud-based messaging platform that enables teams to communicate and collaborate in real-time. It is known for its user-friendly interface and extensive third-party integrations, making it a highly customizable platform for teams of all sizes. Slack allows users to easily organize their conversations into channels, share files, and collaborate with other team members. It also offers multiple app integrations, including project management and automation tools.
3. What is Microsoft Teams?
Microsoft Teams is another popular communication and collaboration platform that is part of the Microsoft Office 365 suite. It enables teams to chat, share files, and collaborate in real time, both synchronously and asynchronously. With features such as video conferencing, screen sharing, and group chats, Microsoft Teams is ideal for businesses and organizations that require a comprehensive and centralized collaboration platform.
4. Missing Provider Support error message
If your message did not go through, check your Courier logs. For a "MISSING_PROVIDER_SUPPORT" error message, you will need to double-check if the Slack and/or Teams channels were installed properly in Courier. Try removing the channel(s) (go to the channel and click "Remove Channel" at the bottom of the page) that is causing the error and then adding it again.
Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.
Sign-up
How to Set Up Automatic Push Notifications Based on Segment Events
Push notifications have carved their own niche as a powerful tool for continuous user engagement. Regardless of whether an app is actively in use, they deliver your messages straight to your user's device. Two key players that can combine to enhance your push notification strategy are Segment and Courier. In this tutorial, we show you how to set up Courier to listen to your Segment events and then send push notifications to an Android device based on data from these events.
Sarah Barber
November 17, 2023
How to Send Firebase Notifications to iOS Devices Using Courier
This tutorial explains how to send push notifications to iOS devices from your iOS application code using Firebase FCM and Courier’s iOS SDK.
Martina Caccamo
November 01, 2023
Free Tools
Comparison Guides
Send up to 10,000 notifications every month, for free.
Get started for free
Send up to 10,000 notifications every month, for free.
Get started for free
© 2024 Courier. All rights reserved.