← All @molecule/* packages · App templates
@molecule/api-channel-slackProvider bond · channel · API (Node) · v1.0.1 · Apache-2.0
Slack channel bond — implements @molecule/api-channel for sendMessage, webhook signature verification, and inbound event parsing.
npm install @molecule/api-channel-slacknpm · Source on GitHub · Implements @molecule/api-channel
@molecule/api-channel-slack is a provider bond on the API (Node) side: it implements the channel core interface (@molecule/api-channel) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { setProvider } from '@molecule/api-channel'
import { createProvider } from '@molecule/api-channel-slack'
setProvider(
'slack',
createProvider({
botToken: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
}),
)Works with: @molecule/api-channel, @molecule/api-secrets
Secrets: SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Slack channel bond for molecule.dev.
Implements the {@link ChannelProvider} interface from
@molecule/api-channel on top of @slack/web-api. Used by apps that
post into Slack channels (notifications, AI bot replies, helpdesk
announcements) and consume inbound Slack events (message events,
app_mention, slash commands) via signed webhooks.
import { setProvider } from '@molecule/api-channel'
import { createProvider } from '@molecule/api-channel-slack'
setProvider(
'slack',
createProvider({
botToken: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
}),
)
provider
npm install @molecule/api-channel-slack @molecule/api-channel @molecule/api-secrets @slack/web-api
ProcessEnvEnvironment variables consumed by the Slack channel provider.
interface ProcessEnv {
/**
* Bot user OAuth token (xoxb-…). Required for outbound `sendMessage`.
*/
SLACK_BOT_TOKEN: string
/**
* Slack app signing secret. Required for `verifyWebhookSignature`.
*/
SLACK_SIGNING_SECRET: string
}
SlackBlockMinimal shape of a Slack Block Kit block as used by this provider.
Slack's full block schema is large; we only constrain the fields we
emit (section and actions) and treat the rest as opaque pass-through.
interface SlackBlock {
type: string
text?: { type: string; text: string }
elements?: Array<{
type: string
text?: { type: string; text: string }
value?: string
action_id?: string
}>
}
SlackChannelConfigConfiguration for the Slack channel provider.
Tokens default to environment variables when not supplied so deployment
pipelines that already inject SLACK_BOT_TOKEN / SLACK_SIGNING_SECRET
keep working without extra wiring.
interface SlackChannelConfig {
/**
* Bot user OAuth token used for `chat.postMessage` and other Web API
* calls. Defaults to `process.env.SLACK_BOT_TOKEN`.
*/
botToken?: string
/**
* Slack app signing secret used to verify the HMAC of inbound webhook
* requests. Defaults to `process.env.SLACK_SIGNING_SECRET`.
*/
signingSecret?: string
/**
* Maximum allowed clock skew (in seconds) between the request timestamp
* and the verifier when validating `x-slack-signature`. Defaults to 300
* seconds (5 minutes), matching Slack's documented replay window.
*/
signatureToleranceSeconds?: number
/**
* Optional pre-built `WebClient`-shaped object. Tests inject a minimal
* mock here; production code should leave this unset and let the
* provider construct its own client from {@link botToken}.
*/
webClient?: SlackWebClientLike
}
SlackChatPostMessageArgsSubset of chat.postMessage arguments consumed by this provider.
interface SlackChatPostMessageArgs {
channel: string
text?: string
blocks?: SlackBlock[]
thread_ts?: string
attachments?: SlackOutboundAttachment[]
}
SlackChatPostMessageResponseSubset of chat.postMessage response fields consumed by this provider.
interface SlackChatPostMessageResponse {
ok: boolean
ts?: string
channel?: string
error?: string
}
SlackOutboundAttachmentSlack-flavoured outbound attachment (legacy attachments API). Used as a pass-through for callers that already speak Slack's attachment shape.
interface SlackOutboundAttachment {
fallback?: string
text?: string
title?: string
title_link?: string
image_url?: string
thumb_url?: string
color?: string
}
SlackWebClientLikeThe narrow surface of @slack/web-api's WebClient that this provider
actually uses. Defining it explicitly keeps tests free of the full SDK
type tree and documents the integration contract.
interface SlackWebClientLike {
chat: {
postMessage(args: SlackChatPostMessageArgs): Promise<SlackChatPostMessageResponse>
}
}
createProvider(config)Creates a Slack-backed {@link ChannelProvider}.
Tokens are sourced from the supplied {@link SlackChannelConfig} or, as a fallback, the documented environment variables. Methods that require a particular secret throw a generic error if the secret is missing — the missing token name is surfaced, but never its value.
function createProvider(config?: SlackChannelConfig): ChannelProvider
config — Provider configuration. All fields are optional; env vars cover the production wiring path.Returns: A ChannelProvider ready to be bonded under name 'slack'.
channelSlackSecretDefinitionsSecret definitions required by the Slack channel bond.
const channelSlackSecretDefinitions: SecretDefinition[]
providerDefault Slack channel provider — pre-bound to env vars at import time.
Convenience export for apps that want to bond('channel', 'slack', provider) without explicit configuration. Configuration via env vars
still applies.
const provider: ChannelProvider
Implements @molecule/api-channel interface.
Peer dependencies:
@molecule/api-channel ^1.0.1@molecule/api-secrets ^1.0.1SLACK_BOT_TOKEN (required) — Slack bot token
xoxb-...SLACK_SIGNING_SECRET (required) — Slack signing secret
@molecule/api-channel@molecule/api-secrets@slack/web-apiTokens are deliberately scrubbed from any error this provider raises; upstream stack traces that contain a token are still possible if a higher layer re-throws without going through this bond.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip:
read_activity tool (filter type 'channel'); never mock the flow or
modify production code to expose the message.undefined
placeholders, no secrets).