@chat-adapter/slack
Slack adapter for Chat SDK. Configure single-workspace or multi-workspace OAuth deployments.
Installation
Single-workspace mode
For bots deployed to a single Slack workspace. The adapter auto-detects SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET from environment variables:
Multi-workspace mode
For apps installed across multiple Slack workspaces via OAuth, omit botToken and provide OAuth credentials instead. The adapter resolves tokens dynamically from your state adapter using the team_id from incoming webhooks.
When you pass any auth-related config (like clientId), the adapter won't fall back to env vars for other auth fields, preventing accidental mixing of auth modes.
OAuth callback
The adapter handles the full Slack OAuth V2 exchange. Point your OAuth redirect URL to a route that calls handleOAuthCallback:
Using the adapter outside webhooks
During webhook handling, the adapter resolves tokens automatically from team_id. Outside that context (e.g. cron jobs or background workers), use getInstallation and withBotToken:
withBotToken uses AsyncLocalStorage under the hood, so concurrent calls with different tokens are isolated.
Removing installations
Token encryption
Pass a base64-encoded 32-byte key as encryptionKey to encrypt bot tokens at rest using AES-256-GCM:
When encryptionKey is set, setInstallation() encrypts the token before storing and getInstallation() decrypts it transparently.
Slack app setup
1. Create a Slack app from manifest
- Go to api.slack.com/apps
- Click Create New App then From an app manifest
- Select your workspace and paste the following manifest:
- Replace
https://your-domain.com/api/webhooks/slackwith your deployed webhook URL - Click Create
2. Get credentials
After creating the app, go to Basic Information → App Credentials and copy:
- Signing Secret as
SLACK_SIGNING_SECRET - Client ID as
SLACK_CLIENT_ID(multi-workspace only) - Client Secret as
SLACK_CLIENT_SECRET(multi-workspace only)
Single workspace: Go to OAuth & Permissions, click Install to Workspace, and copy the Bot User OAuth Token (xoxb-...) as SLACK_BOT_TOKEN.
Multi-workspace: Enable Manage Distribution under Basic Information and set up an OAuth redirect URL pointing to your callback route.
3. Configure slash commands (optional)
- Go to Slash Commands in your app settings
- Click Create New Command
- Set Command (e.g.,
/feedback) - Set Request URL to
https://your-domain.com/api/webhooks/slack - Add a description and click Save
Configuration
All options are auto-detected from environment variables when not provided. You can call createSlackAdapter() with no arguments if the env vars are set.
*signingSecret is required — either via config or SLACK_SIGNING_SECRET env var.
Environment variables
Features
Messaging
Rich content
Conversations
Message history
Platform-specific
Slack Assistants API
The adapter supports Slack's Assistants API for building AI-powered assistant experiences. This enables suggested prompts, status indicators, and thread titles in assistant DM threads.
Event handlers
Register handlers on the Chat instance:
Adapter methods
The SlackAdapter exposes these methods for the Assistants API:
Required scopes and events
Add these to your Slack app manifest for Assistants API support:
Stream with stop blocks
When streaming in an assistant thread, you can attach Block Kit elements to the final message:
Troubleshooting
handleOAuthCallback throws "Adapter not initialized"
- Call
await bot.initialize()beforehandleOAuthCallback()in your callback route. - In a Next.js app, this ensures:
- state adapter is connected
- the Slack adapter is attached to Chat
- installation writes succeed
"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