chat-sdk by vercel/chat
npx skills add https://github.com/vercel/chat --skill chat-sdk用于构建跨 Slack、Teams、Google Chat、Discord、Telegram、GitHub、Linear 和 WhatsApp 聊天机器人的统一 TypeScript SDK。一次编写机器人逻辑,随处部署。
当 Chat SDK 安装在用户项目中时,检查 node_modules 中附带的已发布文件:
node_modules/chat/docs/ # 捆绑的文档
node_modules/chat/dist/index.d.ts # 核心 API 类型
node_modules/chat/dist/jsx-runtime.d.ts # JSX 运行时类型
node_modules/chat/docs/contributing/ # 适配器编写文档
node_modules/chat/docs/guides/ # 框架/平台指南
如果以下某个路径不存在,则表示该包尚未安装在项目中。
在编写代码之前,请阅读以下内容:
node_modules/chat/docs/getting-started.mdx — 安装与设置node_modules/chat/docs/usage.mdx — Chat 配置与生命周期node_modules/chat/docs/handling-events.mdx — 事件路由与处理器广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
node_modules/chat/docs/threads-messages-channels.mdx — 线程/频道/消息模型node_modules/chat/docs/posting-messages.mdx — 发布、编辑、删除、定时发送node_modules/chat/docs/streaming.mdx — AI SDK 集成与流式语义node_modules/chat/docs/cards.mdx — JSX 卡片node_modules/chat/docs/actions.mdx — 按钮/选择器交互node_modules/chat/docs/modals.mdx — 模态框提交/关闭流程node_modules/chat/docs/slash-commands.mdx — 斜杠命令路由node_modules/chat/docs/direct-messages.mdx — 私信行为与 openDM()node_modules/chat/docs/files.mdx — 附件/上传node_modules/chat/docs/state.mdx — 持久化、锁定、去重node_modules/chat/docs/adapters.mdx — 跨平台功能矩阵node_modules/chat/docs/api/chat.mdx — 精确的 Chat APInode_modules/chat/docs/api/thread.mdx — 精确的 Thread APInode_modules/chat/docs/api/message.mdx — 精确的 Message APInode_modules/chat/docs/api/modals.mdx — 模态框元素和事件详情对于你正在使用的特定适配器或状态包,请在 node_modules 中检查该已安装包的 dist/index.d.ts 导出接口。
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}`);
});
post()、stream()、subscribe()、setState()、startTyping() 的对话上下文text、formatted、附件、作者信息和平台原始数据 raw| 处理器 | 触发条件 |
|---|---|
onNewMention | 机器人在未订阅的线程中被 @ 提及 |
onDirectMessage | 在未订阅的私信线程中收到新私信 |
onSubscribedMessage | 已订阅线程中的任何消息 |
onNewMessage(regex) | 未订阅线程中的消息匹配正则表达式 |
onReaction(emojis?) | 表情符号被添加或移除 |
onAction(actionIds?) | 按钮点击和选择器/单选交互 |
onModalSubmit(callbackId?) | 模态框表单提交 |
onModalClose(callbackId?) | 模态框被关闭/取消 |
onSlashCommand(commands?) | 斜杠命令调用 |
onAssistantThreadStarted | Slack 助手线程开启 |
onAssistantContextChanged | Slack 助手上下文变更 |
onAppHomeOpened | Slack 应用主页被打开 |
onMemberJoinedChannel | Slack 成员加入频道事件 |
在连接处理器之前,请阅读 node_modules/chat/docs/handling-events.mdx、node_modules/chat/docs/actions.mdx、node_modules/chat/docs/modals.mdx 和 node_modules/chat/docs/slash-commands.mdx。onDirectMessage 行为记录在 node_modules/chat/docs/direct-messages.mdx 中。
将任何 AsyncIterable<string> 传递给 thread.post() 或 thread.stream()。对于 AI SDK,如果可用,优先使用 result.fullStream 而非 result.textStream,以保留步骤边界。
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);
});
关键细节:
streamingUpdateIntervalMs 控制发布+编辑回退节奏fallbackStreamingPlaceholderText 默认为 "...";设置为 null 以禁用StreamChunk 支持仅限 Slack;其他适配器会忽略非文本块在 tsconfig.json 中设置 jsxImportSource: "chat"。
卡片组件:
Card, CardText, Section, Fields, Field, Button, CardLink, LinkButton, Actions, Select, SelectOption, RadioSelect, Table, Image, Divider模态框组件:
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> );
| 平台 | 包 | 工厂函数 |
|---|---|---|
| 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 |
| 状态后端 | 包 | 工厂函数 |
|---|---|---|
| Redis | @chat-adapter/state-redis | createRedisState |
| ioredis | @chat-adapter/state-ioredis | createIoRedisState |
| PostgreSQL | @chat-adapter/state-pg | createPostgresState |
| Memory | @chat-adapter/state-memory | createMemoryState |
chat-state-cloudflare-do@beeper/chat-adapter-matrixchat-adapter-imessage@bitbasti/chat-adapter-webex@resend/chat-sdk-adapterchat-adapter-baileys首先阅读这些已发布的文档:
node_modules/chat/docs/contributing/building.mdxnode_modules/chat/docs/contributing/testing.mdxnode_modules/chat/docs/contributing/publishing.mdx同时检查:
node_modules/chat/dist/index.d.ts — Adapter 及相关接口node_modules/@chat-adapter/shared/dist/index.d.ts — 共享错误和工具函数dist/index.d.ts 文件 — 配置和 API 的参考实现自定义适配器需要请求验证、webhook 解析、消息/线程/频道操作、ID 编码/解码以及格式转换器。使用来自 chat 的 BaseFormatConverter 和来自 @chat-adapter/shared 的共享工具函数。
每个注册的适配器都会暴露 bot.webhooks.<name>。将这些直接连接到你的 HTTP 框架路由。有关特定框架的路由模式,请参阅 node_modules/chat/docs/guides/slack-nextjs.mdx 和 node_modules/chat/docs/guides/discord-nuxt.mdx。
每周安装量
925
代码仓库
GitHub 星标数
1.5K
首次出现
2026年2月24日
安全审计
安装于
codex910
opencode909
gemini-cli906
cursor906
github-copilot906
amp906
Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, Telegram, GitHub, Linear, and WhatsApp. Write bot logic once, deploy everywhere.
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 setupnode_modules/chat/docs/usage.mdx — Chat config and lifecyclenode_modules/chat/docs/handling-events.mdx — event routing and handlersnode_modules/chat/docs/threads-messages-channels.mdx — thread/channel/message modelnode_modules/chat/docs/posting-messages.mdx — post, edit, delete, schedulenode_modules/chat/docs/streaming.mdx — AI SDK integration and streaming semanticsnode_modules/chat/docs/cards.mdx — JSX cardsnode_modules/chat/docs/actions.mdx — button/select interactionsnode_modules/chat/docs/modals.mdx — modal submit/close flowsnode_modules/chat/docs/slash-commands.mdx — slash command routingnode_modules/chat/docs/direct-messages.mdx — DM behavior and openDM()node_modules/chat/docs/files.mdx — attachments/uploadsnode_modules/chat/docs/state.mdx — persistence, locking, dedupenode_modules/chat/docs/adapters.mdx — cross-platform feature matrixnode_modules/chat/docs/api/chat.mdx — exact Chat APInode_modules/chat/docs/api/thread.mdx — exact Thread APInode_modules/chat/docs/api/message.mdx — exact Message APInode_modules/chat/docs/api/modals.mdx — modal element and event detailsFor the specific adapter or state package you are using, inspect that installed package's dist/index.d.ts export surface in node_modules.
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}`);
});
post(), stream(), subscribe(), setState(), startTyping()text, formatted, attachments, author info, and platform raw| 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?) |
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.
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-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 cadencefallbackStreamingPlaceholderText defaults to "..."; set null to disableStreamChunk support is Slack-only; other adapters ignore non-text chunksSet jsxImportSource: "chat" in tsconfig.json.
Card components:
Card, CardText, Section, Fields, Field, Button, CardLink, LinkButton, Actions, Select, SelectOption, RadioSelect, , , 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> );
| Platform | Package | Factory |
|---|---|---|
| Slack | @chat-adapter/slack | createSlackAdapter |
| Microsoft Teams | @chat-adapter/teams | createTeamsAdapter |
| Google Chat | @chat-adapter/gchat | createGoogleChatAdapter |
| Discord |
| State backend | Package | Factory |
|---|---|---|
| Redis | @chat-adapter/state-redis | createRedisState |
| ioredis | @chat-adapter/state-ioredis | createIoRedisState |
| PostgreSQL | @chat-adapter/state-pg | createPostgresState |
| Memory |
chat-state-cloudflare-do@beeper/chat-adapter-matrixchat-adapter-imessage@bitbasti/chat-adapter-webex@resend/chat-sdk-adapterchat-adapter-baileysRead these published docs first:
node_modules/chat/docs/contributing/building.mdxnode_modules/chat/docs/contributing/testing.mdxnode_modules/chat/docs/contributing/publishing.mdxAlso inspect:
node_modules/chat/dist/index.d.ts — Adapter and related interfacesnode_modules/@chat-adapter/shared/dist/index.d.ts — shared errors and utilitiesdist/index.d.ts files — reference implementations for config and APIsA 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.
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.
Weekly Installs
925
Repository
GitHub Stars
1.5K
First Seen
Feb 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex910
opencode909
gemini-cli906
cursor906
github-copilot906
amp906
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
Gemini Interactions API 指南:统一接口、智能体交互与服务器端状态管理
833 周安装
Apollo MCP 服务器:让AI代理通过GraphQL API交互的完整指南
834 周安装
智能体记忆系统构建指南:分块策略、向量存储与检索优化
835 周安装
Scrapling官方网络爬虫框架 - 自适应解析、绕过Cloudflare、Python爬虫库
836 周安装
抽奖赢家选取器 - 随机选择工具,支持CSV、Excel、Google Sheets,公平透明
838 周安装
Medusa 前端开发指南:使用 SDK、React Query 构建电商商店
839 周安装
| 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 |
TableImageDivider@chat-adapter/discordcreateDiscordAdapter |
| GitHub | @chat-adapter/github | createGitHubAdapter |
| Linear | @chat-adapter/linear | createLinearAdapter |
| Telegram | @chat-adapter/telegram | createTelegramAdapter |
| WhatsApp Business Cloud | @chat-adapter/whatsapp | createWhatsAppAdapter |
@chat-adapter/state-memorycreateMemoryState |