Labsco
vercel-labs logo

chat-sdk

β˜… 5,700

by vercel Β· part of vercel-labs/open-agents

Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, and WhatsApp. Write bot logic once, deploy everywhere.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeQuick setup
🧩 One of 7 skills in the vercel-labs/open-agents package β€” works on its own, and pairs well with its siblings.

Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, and WhatsApp. Write bot logic once, deploy everywhere.

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates β€” shown here so you can audit it before installing. You don't need to read it to use the skill.


name: chat-sdk description: > Build multi-platform chat bots with Chat SDK (chat npm package). Use when developers want to (1) Build a Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, or WhatsApp bot, (2) Use Chat SDK to handle mentions, direct messages, subscribed threads, reactions, slash commands, cards, modals, files, or AI streaming, (3) Set up webhook routes or multi-adapter bots, (4) Send rich cards or streamed AI responses to chat platforms, (5) Build or maintain a custom adapter or state adapter. Triggers on "chat sdk", "chat bot", "slack bot", "teams bot", "google chat bot", "discord bot", "telegram bot", "whatsapp bot", "@chat-adapter", "@chat-adapter/state-", "custom adapter", "state adapter", "build adapter", and building bots that work across multiple chat platforms.

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:

Copy & paste β€” that's it
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.

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

HandlerTrigger
onNewMentionBot @-mentioned in an unsubscribed thread
onDirectMessageNew DM in an unsubscribed DM thread
onSubscribedMessageAny 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
onAssistantThreadStartedSlack assistant thread opened
onAssistantContextChangedSlack assistant context changed
onAppHomeOpenedSlack App Home opened
onMemberJoinedChannelSlack 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.

Copy & paste β€” that's it
import { ToolLoopAgent } from "ai";

const agent = new ToolLoopAgent({ model: "anthropic/claude-4.5-sonnet" });

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
Copy & paste β€” that's it
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

PlatformPackageFactory
Slack@chat-adapter/slackcreateSlackAdapter
Microsoft Teams@chat-adapter/teamscreateTeamsAdapter
Google Chat@chat-adapter/gchatcreateGoogleChatAdapter
Discord@chat-adapter/discordcreateDiscordAdapter
GitHub@chat-adapter/githubcreateGitHubAdapter
Linear@chat-adapter/linearcreateLinearAdapter
Telegram@chat-adapter/telegramcreateTelegramAdapter
WhatsApp Business Cloud@chat-adapter/whatsappcreateWhatsAppAdapter

Official state adapters

State backendPackageFactory
Redis@chat-adapter/state-rediscreateRedisState
ioredis@chat-adapter/state-iorediscreateIoRedisState
PostgreSQL@chat-adapter/state-pgcreatePostgresState
Memory@chat-adapter/state-memorycreateMemoryState

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.