@chat-adapter/slack
v4.6.0
Published
Slack adapter for chat
Downloads
9,597
Readme
@chat-adapter/slack
Slack adapter for the chat SDK.
Installation
npm install chat @chat-adapter/slackUsage
import { Chat } from "chat";
import { createSlackAdapter } from "@chat-adapter/slack";
const chat = new Chat({
userName: "mybot",
adapters: {
slack: createSlackAdapter({
botToken: process.env.SLACK_BOT_TOKEN!,
signingSecret: process.env.SLACK_SIGNING_SECRET!,
}),
},
});
// Handle @mentions
chat.onNewMention(async (thread, message) => {
await thread.post("Hello from Slack!");
});Configuration
| Option | Required | Description |
|--------|----------|-------------|
| botToken | Yes | Slack bot token (starts with xoxb-) |
| signingSecret | Yes | Slack signing secret for webhook verification |
Environment Variables
SLACK_BOT_TOKEN=xoxb-...
SLACK_SIGNING_SECRET=...Slack App Setup
1. Create a Slack App
- Go to api.slack.com/apps
- Click Create New App → From scratch
- Enter app name and select workspace
- Click Create App
2. Configure Bot Token Scopes
- Go to OAuth & Permissions in the sidebar
- Under Scopes → Bot Token Scopes, add:
app_mentions:read- Receive @mention eventschannels:history- Read messages in public channelschannels:read- View basic channel infochat:write- Send messagesgroups:history- Read messages in private channelsgroups:read- View basic private channel infoim:history- Read direct messagesim:read- View basic DM inforeactions:read- View emoji reactionsreactions:write- Add/remove emoji reactionsusers:read- View user info (for display names)
3. Install App to Workspace
- Go to OAuth & Permissions
- Click Install to Workspace
- Authorize the app
- Copy the Bot User OAuth Token (starts with
xoxb-) →SLACK_BOT_TOKEN
4. Get Signing Secret
- Go to Basic Information
- Under App Credentials, copy Signing Secret →
SLACK_SIGNING_SECRET
5. Configure Event Subscriptions
- Go to Event Subscriptions
- Toggle Enable Events to On
- Set Request URL to:
https://your-domain.com/api/webhooks/slack- Slack will verify the URL immediately
- Under Subscribe to bot events, add:
app_mention- When someone @mentions your botmessage.channels- Messages in public channelsmessage.groups- Messages in private channelsmessage.im- Direct messages
- Click Save Changes
6. (Optional) Enable Interactivity
If you want to use buttons, modals, or other interactive components:
- Go to Interactivity & Shortcuts
- Toggle Interactivity to On
- Set Request URL to:
https://your-domain.com/api/webhooks/slack
Features
- Message posting and editing
- Thread subscriptions
- Reaction handling (add/remove/events)
- File attachments
- Rich cards (Block Kit)
- Action callbacks (interactive components)
- Direct messages
Troubleshooting
"Invalid signature" error
- Verify
SLACK_SIGNING_SECRETis correct - Check that the request timestamp is within 5 minutes (clock sync issue)
Bot not responding to messages
- Verify Event Subscriptions are configured
- Check that the bot has been added to the channel
- Ensure the webhook URL is correct and accessible
License
MIT
