Chat SDK
Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, and WhatsApp. Write bot logic once, deploy everywhere.
Start with published sources
When Chat SDK is installed in a user project, inspect the published files that ship in node_modules:
node_modules/chat/docs/ # bundled docs
node_modules/chat/dist/index.d.ts # core API types
node_modules/chat/dist/jsx-runtime.d.ts # JSX runtime types
node_modules/chat/docs/contributing/ # adapter-authoring docs
node_modules/chat/docs/guides/ # framework/platform guides
If one of the paths below does not exist, that package is not installed in the project yet.
Read these before writing code:
node_modules/chat/docs/getting-started.mdx — install and setup
node_modules/chat/docs/usage.mdx — Chat config and lifecycle
node_modules/chat/docs/handling-events.mdx — event routing and handlers
node_modules/chat/docs/threads-messages-channels.mdx — thread/channel/message model
node_modules/chat/docs/posting-messages.mdx — post, edit, delete, schedule
node_modules/chat/docs/streaming.mdx — AI SDK integration and streaming semantics
node_modules/chat/docs/cards.mdx — JSX cards
node_modules/chat/docs/actions.mdx — button/select interactions
node_modules/chat/docs/modals.mdx — modal submit/close flows
node_modules/chat/docs/slash-commands.mdx — slash command routing
node_modules/chat/docs/direct-messages.mdx — DM behavior and openDM()
node_modules/chat/docs/files.mdx — attachments/uploads
node_modules/chat/docs/state.mdx — persistence, locking, dedupe
node_modules/chat/docs/adapters.mdx — cross-platform feature matrix
node_modules/chat/docs/api/chat.mdx — exact Chat API
node_modules/chat/docs/api/thread.mdx — exact Thread API
node_modules/chat/docs/api/message.mdx — exact Message API
node_modules/chat/docs/api/modals.mdx — modal element and event details
For the specific adapter or state package you are using, inspect that installed package's dist/index.d.ts export surface in node_modules.
Quick start
import { Chat } from "chat";
import { createSlackAdapter } from "@chat-adapter/slack";
import { createRedisState } from "@chat-adapter/state-redis";
const bot = new Chat({
userName: "mybot",
adapters: {
slack: createSlackAdapter(),
},
state: createRedisState(),
dedupeTtlMs: 600_000,
});
bot.onNewMention(async (thread) => {
await thread.subscribe();
await thread.post("Hello! I'm listening to this thread.");
});
bot.onSubscribedMessage(async (thread, message) => {
await thread.post(`You said: ${message.text}`);
});
Core concepts
- Chat — main entry point; coordinates adapters, routing, locks, and state
- Adapters — platform-specific integrations for Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, and WhatsApp
- State adapters — persistence for subscriptions, locks, dedupe, and thread state
- Thread — conversation context with
post(), stream(), subscribe(), setState(), startTyping()
- Message — normalized content with
text, formatted, attachments, author info, and platform raw
- Channel — container for threads and top-level posts
Event handlers
| Handler |
Trigger |
onNewMention |
Bot @-mentioned in an unsubscribed thread |
onDirectMessage |
New DM in an unsubscribed DM thread |
onSubscribedMessage |
Any message in a subscribed thread |
onNewMessage(regex) |
Regex match in an unsubscribed thread |
onReaction(emojis?) |
Emoji added or removed |
onAction(actionIds?) |
Button clicks and select/radio interactions |
onModalSubmit(callbackId?) |
Modal form submitted |
onModalClose(callbackId?) |
Modal dismissed/cancelled |
onSlashCommand(commands?) |
Slash command invocation |
onAssistantThreadStarted |
Slack assistant thread opened |
onAssistantContextChanged |
Slack assistant context changed |
onAppHomeOpened |
Slack App Home opened |
onMemberJoinedChannel |
Slack member joined channel event |
Read node_modules/chat/docs/handling-events.mdx, node_modules/chat/docs/actions.mdx, node_modules/chat/docs/modals.mdx, and node_modules/chat/docs/slash-commands.mdx before wiring handlers. onDirectMessage behavior is documented in node_modules/chat/docs/direct-messages.mdx.
Streaming
Pass any AsyncIterable<string> to thread.post() or thread.stream(). For AI SDK, prefer result.fullStream over result.textStream when available so step boundaries are preserved.
import { ToolLoopAgent } from "ai";
const agent = new ToolLoopAgent({ model: "anthropic/claude-sonnet-4.6" });
bot.onNewMention(async (thread, message) => {
const result = await agent.stream({ prompt: message.text });
await thread.post(result.fullStream);
});
Key details:
streamingUpdateIntervalMs controls post+edit fallback cadence
fallbackStreamingPlaceholderText defaults to "..."; set null to disable
- Structured
StreamChunk support is Slack-only; other adapters ignore non-text chunks
Cards and modals (JSX)
Set jsxImportSource: "chat" in tsconfig.json.
Card components:
Card, CardText, Section, Fields, Field, Button, CardLink, LinkButton, Actions, Select, SelectOption, RadioSelect, Table, Image, Divider
Modal components:
Modal, TextInput, Select, SelectOption, RadioSelect
await thread.post(
<Card title="Order #1234">
<CardText>Your order has been received.</CardText>
<Actions>
<Button id="approve" style="primary">Approve</Button>
<Button id="reject" style="danger">Reject</Button>
</Actions>
</Card>
);
Adapter inventory
Official platform adapters
| Platform |
Package |
Factory |
| Slack |
@chat-adapter/slack |
createSlackAdapter |
| Microsoft Teams |
@chat-adapter/teams |
createTeamsAdapter |
| Google Chat |
@chat-adapter/gchat |
createGoogleChatAdapter |
| Discord |
@chat-adapter/discord |
createDiscordAdapter |
| GitHub |
@chat-adapter/github |
createGitHubAdapter |
| Linear |
@chat-adapter/linear |
createLinearAdapter |
| Telegram |
@chat-adapter/telegram |
createTelegramAdapter |
| WhatsApp Business Cloud |
@chat-adapter/whatsapp |
createWhatsAppAdapter |
Official state adapters
| State backend |
Package |
Factory |
| Redis |
@chat-adapter/state-redis |
createRedisState |
| ioredis |
@chat-adapter/state-ioredis |
createIoRedisState |
| PostgreSQL |
@chat-adapter/state-pg |
createPostgresState |
| Memory |
@chat-adapter/state-memory |
createMemoryState |
Community adapters
chat-state-cloudflare-do
@beeper/chat-adapter-matrix
chat-adapter-imessage
@bitbasti/chat-adapter-webex
@resend/chat-sdk-adapter
chat-adapter-baileys
Coming-soon platform entries
- Instagram
- Signal
- X
- Messenger
Building a custom adapter
Read these published docs first:
node_modules/chat/docs/contributing/building.mdx
node_modules/chat/docs/contributing/testing.mdx
node_modules/chat/docs/contributing/publishing.mdx
Also inspect:
node_modules/chat/dist/index.d.ts — Adapter and related interfaces
node_modules/@chat-adapter/shared/dist/index.d.ts — shared errors and utilities
- Installed official adapter
dist/index.d.ts files — reference implementations for config and APIs
A custom adapter needs request verification, webhook parsing, message/thread/channel operations, ID encoding/decoding, and a format converter. Use BaseFormatConverter from chat and shared utilities from @chat-adapter/shared.
Webhook setup
Each registered adapter exposes bot.webhooks.<name>. Wire those directly to your HTTP framework routes. See node_modules/chat/docs/guides/slack-nextjs.mdx and node_modules/chat/docs/guides/discord-nuxt.mdx for framework-specific route patterns.
1---2name: chat-sdk3description: Vercel Chat SDK expert guidance. Use when building multi-platform chat bots — Slack, Telegram, Microsoft Teams, Discord, Google Chat, GitHub, Linear — with a single codebase. Covers the Chat class, adapters, threads, messages, cards, modals, streaming, state management, and webhook setup.4---5# Chat SDK67Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, and WhatsApp. Write bot logic once, deploy everywhere.89## Start with published sources1011When Chat SDK is installed in a user project, inspect the published files that ship in `node_modules`:1213```14node_modules/chat/docs/ # bundled docs15node_modules/chat/dist/index.d.ts # core API types16node_modules/chat/dist/jsx-runtime.d.ts # JSX runtime types17node_modules/chat/docs/contributing/ # adapter-authoring docs18node_modules/chat/docs/guides/ # framework/platform guides19```2021If one of the paths below does not exist, that package is not installed in the project yet.2223Read these before writing code:24- `node_modules/chat/docs/getting-started.mdx` — install and setup25- `node_modules/chat/docs/usage.mdx` — `Chat` config and lifecycle26- `node_modules/chat/docs/handling-events.mdx` — event routing and handlers27- `node_modules/chat/docs/threads-messages-channels.mdx` — thread/channel/message model28- `node_modules/chat/docs/posting-messages.mdx` — post, edit, delete, schedule29- `node_modules/chat/docs/streaming.mdx` — AI SDK integration and streaming semantics30- `node_modules/chat/docs/cards.mdx` — JSX cards31- `node_modules/chat/docs/actions.mdx` — button/select interactions32- `node_modules/chat/docs/modals.mdx` — modal submit/close flows33- `node_modules/chat/docs/slash-commands.mdx` — slash command routing34- `node_modules/chat/docs/direct-messages.mdx` — DM behavior and `openDM()`35- `node_modules/chat/docs/files.mdx` — attachments/uploads36- `node_modules/chat/docs/state.mdx` — persistence, locking, dedupe37- `node_modules/chat/docs/adapters.mdx` — cross-platform feature matrix38- `node_modules/chat/docs/api/chat.mdx` — exact `Chat` API39- `node_modules/chat/docs/api/thread.mdx` — exact `Thread` API40- `node_modules/chat/docs/api/message.mdx` — exact `Message` API41- `node_modules/chat/docs/api/modals.mdx` — modal element and event details4243For the specific adapter or state package you are using, inspect that installed package's `dist/index.d.ts` export surface in `node_modules`.4445## Quick start4647```typescript48import { Chat } from "chat";49import { createSlackAdapter } from "@chat-adapter/slack";50import { createRedisState } from "@chat-adapter/state-redis";5152const bot = new Chat({53 userName: "mybot",54 adapters: {55 slack: createSlackAdapter(),56 },57 state: createRedisState(),58 dedupeTtlMs: 600_000,59});6061bot.onNewMention(async (thread) => {62 await thread.subscribe();63 await thread.post("Hello! I'm listening to this thread.");64});6566bot.onSubscribedMessage(async (thread, message) => {67 await thread.post(`You said: ${message.text}`);68});69```7071## Core concepts7273- **Chat** — main entry point; coordinates adapters, routing, locks, and state74- **Adapters** — platform-specific integrations for Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, and WhatsApp75- **State adapters** — persistence for subscriptions, locks, dedupe, and thread state76- **Thread** — conversation context with `post()`, `stream()`, `subscribe()`, `setState()`, `startTyping()`77- **Message** — normalized content with `text`, `formatted`, attachments, author info, and platform `raw`78- **Channel** — container for threads and top-level posts7980## Event handlers8182| Handler | Trigger |83|---------|---------|84| `onNewMention` | Bot @-mentioned in an unsubscribed thread |85| `onDirectMessage` | New DM in an unsubscribed DM thread |86| `onSubscribedMessage` | Any message in a subscribed thread |87| `onNewMessage(regex)` | Regex match in an unsubscribed thread |88| `onReaction(emojis?)` | Emoji added or removed |89| `onAction(actionIds?)` | Button clicks and select/radio interactions |90| `onModalSubmit(callbackId?)` | Modal form submitted |91| `onModalClose(callbackId?)` | Modal dismissed/cancelled |92| `onSlashCommand(commands?)` | Slash command invocation |93| `onAssistantThreadStarted` | Slack assistant thread opened |94| `onAssistantContextChanged` | Slack assistant context changed |95| `onAppHomeOpened` | Slack App Home opened |96| `onMemberJoinedChannel` | Slack member joined channel event |9798Read `node_modules/chat/docs/handling-events.mdx`, `node_modules/chat/docs/actions.mdx`, `node_modules/chat/docs/modals.mdx`, and `node_modules/chat/docs/slash-commands.mdx` before wiring handlers. `onDirectMessage` behavior is documented in `node_modules/chat/docs/direct-messages.mdx`.99100## Streaming101102Pass any `AsyncIterable<string>` to `thread.post()` or `thread.stream()`. For AI SDK, prefer `result.fullStream` over `result.textStream` when available so step boundaries are preserved.103104```typescript105import { ToolLoopAgent } from "ai";106107const agent = new ToolLoopAgent({ model: "anthropic/claude-sonnet-4.6" });108109bot.onNewMention(async (thread, message) => {110 const result = await agent.stream({ prompt: message.text });111 await thread.post(result.fullStream);112});113```114115Key details:116- `streamingUpdateIntervalMs` controls post+edit fallback cadence117- `fallbackStreamingPlaceholderText` defaults to `"..."`; set `null` to disable118- Structured `StreamChunk` support is Slack-only; other adapters ignore non-text chunks119120## Cards and modals (JSX)121122Set `jsxImportSource: "chat"` in `tsconfig.json`.123124Card components:125- `Card`, `CardText`, `Section`, `Fields`, `Field`, `Button`, `CardLink`, `LinkButton`, `Actions`, `Select`, `SelectOption`, `RadioSelect`, `Table`, `Image`, `Divider`126127Modal components:128- `Modal`, `TextInput`, `Select`, `SelectOption`, `RadioSelect`129130```tsx131await thread.post(132 <Card title="Order #1234">133 <CardText>Your order has been received.</CardText>134 <Actions>135 <Button id="approve" style="primary">Approve</Button>136 <Button id="reject" style="danger">Reject</Button>137 </Actions>138 </Card>139);140```141142## Adapter inventory143144### Official platform adapters145146| Platform | Package | Factory |147|---------|---------|---------|148| Slack | `@chat-adapter/slack` | `createSlackAdapter` |149| Microsoft Teams | `@chat-adapter/teams` | `createTeamsAdapter` |150| Google Chat | `@chat-adapter/gchat` | `createGoogleChatAdapter` |151| Discord | `@chat-adapter/discord` | `createDiscordAdapter` |152| GitHub | `@chat-adapter/github` | `createGitHubAdapter` |153| Linear | `@chat-adapter/linear` | `createLinearAdapter` |154| Telegram | `@chat-adapter/telegram` | `createTelegramAdapter` |155| WhatsApp Business Cloud | `@chat-adapter/whatsapp` | `createWhatsAppAdapter` |156157### Official state adapters158159| State backend | Package | Factory |160|--------------|---------|---------|161| Redis | `@chat-adapter/state-redis` | `createRedisState` |162| ioredis | `@chat-adapter/state-ioredis` | `createIoRedisState` |163| PostgreSQL | `@chat-adapter/state-pg` | `createPostgresState` |164| Memory | `@chat-adapter/state-memory` | `createMemoryState` |165166### Community adapters167168- `chat-state-cloudflare-do`169- `@beeper/chat-adapter-matrix`170- `chat-adapter-imessage`171- `@bitbasti/chat-adapter-webex`172- `@resend/chat-sdk-adapter`173- `chat-adapter-baileys`174175### Coming-soon platform entries176177- Instagram178- Signal179- X180- Messenger181182## Building a custom adapter183184Read these published docs first:185- `node_modules/chat/docs/contributing/building.mdx`186- `node_modules/chat/docs/contributing/testing.mdx`187- `node_modules/chat/docs/contributing/publishing.mdx`188189Also inspect:190- `node_modules/chat/dist/index.d.ts` — `Adapter` and related interfaces191- `node_modules/@chat-adapter/shared/dist/index.d.ts` — shared errors and utilities192- Installed official adapter `dist/index.d.ts` files — reference implementations for config and APIs193194A custom adapter needs request verification, webhook parsing, message/thread/channel operations, ID encoding/decoding, and a format converter. Use `BaseFormatConverter` from `chat` and shared utilities from `@chat-adapter/shared`.195196## Webhook setup197198Each registered adapter exposes `bot.webhooks.<name>`. Wire those directly to your HTTP framework routes. See `node_modules/chat/docs/guides/slack-nextjs.mdx` and `node_modules/chat/docs/guides/discord-nuxt.mdx` for framework-specific route patterns.