Prerequisites
- Node.js 18+
- pnpm (or npm/yarn)
- A Slack workspace where you can install apps
- A Redis instance for state management
Create a Next.js app
Scaffold a new Next.js project and install Chat SDK dependencies:Terminal
Create a Slack app
- Go to api.slack.com/apps
- Click Create New App then From an app manifest
- Select your workspace and paste the following manifest:
slack-manifest.yml
- Replace
https://your-domain.com/api/webhooks/slackwith your deployed webhook URL - Click Create
Get credentials
After creating the app:- Go to OAuth & Permissions, click Install to Workspace, and copy the Bot User OAuth Token (
xoxb-...) — you’ll need this asSLACK_BOT_TOKEN - Go to Basic Information → App Credentials and copy the Signing Secret — you’ll need this as
SLACK_SIGNING_SECRET
Configure environment variables
Create a.env.local file in your project root:
.env.local
Create the bot
Createlib/bot.ts with a Chat instance configured with the Slack adapter:
lib/bot.ts
SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET from your environment, and createRedisState() reads REDIS_URL automatically.
onNewMention fires when a user @mentions your bot. Calling thread.subscribe() tells the SDK to track that thread, so subsequent messages trigger onSubscribedMessage.
Create the webhook route
Create a dynamic API route that handles incoming webhooks:app/api/webhooks/[platform]/route.ts
POST /api/webhooks/slack endpoint. The waitUntil option ensures message processing completes after the HTTP response is sent — required on serverless platforms where the function would otherwise terminate before your handlers finish.
Test locally
- Start your development server (
pnpm dev) - Expose it with a tunnel (e.g.
ngrok http 3000) - Update the Slack Event Subscriptions Request URL to your tunnel URL
- Invite your bot to a Slack channel (
/invite @mybot) - @mention the bot — it should respond with “Hello! I’m listening to this thread now.”
- Reply in the thread — it should echo your message back
Add interactive features
Chat SDK supports rich interactive messages using a JSX-like syntax. Update your bot to send cards with buttons:lib/bot.tsx
The file extension must be
.tsx (not .ts) when using JSX components like Card and Button. Make sure your tsconfig.json has "jsx": "react-jsx" and "jsxImportSource": "chat".Deploy to Vercel
Deploy your bot to Vercel:Terminal
SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET, REDIS_URL). If your manifest used a placeholder URL, update the Event Subscriptions and Interactivity Request URLs in your Slack app settings to your production URL.
Next steps
- Cards — Build rich interactive messages with buttons, fields, and selects
- Modals — Open forms and dialogs from button clicks
- Streaming — Stream AI-generated responses to chat
- Actions — Handle button clicks, select menus, and other interactions
- Slack adapter — Multi-workspace OAuth, token encryption, and full configuration reference