用途:Chat SDK 是统一的 TypeScript SDK,用于构建跨 Slack、Teams、Google Chat、Discord、Telegram、GitHub、Linear、WhatsApp 的聊天机器人,实现“写一次逻辑,到处部署”。
主要能力:核心入口 Chat 负责协调适配器、路由、锁与状态;适配器提供各平台集成;状态适配器负责订阅、锁、去重与线程状态的持久化;Thread 提供 post()、stream()、subscribe()、setState()、startTyping();Message 提供规范化内容(text、formatted、attachments、作者信息、平台原始数据);Channel 是线程与顶层消息的容器。事件处理器包括 onNewMention、onDirectMessage、onSubscribedMessage、onNewMessage(regex)、onReaction、onAction、onModalSubmit、onModalClose、onSlashCommand 以及若干 Slack 专用事件。支持流式输出(向 thread.post() 或 thread.stream() 传入 AsyncIterable<string>,AI SDK 建议用 result.fullStream),支持 JSX 卡片与模态框(需在 tsconfig.json 设置 jsxImportSource: "chat")。
使用方式:安装后先阅读 node_modules/chat/docs/ 下的文档(getting-started、usage、handling-events、threads-messages-channels、posting-messages、streaming、cards、actions、modals、slash-commands、direct-messages、files、state、adapters 及 api/ 下的接口文档)。快速开始示例:import { Chat } from "chat"; import { createSlackAdapter } from "@chat-adapter/slack"; import { createRedisState } from "@chat-adapter/state-redis"; 然后 new Chat({ userName, adapters, state, dedupeTtlMs }),用 bot.onNewMention 等注册处理器。各适配器暴露 bot.webhooks.<name>,可直接接入 HTTP 框架路由(参考 guides/slack-nextjs.mdx、guides/discord-nuxt.mdx)。
适用场景:需要同时覆盖多个聊天平台的机器人、AI 助手、通知与交互式卡片/表单流程。
限制:结构化 StreamChunk 仅 Slack 支持,其他适配器忽略非文本块;自定义适配器需实现请求校验、webhook 解析、消息/线程/频道操作、ID 编解码与格式转换。具体收费、价格与平台支持细节资料未提供。