Chat Sdk

vercel/vercel-plugin/skills/chat-sdk/upstream

作者 vercel882e66c2698689324c341b7bb8fd8beb92c27bf6无许可证301 个星标收录于 2026年10月9日更新于 2026年10月9日仓库今天更新

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.

AI 生成的概览

指导开发者使用 Chat SDK TypeScript 包构建多平台聊天机器人。

功能
该技能为使用 Chat SDK(chat npm 包)构建聊天机器人提供参考指导,这是一个统一的 TypeScript SDK,覆盖 Slack、Teams、Google Chat、Discord、Telegram、GitHub、Linear 和 WhatsApp。它说明 Chat、适配器、状态适配器、线程、消息和频道等核心概念,以及事件处理器、流式输出、JSX 卡片与模态框、webhook 设置和自定义适配器编写。它指向 node_modules 中随包发布的文档和类型定义文件,以获取准确的 API。
适用场景
当开发者想要为一个或多个聊天平台构建机器人,处理提及、私信、已订阅线程、表情回应、斜杠命令、卡片、模态框、文件或 AI 流式输出时使用。它也适用于设置 webhook 路由、多适配器机器人,或构建和维护自定义平台适配器或状态适配器。
运行要求
需要在项目中安装 Chat SDK 的 chat npm 包以及相应的平台适配器和状态适配器包,并需要 TypeScript。部分功能需要 Redis 或 PostgreSQL 等状态后端,平台机器人还需要各自的凭据和 webhook 路由。该技能不附带脚本,仅为说明文档。

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 docsnode_modules/chat/dist/index.d.ts          # core API typesnode_modules/chat/dist/jsx-runtime.d.ts    # JSX runtime typesnode_modules/chat/docs/contributing/       # adapter-authoring docsnode_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

typescript
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

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.

typescript
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
tsx
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.

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.

来源与署名

来源:vercel/vercel-plugin位于skills/chat-sdk/upstream提交882e66c

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架