> ## Documentation Index
> Fetch the complete documentation index at: https://v0.x-docs.novu.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Slack

> Learn about how to use Slack provider for chat notifications

When using Slack you will have to save the integration credentials in the subscriber entity.

This guide will walk you through the steps needed to obtain the `webhookUrl` that Novu requires to send chat messages to your customers.

We will provide the basic flow that the user needs to perform, to successfully send notifications via the Slack integration.

<Note>We've a [dedicated guide](/guides/slack-guide) on integrating Novu in a Slack app.</Note>

### Creating application

This step is optional, if you already have a Slack application you can reuse it.

1. Go to Slack's developer dashboard [https://api.slack.com/apps](https://api.slack.com/apps).
2. Create a new application.

### Integrating Novu with Slack

There are two ways to integrate Novu with Slack - Novu Managed (recommended) and manually managed. Let’s look at both of them in detail:

### 1. Novu Managed (Recommended)

If you use this approach, then Novu will manage the OAuth flow and store the credentials

1. Configure your Slack application as mentioned [below](#configuring-slack-application).
2. You need to make a network request to the `Shareable URL` to perform authentication.
3. You can find the `Shareable URL` in the [Integration Store](https://web.novu.co/integrations?utm_campaign=docs-integrations-slack)

<Frame caption="Use the 'Shareable URL' from the Novu Integration Store">
  <img src="https://mintcdn.com/novu-v2-docs/sGuc2UrECiU5eWcY/images/channels-and-providers/shreable-url.png?fit=max&auto=format&n=sGuc2UrECiU5eWcY&q=85&s=536fa6be9f93eb7fe059cf010835186a" width="3562" height="2068" data-path="images/channels-and-providers/shreable-url.png" />
</Frame>

4. You can either add the `Add to Slack` button or use the `Shareable URL` directly, in the application you'll be using Novu in.
   <Info>The network request to the 'Shareable URL' will happen when the user clicks the 'Add to Slack' button.</Info>
5. This is to request permission for access (scope: incoming-webhook).
6. You can use the generated `Shareable URL` that is found under the Slack integration in the [Integration Store](https://web.novu.co/integrations?utm_campaign=docs-integrations-slack). The `Shareable URL` should have the following format:

```bash theme={null}
https://api.novu.co/v1/subscribers/<SUBSCRIBER_ID>/credentials/slack/oauth?environmentId=<ENVIRONMENT_ID>&integrationIdentifier=<PROVIDER_ID>.

```

* `SUBSCRIBER_ID` is a custom identifier used when identifying your users within the Novu platform.
* `ENVIRONMENT_ID` is a context of an environment you can locate your environment id in the setting in the [dashboard settings](https://web.novu.co/settings?utm_campaign=docs-integrations-slack).
* `PROVIDER_ID` (optional) is a unique identifier of the integration and is required when you have multiple slack integrations in Novu. You can locate your integration identifier in the [Integration Store](https://web.novu.co/integrations?utm_campaign=docs-integratons-slack). When not provided, the last created integration will be used.
  If you are using the `Add to Slack` button you have to provide the `Shareable URL` as the `redirect_uri` parameter like in this example. Make sure that the `Shareable URL` is URL encoded:

```html theme={null}
<a
  href="https://slack.com/oauth/v2/authorize?client_id=CLIENT_ID&scope=incoming-webhook&user_scope=&redirect_uri=https%3A%2F%2Fapi.novu.co%2Fv1%2Fsubscribers%2FSUBSCRIBER_ID%2Fcredentials%2Fslack%2Foauth%3FenvironmentId%3DENVIRONMENT_ID%26integrationIdentifier%3DINTEGRATION_IDENTIFIER"
  ><img
    alt="Add to Slack"
    height="40"
    width="139"
    src="https://platform.slack-edge.com/img/add_to_slack.png"
/></a>
```

7. Either you use the 'add to Slack' button or use the `Shareable URL`, you should land here:

<Frame caption="Select the channel and grant this permission">
  <img src="https://mintcdn.com/novu-v2-docs/sGuc2UrECiU5eWcY/images/channels-and-providers/permission-to-access.png?fit=max&auto=format&n=sGuc2UrECiU5eWcY&q=85&s=516c45a040f45546e073edaac25e2c63" width="3580" height="2052" data-path="images/channels-and-providers/permission-to-access.png" />
</Frame>

8. Then you'll be redirected to the address you chose in the [Integration Store](https://web.novu.co/integrations?utm_campaign=docs-integrations-slack):

<Frame caption="Select the channel and grant this permission">
  <img src="https://mintcdn.com/novu-v2-docs/sGuc2UrECiU5eWcY/images/channels-and-providers/redirect-url.png?fit=max&auto=format&n=sGuc2UrECiU5eWcY&q=85&s=44b9275d76ca78e94e7821dcacc4d2aa" width="3556" height="2058" data-path="images/channels-and-providers/redirect-url.png" />
</Frame>

<Info>You can use the URL of whichever page you want your users to land on, after successful execution</Info>
9\. That's it! Now you can trigger your workflow and send notifications:

<Frame caption="Now you can send notifications to the channel you chose earlier">
  <img src="https://mintcdn.com/novu-v2-docs/sGuc2UrECiU5eWcY/images/channels-and-providers/notifications-to-channel.png?fit=max&auto=format&n=sGuc2UrECiU5eWcY&q=85&s=0823161d8c09c85e5fd51ba459aa05c1" width="3382" height="1872" data-path="images/channels-and-providers/notifications-to-channel.png" />
</Frame>

<Note>Don't forget to check out our [dedicated guide](/guides/slack-guide) on integrating Novu in a Slack app for more.</Note>

### 2. Manually managed

To use the manually managed option, you need to generate a `webhookUrl` and plug it into your backend.

1. Goto 'Incoming Webhooks' in your Slack app settings and turn it on.

<Frame caption="Turn on 'Incoming Webhooks' in your Slack app">
  <img src="https://mintcdn.com/novu-v2-docs/CHmwHBrTe5Gwp_1J/images/guides/slack-guide/on.png?fit=max&auto=format&n=CHmwHBrTe5Gwp_1J&q=85&s=943d876af2ae6cf77eaa04e997fbb8b6" width="3024" height="1724" data-path="images/guides/slack-guide/on.png" />
</Frame>

2. Click on the 'Add New Webhook to Workspace':

<Frame caption="Click the 'Add New Webhook to Workspace' button">
  <img src="https://mintcdn.com/novu-v2-docs/CHmwHBrTe5Gwp_1J/images/guides/slack-guide/add.png?fit=max&auto=format&n=CHmwHBrTe5Gwp_1J&q=85&s=5840507cc0183b9208f7072acbab3504" width="3024" height="1562" data-path="images/guides/slack-guide/add.png" />
</Frame>

3. Now, go ahead and select the channel in which you want to send notifications and click 'allow'.

<Frame caption="Select the channel">
  <img src="https://mintcdn.com/novu-v2-docs/CHmwHBrTe5Gwp_1J/images/guides/slack-guide/install.png?fit=max&auto=format&n=CHmwHBrTe5Gwp_1J&q=85&s=87405339425bf97c741b497e17977341" width="3024" height="1668" data-path="images/guides/slack-guide/install.png" />
</Frame>

4. Then, copy the 'webhookUrl' from Slack.

<Frame caption="Copy the webhookUrl from Slack">
  <img src="https://mintcdn.com/novu-v2-docs/CHmwHBrTe5Gwp_1J/images/guides/slack-guide/hook.png?fit=max&auto=format&n=CHmwHBrTe5Gwp_1J&q=85&s=9204e5d6ff36b7bdf4f48dc763bf81ce" width="3024" height="1702" data-path="images/guides/slack-guide/hook.png" />
</Frame>

5. Now, you need to save the `webhookUrl` on the relevant subscriber entity in Novu. Here's an example to do the same using our Node SDK:

## Update credential webhookUrl

<Tabs>
  <Tab title="Node.js">
    ```javaScript theme={null}
    import {
      Novu,
      ChatProviderIdEnum
    } from '@novu/node';

    const novu = new Novu("<NOVU_API_KEY>");

    await novu.subscribers.setCredentials('subscriberId', ChatProviderIdEnum.Slack, {
      webhookUrl: "<WEBHOOK_URL>",
    });
    ```
  </Tab>

  <Tab title="cURL">
    ```bash theme={null}
    curl -L -X PUT 'https://api.novu.co/v1/subscribers/<SUBSCRIBER_ID>/credentials' \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -H 'Authorization: ApiKey <NOVU_API_KEY>' \
    -d '{
      "providerId": "slack",
      "credentials": {
          "webhookUrl": "<WEBHOOK_URL>"
      },
      "integrationIdentifier": "slack-MnGLxp8uy"
    }'
    ```
  </Tab>
</Tabs>

Checkout the [API reference](/api-reference/subscribers/update-subscriber-credentials) for more details.

* `subscriberId` is a custom identifier used when identifying your users within the Novu platform.
* `providerId` is a unique provider identifier. We recommend using our ChatProviderIdEnum.Slack if you’re using Node, else string of Slack to specify the provider.
* The third parameter is the credentials object. In this case, we use the `webhookUrl` property to specify the webhook URL generated in the previous step.

6. You are all set up and ready to send your first chat message via our @novu/node package or directly using the REST API.

## Configuring Slack application

1. Go to OAuth & Permissions on Slack's Developer Dashboard and add your REDIRECT\_URL in Redirect URLs.
   * If you use a manual Management solution, add the API endpoint you created in Step 1.
   * If you use the Novu Managed solution add `https://api.novu.co/v1/subscribers`.
2. Go to Incoming Webhooks from the left menu and Activate Incoming Webhooks.
3. Go to Manage Distribution and at the bottom of the page, tick Remove Hard Coded Information and Activate Public Distribution.

### Enabling HMAC Encryption

To enable Hash-Based Message Authentication Codes, you need to do the following steps:

1. Visit the integration store page and enable HMAC encryption under your chat provider.

2. The next step would be to generate an HMAC encrypted subscriberId on your backend:

   ```jsx theme={null}
   import { createHmac } from 'crypto';

   const hmacHash = createHmac('sha256', process.env.NOVU_API_KEY)
     .update(subscriberId)
     .digest('hex');

   ```

3. Add the newly created hash HMAC to the Sharable URL as a query.

This concludes the Slack provider guide.
