You can build a Slack bot that responds to @mentions, tracks thread context, and sends rich interactive messages using Chat SDK with Next.js. Chat SDK handles the platform integration (webhook verification, message parsing, and the Slack API) while a Redis state adapter tracks which threads your bot has subscribed to across serverless invocations. Together with Vercel for deployment, you get a production-ready Slack bot without managing infrastructure or writing platform-specific glue code.
This guide will walk you through scaffolding a Next.js app, configuring a Slack app, wiring up event handlers with Chat SDK, adding interactive cards and buttons, and deploying to Vercel.
Before you begin, make sure you have:
- Node.js 18+
- pnpm (or npm/yarn)
- A Slack workspace where you can install apps
- A Redis instance (local or hosted, such as Upstash)
Chat SDK is a unified TypeScript SDK for building chatbots across Slack, Teams, Discord, and other platforms. You register event handlers (like onNewMention and onSubscribedMessage), and the SDK routes incoming webhooks to them. The Slack adapter handles webhook verification, message parsing, and the Slack API. The Redis state adapter tracks which threads your bot has subscribed to and manages distributed locking for concurrent message handling.
When a user @mentions your bot, onNewMention fires. Calling thread.subscribe() tells the SDK to track that thread, so subsequent messages trigger onSubscribedMessage. This lets your bot maintain conversation context across multiple turns without you managing thread state yourself.
Create a new Next.js app and add the Chat SDK and adapter packages:
The chat package is the Chat SDK core. The @chat-adapter/slack and @chat-adapter/state-redis packages are the Slack platform adapter and Redis state adapter.
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/slack with your deployed webhook URL, then click Create.
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
If you're distributing the app across multiple workspaces via OAuth instead of installing it to one workspace, configure clientId and clientSecret on the Slack adapter and pass the same redirect URI used during the authorize step into handleOAuthCallback(request, { redirectUri }) in your callback route.
Create a .env.local file in your project root:
The Slack adapter auto-detects SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET from your environment, and createRedisState() reads REDIS_URL automatically.
Create lib/bot.ts with a Chat instance configured with the Slack adapter:
onNewMention fires when a user @mentions your bot. Calling thread.subscribe() tells the SDK to track that thread, so subsequent messages trigger onSubscribedMessage.
Create a dynamic API route that handles incoming webhooks:
This creates a POST /api/webhooks/slack endpoint. The waitUntil option ensures message processing completes after the HTTP response is sent. This is required on serverless platforms where the function would otherwise terminate before your handlers finish.
- 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
Chat SDK supports rich interactive messages using a JSX-like syntax. Update your bot to send cards with buttons:
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 your bot to Vercel:
After deployment, set your environment variables in the Vercel dashboard (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.
Check that your Slack app has the app_mentions:read scope and that the Event Subscriptions Request URL is correct. Slack sends a challenge request when you first set the URL, so your server must be running and reachable.
Confirm that SLACK_SIGNING_SECRET matches the value in your Slack app's Basic Information → App Credentials. A mismatched or missing signing secret will cause the adapter to reject incoming webhooks.
Verify that REDIS_URL is reachable from your deployment environment. If running locally, make sure your Redis instance is started. The state adapter uses Redis for distributed locking, so the bot won't process messages without a working connection.
Make sure your webhook route passes waitUntil to the handler, as shown in step 5. Without it, serverless functions can terminate before your event handlers finish.
Chat SDK Form BotBuild a bot that helps you address form submissions right from Slack, Teams, and more.
Chat SDK Deploy BotBuild a bot that lets you deploy projects from Slack, with a built-in approval flow.
The Complete Guide to Chat SDK
Learn how Chat SDK works end-to-end: from core concepts to building your first bot to deploying it across Slack, Teams, and more.
Yes, Chat SDK is free and open source. You can install it from npm, use it in commercial projects, and contribute to its development without any licensing cost. The official platform adapters published under @chat-adapter/* are also free to use. You will still need to pay for any third-party services your bot relies on, such as your chat platform's API tier, your AI model provider, and your Redis or Postgres host.
Yes, you can register as many adapters as you need on a single Chat instance. Add each adapter to the adapters object when you create your bot, and the same handlers will run for events from every connected platform. This is the main reason to use Chat SDK: you write your bot logic once and it works across Slack, Teams, Discord, Linear, and any other platform you add later, without changing the rest of your code.
Chat SDK supports nearly any JavaScript or TypeScript framework, so you can add it to your existing codebase without changing your stack. It works with Next.js, Nuxt, Hono, SvelteKit, Express, and other server frameworks that can handle HTTP requests. Each platform adapter exposes a webhook handler (such as bot.webhooks.slack) that you wire into your framework's routing, whether that is a Next.js route handler, a Hono route, a Nuxt server route, or something else.
No, Chat SDK works anywhere you can run a Node.js or TypeScript server. It is framework-agnostic and runs on Next.js, Nuxt, Hono, and other frameworks, so you can deploy it to Vercel, AWS, Netlify, Cloudflare Workers, your own infrastructure, or any other host. Vercel maintains the SDK and the official adapters, but there is no requirement to deploy on Vercel to use it.