Use for multi-platform bots built with chat SDK: webhooks, mentions, slash commands, cards, modals and streaming.
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-chat-sdk-fa60f9233bb2 ,按照其中的说明把「chat-sdk」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, GitHub, and Linear. Write bot logic once, deploy everywhere.
The chat package ships with full documentation in node_modules/chat/docs/ and TypeScript source types. Always read these before writing code:
node_modules/chat/docs/ # Full documentation (MDX files)
node_modules/chat/dist/ # Built types (.d.ts files)
Key docs to read based on task:
docs/getting-started.mdx — setup guidesdocs/usage.mdx — event handlers, threads, messages, channelsdocs/streaming.mdx — AI streaming with AI SDKdocs/cards.mdx — JSX interactive cardsdocs/actions.mdx — button/dropdown handlersdocs/modals.mdx — form dialogs (Slack only)docs/adapters.mdx, docs/platform-adapters.mdx — adapter overview and platform-specific setupdocs/state-adapters.mdx — state adapter config (Redis, ioredis, memory)Also read the TypeScript types from node_modules/chat/dist/ to understand the full API surface.
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({
botToken: process.env.SLACK_BOT_TOKEN!,
signingSecret: process.env.SLACK_SIGNING_SECRET!,
}),
},
state: createRedisState({ url: process.env.REDIS_URL! }),
});
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(), subscribe(), startTyping()text, formatted (mdast AST), raw| Handler | Trigger |
|---|---|
onNewMention | Bot @-mentioned in unsubscribed thread |
onSubscribedMessage | Any message in subscribed thread |
onNewMessage(regex) | Messages matching pattern in unsubscribed threads |
onSlashCommand("/cmd") | Slash command invocations |
onReaction(emojis) | Emoji reactions added/removed |
onAction(actionId) | Button clicks and dropdown selections |
onAssistantThreadStarted | Slack Assistants API thread opened |
onAppHomeOpened | Slack App Home tab opened |
Pass any AsyncIterable<string> to thread.post(). Works with AI SDK's textStream:
import { ToolLoopAgent } from 'ai';
const agent = new ToolLoopAgent({ model: 'anthropic/claude-sonnet-5' });
bot.onNewMention(async (thread, message) => {
const result = await agent.stream({ prompt: message.text });
await thread.post(result.textStream);
});
Set jsxImportSource: "chat" in tsconfig. Components: Card, CardText, Button, Actions, Fields, Field, Select, SelectOption, Image, Divider, LinkButton, Section, 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>,
);
chat and the @chat-adapter/* packages are an external SDK this repo
consumes (pinned via semver range in package.json), not something built or
versioned here — there's no Changesets/release flow to document for them.
| Package | Purpose |
|---|---|
chat | Core SDK |
@chat-adapter/discord | Discord |
@chat-adapter/slack | Slack |
@chat-adapter/telegram | Telegram |
@chat-adapter/state-ioredis | ioredis state |
@lobechat/chat-adapter-feishu | Lark/Feishu — built in-repo (packages/chat-adapter-feishu), not from @chat-adapter/ |
@lobechat/chat-adapter-imessage | iMessage via BlueBubbles — built in-repo |
@lobechat/chat-adapter-line | LINE Messaging API — built in-repo |
@lobechat/chat-adapter-qq | QQ Bot — built in-repo |
@lobechat/chat-adapter-wechat | WeChat (iLink) — built in-repo |
Each adapter exposes a webhook handler via bot.webhooks.{platform}. Wire these to your HTTP framework's routes (e.g. Next.js API routes, Hono, Express).