โ† back
Packages ยท Chat

@notifkit/provider-slack

The native Slack transport. Posts to Slack channels, direct messages (DMs), or Incoming Webhook URLs with support for plain text, mentions, and rich Block Kit UI components.

npm install @notifkit/provider-slack
import { NotifkitServer } from "notifkit";
import { SlackTransport } from "@notifkit/provider-slack";

const server = new NotifkitServer({
  services: ["all"],
  providers: [
    new SlackTransport({
      botToken: process.env.SLACK_BOT_TOKEN, // xoxb-...
      webhookUrl: process.env.SLACK_WEBHOOK_URL, // optional fallback webhook
    }),
  ],
});

Options

OptionRequiredNotes
botToken / tokenoptional*Bot or user OAuth token (xoxb-... or xoxp-...). Required for sending to Slack channels or user IDs via chat.postMessage.
webhookUrloptional*Default Incoming Webhook URL. Used when a message or recipient specifies no destination target.
appIdnoDescriptive app ID for multi-workspace logging.
loggernoA notifkit logger instance.
limitsnoProvider sliding-window rate limit. Defaults to { limit: 1000, windowSeconds: 10 }.

*At least one of botToken or webhookUrl must be provided.

Destinations

A recipient's slack contact target determines how the transport sends:

  • Channel ID (e.g. C0123456789) or User ID (e.g. U0123456789 for DMs): Dispatched via Slack Web API (chat.postMessage) using botToken.
  • Incoming Webhook URL (e.g. https://hooks.slack.com/services/...): Posted directly to the webhook URL without requiring a bot token.

Which template keys it reads

Template keyLands as
text or bodyThe message text or fallback notification banner.
blocksAn array of Slack Block Kit layout objects (sections, dividers, actions, context).
channelOverride the destination channel ID, user ID, or webhook URL per template.

Block Kit example

await notifkit.syncTemplates({
  templates: [
    {
      id: "incident-alert",
      channel: "slack",
      content: {
        text: "Incident alert: {{service}} is degraded",
        blocks: [
          {
            type: "header",
            text: { type: "plain_text", text: "๐Ÿšจ Service Incident" }
          },
          {
            type: "section",
            text: { type: "mrkdwn", text: "*Service:* {{service}}\n*Severity:* {{severity}}" }
          }
        ]
      },
    },
  ],
});
automatic deactivation

If Slack returns errors indicating a dead destination (such as channel_not_found, is_archived, user_not_found, or not_in_channel), notifkit flags the contact target as invalid and suspends future deliveries to that target.