Agent Skills › lobehub/lobehub › chat-sdk

chat-sdk

GitHub

提供跨平台聊天机器人构建SDK,支持Slack、Teams等多平台适配。用于实现Webhook、命令处理、卡片交互及流式响应等核心功能,帮助开发者编写一次逻辑即可部署至多端。

.agents/skills/chat-sdk/SKILL.md lobehub/lobehub

Trigger Scenarios

需要构建跨平台聊天机器人 集成Slack或Teams等消息平台 实现聊天机器人事件处理与交互

Install

npx skills add lobehub/lobehub --skill chat-sdk -g -y
More Options

Non-standard path

npx skills add https://github.com/lobehub/lobehub/tree/canary/.agents/skills/chat-sdk -g -y

Use without installing

npx skills use lobehub/lobehub@chat-sdk

指定 Agent (Claude Code)

npx skills add lobehub/lobehub --skill chat-sdk -a claude-code -g -y

安装 repo 全部 skill

npx skills add lobehub/lobehub --all -g -y

预览 repo 内 skill

npx skills add lobehub/lobehub --list

SKILL.md

Frontmatter
{
    "name": "chat-sdk",
    "description": "Use for multi-platform bots built with chat SDK: webhooks, mentions, slash commands, cards, modals and streaming.",
    "user-invocable": false
}

Chat SDK

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

Critical: Read the bundled docs

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 guides
  • docs/usage.mdx — event handlers, threads, messages, channels
  • docs/streaming.mdx — AI streaming with AI SDK
  • docs/cards.mdx — JSX interactive cards
  • docs/actions.mdx — button/dropdown handlers
  • docs/modals.mdx — form dialogs (Slack only)
  • docs/adapters.mdx, docs/platform-adapters.mdx — adapter overview and platform-specific setup
  • docs/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.

Quick start

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}`);
});

Core concepts

  • Chat — main entry point, coordinates adapters and routes events
  • Adapters — platform-specific (Slack, Teams, GChat, Discord, GitHub, Linear)
  • State — pluggable persistence (Redis for prod, memory for dev)
  • Thread — conversation thread with post(), subscribe(), startTyping()
  • Message — normalized format with text, formatted (mdast AST), raw
  • Channel — container for threads, supports listing and posting

Event handlers

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

Streaming

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);
});

Cards (JSX)

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>,
);

Packages

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

Webhook setup

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).

Version History

  • 69012b8 Current 2026-09-28 20:12
  • e0d4b61 2026-09-23 09:51
  • 29fe043 2026-08-20 18:33

Same Skill Collection

.agents/skills/add-model-provider/SKILL.md
.agents/skills/add-provider-doc/SKILL.md
.agents/skills/add-setting-env/SKILL.md
.agents/skills/agent-runtime-hooks/SKILL.md
.agents/skills/agent-signal/SKILL.md
.agents/skills/agent-testing-bot/SKILL.md
.agents/skills/agent-tracing/SKILL.md
.agents/skills/agent-work/SKILL.md
.agents/skills/alint-ruleset/SKILL.md
.agents/skills/builtin-tool/SKILL.md
.agents/skills/cleanup-git-worktrees/SKILL.md
.agents/skills/cli/SKILL.md
.agents/skills/compose-atoms/SKILL.md
.agents/skills/data-fetching-architecture/SKILL.md
.agents/skills/db-migrations/SKILL.md
.agents/skills/debug-frontend-with-browser/SKILL.md
.agents/skills/debug-package/SKILL.md
.agents/skills/deep-review/SKILL.md
.agents/skills/design-prototype/SKILL.md
.agents/skills/desktop-security-update/SKILL.md
.agents/skills/desktop/SKILL.md
.agents/skills/docs-changelog/SKILL.md
.agents/skills/drizzle/SKILL.md
.agents/skills/full-text-search/SKILL.md
.agents/skills/heterogeneous-agent/SKILL.md
.agents/skills/hotkey/SKILL.md
.agents/skills/i18n/SKILL.md
.agents/skills/linear/SKILL.md
.agents/skills/llm-generation/SKILL.md
.agents/skills/modal/SKILL.md
.agents/skills/model-bank-metadata/SKILL.md
.agents/skills/product-design/SKILL.md
.agents/skills/project-overview/SKILL.md
.agents/skills/react/SKILL.md
.agents/skills/response-compliance/SKILL.md
.agents/skills/run-eval-harbor/SKILL.md
.agents/skills/skills-audit/SKILL.md
.agents/skills/source-layout/SKILL.md
.agents/skills/spa-routes/SKILL.md
.agents/skills/split-large-file/SKILL.md
.agents/skills/split-micro-app/SKILL.md
.agents/skills/store-data-structures/SKILL.md
.agents/skills/testing-heterogeneous-agents/SKILL.md
.agents/skills/testing/SKILL.md
.agents/skills/trpc-router/SKILL.md
.agents/skills/typescript/SKILL.md
.agents/skills/upstash-workflow/SKILL.md
.agents/skills/ux-audit/SKILL.md
.agents/skills/ux/SKILL.md

Metadata

Files
0
Version
aace12f
Hash
cf7eef6f
Indexed
2026-08-20 18:33

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-24 22:48
浙ICP备14020137号-1