---
title: Using Slack with Notehub
description: A guide to sending Notehub data and alerts to Slack, using either a Slack route or a Slack notification on an alert monitor, with Blues Notecard over Cellular, Satellite, LoRa, or WiFi connectivity.
source_url: https://dev.blues.io/notehub/messaging-and-data-pipelines/using-slack-with-notehub/
canonical_url: https://dev.blues.io/notehub/messaging-and-data-pipelines/using-slack-with-notehub/
markdown_url: https://dev.blues.io/notehub/messaging-and-data-pipelines/using-slack-with-notehub.md
---

# Using Slack with Notehub

Notehub can post messages to [Slack](https://slack.com/), making it easy to get device data and alerts in front of your team. There are two places you can do this.

- A **Slack route** forwards events to Slack as they arrive in Notehub. Use a route when you want a running feed of some or all of your events.
- A **Slack notification on an alert monitor** posts to Slack only when a monitor's condition is met — a device stops checking in, or a value in a Note crosses a threshold you define.

Both options ask for the same set of Slack values, so the setup below applies to either path. Configure your Slack app once, then jump to the section for the option you want.

> **Note:**
>
> To send messages to Slack you must have admin access to a Slack channel, and have created a Slack app. If you haven't built a Slack app before, you can start a new one [here](https://api.slack.com/apps/new).

## Creating a Slack App

Every Notehub-to-Slack connection posts as a Slack app, so start there. If you already have an app you want to use, skip ahead to [Slack Configuration Fields](#slack-configuration-fields).

1. Create a new app at [api.slack.com/apps/new](https://api.slack.com/apps/new), choosing **Blank app** unless you have a manifest to work from.

2. Give the app a name your team will recognize in the channel (for example, "Notehub"), and select the workspace you want it to post into.

Once the app exists, decide how Notehub should authenticate to it. Notehub supports two mechanisms, and the choice determines which values you need to collect next.

- (Recommended) A **Webhook** is the easiest way to interact with Slack. You create a webhook URL that can post to a single Slack channel, and Notehub needs nothing else.

- A **Bearer** connection uses OAuth authentication to allow your Slack app to send messages. With this option you'll need to generate an OAuth token and add permissions to your app, but you'll be able to send Slack messages to different channels.

## Slack Configuration Fields

Whether you're creating a route or adding a Slack notification to an alert monitor, Notehub presents the same block of Slack fields. This section explains what each one wants; the two sections that follow cover where to find that block and what surrounds it.

The first field is always **Slack Route Type**, which selects the authentication mechanism you chose above — **Webhook** or **Bearer**. The fields below it change depending on which one you pick.

### Webhook Route Type

Complete these steps if you're using a **Slack Route Type** of **Webhook**.

1. To find your **Webhook URL**, select your Slack app on [api.slack.com/apps](https://api.slack.com/apps), select **Incoming Webhooks** in the menu, and enable the **Activate Incoming Webhooks** switch.

2. After you activate incoming webhooks, scroll down the same page and find the **Add New Webhook to Workspace** button. Click that button and complete the subsequent steps to generate a Webhook URL. Copy that URL and paste it into the **Webhook URL** field in Notehub.

   ![Webhook URL location](https://dev.blues.io/images/notehub/slack/webhook-url.png?v=627b2375)

3. [Skip ahead to Additional Fields](#additional-fields).

### Bearer Route Type

Complete these steps if you're using a **Slack Route Type** of **Bearer**.

1. Provide the **Channel** ID you would like to send your messages to. The easiest way to get your channel ID is to right click on a channel within Slack, select **Copy**, and then **Copy Link**. The channel is in the URL you just copied, and is in the format `CXXXXXXXXXX`.

   ![Slack Channel ID location](https://dev.blues.io/images/notehub/slack/channel-id.png?v=0bde65e2)

2. To generate a **Bearer Token**, select your [Slack app](https://api.slack.com/apps) and click the **OAuth & Permissions** menu. Scroll down and find the **OAuth Tokens for Your Workspace** heading. Click the **Install to Workspace** button and complete the subsequent steps. When you're done use the **Copy** button to get the token you need for Notehub.

   ![OAuth token location](https://dev.blues.io/images/notehub/slack/oauth-token-location.png?v=2b5f72ea)

In order to successfully use your token to post to a channel you'll need to complete a few additional steps.

1. While still on the same **OAuth & Permissions** settings page, scroll down to the **Scopes** section, click the **Add an OAuth Scope** button, and add the `chat:write` permission. You'll likely be prompted to restart your app for the permission change to take effect.

2. In your Slack client, you need to invite your app to every channel you intend to send messages to. The easiest way to do this is with the `/invite` command.

   ![Inviting an app to Slack](https://dev.blues.io/images/notehub/slack/app-invite.png?v=675e2abf)

   > **Note:**
   >
   > Bearer connections post messages using Slack's `chat.postMessage` API, which only delivers to channels the app is a member of. If you skip this invite step, messages will fail to post even when the token and channel ID are correct.

### Additional Fields

Both Slack route types finish with the same pair of fields.

For **Message Type** you can select either **Text** or **Blocks**. Selecting **Text** allows you to provide simple strings. Use **Blocks** if you need to generate richer Slack messages, and use the [Slack Block Kit Builder](https://app.slack.com/block-kit-builder/#) to generate the syntax you need.

> **Note:**
>
> For the **Blocks** field you can paste either the entire JSON payload produced by the Block Kit Builder (the object that contains a top-level `"blocks"` key) or just the value of the `blocks` array itself—Notehub accepts both forms.
>
> You can use [placeholder variables](https://dev.blues.io/notehub/notehub-walkthrough.md#using-placeholder-variable-substitution-interpolation) to include event-specific information in your messages. If you're configuring Slack for the first time, try using `[.body]` as **Text**, as it sends your Note's `body` as your message.

## Using Slack in a Notehub Route

A Slack route forwards events to Slack as Notehub receives them. Use this when you want an ongoing feed of the Notes your devices send.

1. Open your Notehub project, head to the **Routes** tab, click the **Create Route** button, and then find the Slack option. Click **Select** to get started.

   ![Slack route option](https://dev.blues.io/images/notehub/slack/route-option.png?v=a8621e06)

2. Give the route a **Route name**, which controls how the route is identified within Notehub.

3. Fill in the Slack fields — **Slack Route Type**, the webhook or bearer values it asks for, and **Message Type**. See [Slack Configuration Fields](#slack-configuration-fields) above for what each one needs.

4. Scroll to the **Filters** section, set the **Notefiles** dropdown to **Selected Notefiles**, and select the Notefile you want to use this route for.

   ![route filters](https://dev.blues.io/images/notehub/edge-impulse/route-filters.png?v=ee773186)

5. When you're all set, click the **Create Route** button to save your new route.

## Using Slack in a Notehub Alert Monitor

An [alert monitor](https://dev.blues.io/notehub/notehub-walkthrough.md#configuring-alert-monitors) posts to Slack only when the condition you define is met, rather than on every event. Notehub supports two monitor sources, and both can notify Slack.

- A **Heartbeat** monitor fires when a device hasn't communicated with Notehub for a period of time you set.
- An **Events** monitor fires when a value inside the Notes your devices send crosses a threshold.

Follow [Creating a Heartbeat Monitor](https://dev.blues.io/notehub/notehub-walkthrough.md#creating-a-heartbeat-monitor) or [Creating an Event Monitor](https://dev.blues.io/notehub/notehub-walkthrough.md#creating-an-event-monitor) to set up the monitor itself, then configure Slack in its **Notification** section.

1. Under **Notification**, set **Notification Type** to **Slack**.

2. Fill in the Slack fields that appear: **Slack Route Type**, the webhook or bearer values it asks for, and **Message Type**. These are the same fields a route uses, so see [Slack Configuration Fields](#slack-configuration-fields) above for what each one needs.

3. Click the **Save Monitor** button to save your changes.

> **Note:**
>
> A monitor's Slack settings live on the monitor itself — they are not a reference to a route you created on the **Routes** tab. If you want the same channel used by both a route and a monitor, enter the webhook URL (or token and channel) in each one.

> **Tip:**
>
> Monitors, including their Slack notification settings, can also be created, updated, and deleted programmatically through the [Monitor API](https://dev.blues.io/api-reference/notehub-api/monitor-api.md).

## Testing Your Slack Configuration

With your route or monitor saved you're now ready to test it out. The easiest way to make sure everything is working is by sending a Note using the Notecard's In-Browser Terminal.

1. Use the In-Browser Terminal to connect to your Notecard via USB. (If you're unsure how to do this check out the [Notecard quickstart](https://dev.blues.io/quickstart/notecard-quickstart.md).)

   ![Notehub.io: Web Console Button](https://dev.blues.io/images/guides/route-guides/notecard-web-console-button.png?v=25006268)

2. Once connected, associate your Notecard with a Notehub project (if it isn't already).

   ```json
   {
     "req": "hub.set",
     "product": "com.example.yourname:yourproject"
   }
   ```

3. Next, run the command below to queue a Note onto the `data.qo` Notefile. You may wish to change the `file` and `body` of your command, depending on how you configured your route or monitor.

   ```json
   {
     "req": "note.add",
     "file": "data.qo",
     "body": {
       "temp": 22
     }
   }
   ```

4. Finally, run the `hub.sync` request to send this data to your Notehub project.

   ```json
   {
     "req": "hub.sync"
   }
   ```

When the data reaches your Notehub project, Notehub will post to Slack. And if all goes well, you should see your message appear in your channel. For example, if you use a **Text** of `[.body]`, you should see a message that looks like this.

![Data within Slack](https://dev.blues.io/images/notehub/slack/slack-message.png?v=05549a17)

> **Note:**
>
> A route posts to Slack for every event that clears its filters, so the Note above is enough to see a message. A monitor only posts when its condition is met, so testing one takes a little more:
>
> - For an **Events** monitor, send a `body` value that actually crosses the threshold you configured — a `temp` of `22` won't trigger a monitor watching for readings above `80`.
> - For a **Heartbeat** monitor, stop syncing and wait out the inactivity period you configured. Lower that period temporarily if you don't want to wait.
>
> Alert notifications are also logged under the **Alerts** tab, which is a quick way to confirm a monitor fired even if the Slack message didn't arrive. See [Alert Logging](https://dev.blues.io/notehub/notehub-walkthrough.md#alert-logging).

> **Tip:**
>
> To debug a route or inspect the exact request Notehub sends to your third-party service, open an event in Notehub, click **Route as cURL**, and choose the appropriate HTTP-based route. The modal shows a cURL command that reproduces the same request Notehub makes, with secrets (API keys, passwords, etc.) replaced by placeholders.
>
> ![view curl request from route](https://dev.blues.io/images/guides/route-tutorial/event-route-curl.png?v=22e6a261)
