Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 2.52 KB

mattermost.mdx

File metadata and controls

66 lines (47 loc) · 2.52 KB
title description
Mattermost
Learn about how to use Mattermost provider for chat notifications

When using Mattermost, you will have to store the integration credentials within the subscriber entity. Mattermost supports two ways to do this:

  1. Using the Mattermost Webhook integration.
  2. Using the Mattermost Bot integration.

Mattermost Webhook Integration

To integrate Mattermost with your application using the Mattermost Webhook integration, follow these steps:

  1. Create an incoming webhook in Mattermost. This can be done by going to the Integrations page and clicking on the Incoming Webhooks tab.
  2. Click on the Add Incoming Webhook button and configure the webhook settings. Be sure to select the channel where you want to receive notifications.
  3. Click on the Save button to generate a webhook URL.

Once you have the webhook URL, you can store it in the subscriber entity in your application. This will allow you to send notifications to Mattermost using the following code:

import { Novu, ChatProviderIdEnum } from '@novu/node'; 

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

await novu.subscribers.setCredentials('subscriberId', ChatProviderIdEnum.Mattermost, { webhookUrl: '<enter-mattermost-webhook-url>', });

// Send a notification to Mattermost using the subscriber ID and payload.
await novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>',
  {
    to: {
      subscriberId: '<UNIQUE_SUBSCRIBER_IDENTIFIER>',
    },
    payload: {
      message: 'This is a notification from my application!'
    },
  }
);

Mattermost Bot Integration

To integrate Mattermost with your application using the Mattermost Bot integration, you will need to create a Mattermost bot account and generate an API token for the bot. Once you have the API token, you can store it in the subscriber entity in your application.

Once you have stored the API token in the subscriber entity, you can send notifications to Mattermost using the following code:

import { Novu, ChatProviderIdEnum } from '@novu/node'; 

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

// Get the Mattermost bot API token for the subscriber.
await novu.subscribers.setCredentials('subscriberId', ChatProviderIdEnum.Mattermost, { botApiToken: '<enter-mattermost-bot-api-token>' });

// Send a notification to Mattermost using the bot API token.
await novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>', {
  to: {
    subscriberId: '<UNIQUE_SUBSCRIBER_IDENTIFIER>',
  },
  payload: {
    message: 'This is a notification from my application!',
  },
});