Build bots for chat platforms
import { Chat } from 'chat';
import { createSlackAdapter } from '@chat-adapter/slack';
import { createRedisState } from '@chat-adapter/state-redis';
import { connectSlackAdapter } from '@vercel/connect/chat';
export const bot = new Chat({
userName: 'my-bot',
adapters: {
slack: createSlackAdapter({
...connectSlackAdapter('slack/my-bot'),
}),
},
state: createRedisState(),
});
bot.onNewMention(async (thread) => {
await thread.subscribe();
await thread.post('Hello! Reply here to chat.');
});
bot.onSubscribedMessage(async (thread, message) => {
await thread.post(message.text);
});
import { streamText } from 'ai';
const model = process.env.AI_GATEWAY_MODEL;
if (!model) throw new Error('Set AI_GATEWAY_MODEL.');
bot.onNewMention(async (thread, message) => {
const result = streamText({
model,
prompt: message.text,
abortSignal: thread.signal,
});
await thread.post(result.textStream);
});
Keep the bot setup from Handle messages and replace its handlers with this example. Add the streamText import, install ai, configure AI Gateway authentication, and set AI_GATEWAY_MODEL to a model ID. See streaming responses.
import { Actions, Button, Card } from 'chat';
bot.onNewMention(async (thread) => {
await thread.post(Card({
title: 'Meet your bot',
children: [Actions([
Button({ id: 'hello', label: 'Say hello' }),
])],
}));
});
bot.onAction('hello', async ({ thread }) => {
if (thread) await thread.post('Hello again!');
});
Keep the bot setup from Handle messages and replace its handlers with this example. Add the shown imports to lib/bot.ts or lib/bot.js. See the cards and action handlers guides.
The Handle messages example connects to Slack through Vercel Connect, stores subscriptions in Redis, and echoes replies in mentioned threads. Use your connector UID in place of slack/my-bot and set REDIS_URL for shared state. Follow the Chat SDK quickstart to scaffold the bot with create-chat-sdk, connect Slack through Vercel Connect, and deploy it on Vercel.
Chat SDK separates your bot's behavior from the platform that delivers each event:
- Event handlers respond to mentions, subscribed messages, and interactions such as button clicks.
- Platform adapters connect your bot to services such as Slack, Discord, and Microsoft Teams. Each adapter translates platform events and outgoing messages into the shared API.
- State adapters store thread subscriptions, coordinate concurrent processing, and deduplicate events. Use persistent shared storage, such as Redis or PostgreSQL, when deploying to Vercel.
A bot can use multiple platform adapters with the same handlers. Supported features vary by platform; use the adapters guide to choose platform and state adapters and check their capabilities.
Expose your bot's webhook through a Vercel Function. With Next.js, a Route Handler passes incoming requests to the platform adapter and uses after to finish processing after sending the webhook response.
The function's maximum duration still applies to this processing. Use Vercel Workflows for work that must survive interruptions or wait for an external event, such as a human approval.
For a complete example with environment variables, persistent Redis state, and webhook configuration, follow the quickstart. To add a bot to an existing Next.js, Nuxt, Hono, Nitro, or TanStack Start app, choose a framework guide.
Chat SDK handles messaging and interactions. You can build a bot without a language model, or combine it with other tools:
| Tool | Use it to |
|---|---|
| AI Gateway | Stream model responses with AI SDK and conversation history. |
| Vercel Connect | Resolve provider credentials at runtime and receive supported platform events through Connect triggers. |
| eve | Run messages through an eve agent while keeping Chat SDK adapters and event handlers. |
| Vercel Passport | Use verified identities to store and retrieve per-user conversation history. |
| Vercel Sandbox | Analyze files with an agent using the AI SDK Bash tool. |
| Vercel Workflows | Pause a durable task for approval from a chat card. |
Explore the integration guides for complete examples.
Persistent Chat SDK state keeps track of subscriptions and coordinates event processing. Vercel Workflows provides durable execution for the tasks your bot starts.
Your bot can reply with a card that the model composes, instead of plain text. With json-render, you define a catalog of components such as tables, charts, and buttons. The model writes a JSON spec from that catalog, and @json-render/chat converts the spec into a Chat SDK card. Each adapter posts the card in its platform's native format, such as Block Kit on Slack and Adaptive Cards on Microsoft Teams.
The card fills in as the model writes. streamCard posts the message once the card has content, edits it as new elements arrive, and finishes with a validated card. Because the model composes each card from one catalog, you don't build and maintain a separate tool for each message shape.
Follow Stream generative UI with json-render to add generated cards to your bot, or try prompts in the json-render Chat SDK playground.
Install the Chat SDK skill to give your coding agent guidance on SDK APIs, adapter patterns, and project conventions:
pnpx skills add vercel/chatThe skill uses the documentation bundled in node_modules/chat/docs, along with adapter guides and starter templates.
For guidance across the Vercel platform, install the Vercel Plugin. It includes the Chat SDK skill, specialist agents, and slash commands:
pnpx plugins add vercel/vercel-pluginSee the plugin setup guide for prerequisites and supported tools.
Deploy a Slack research bot with Claude Managed Agents, a knowledge bot with Nuxt, or a community bot with Next.js:
Chat SDK is an open-source TypeScript library from Vercel for building chat bots that run on several platforms from one codebase. You write event handlers once, and platform adapters translate them for Slack, Microsoft Teams, Google Chat, Discord, Telegram, WhatsApp, GitHub, Linear, and other services. Install the chat package from npm, then add an adapter for each platform your bot uses. See Chat SDK adapters for the options.
Yes. Chat SDK is open source under the MIT license, and its code is in the vercel/chat repository on GitHub. The library has no fee. You pay for the infrastructure your bot uses, such as Vercel Functions, a Redis or PostgreSQL database for state, and model usage through AI Gateway.
Yes. Chat SDK's webhook handlers accept a standard Web Request and return a Response, and you pass your platform's background-task function as the waitUntil option. Vercel Connect is also optional. Without it, adapters read credentials such as SLACK_BOT_TOKEN and SLACK_SIGNING_SECRET from environment variables. When you deploy on Vercel, you can add Vercel Connect for managed credentials and provision a state database from the Marketplace.
No. Chat SDK handles messages, threads, cards, and button clicks, so you can build a bot that answers slash commands, posts notifications, or follows fixed rules without a language model. To add AI responses, pass a model stream to thread.post(). Chat SDK accepts any AsyncIterable<string> and detects AI SDK and TanStack AI streams automatically. See Chat SDK with AI Gateway.
Pass the stream from AI SDK's streamText() to thread.post(), and await the call so the handler stays active until the stream finishes. In Slack, Chat SDK uses Slack's native streaming API to update the message as text arrives. On Discord and Google Chat, it posts a message and edits it as chunks arrive, throttling the edits to avoid rate limits. Adapters such as GitHub and WhatsApp wait for the whole stream and post one final message. See streaming responses. To stream a card with tables, charts, and buttons instead of text, see Stream generative UI with json-render.
Was this helpful?


