Skip to content

Commit 7a0abc5

Browse files
committed
Migrate Discord review approvals to Chat SDK with Redis-backed state.
This replaces custom Discord polling with interactive approval actions, adds webhook handling, and aligns env configuration for Upstash Redis and Discord app credentials.
1 parent 2e05073 commit 7a0abc5

12 files changed

Lines changed: 671 additions & 360 deletions

File tree

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

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
name: chat-sdk
3+
description: >
4+
Build multi-platform chat bots with Chat SDK (`chat` npm package). Use when developers want to
5+
(1) Build a Slack, Teams, Google Chat, Discord, GitHub, or Linear bot,
6+
(2) Use the Chat SDK to handle mentions, messages, reactions, slash commands, cards, modals, or streaming,
7+
(3) Set up webhook handlers for chat platforms,
8+
(4) Send interactive cards or stream AI responses to chat platforms.
9+
Triggers on "chat sdk", "chat bot", "slack bot", "teams bot", "discord bot", "@chat-adapter",
10+
building bots that work across multiple chat platforms.
11+
---
12+
13+
# Chat SDK
14+
15+
Unified TypeScript SDK for building chat bots across Slack, Teams, Google Chat, Discord, GitHub, and Linear. Write bot logic once, deploy everywhere.
16+
17+
## Critical: Read the bundled docs
18+
19+
The `chat` package ships with full documentation in `node_modules/chat/docs/` and TypeScript source types. **Always read these before writing code:**
20+
21+
```
22+
node_modules/chat/docs/ # Full documentation (MDX files)
23+
node_modules/chat/dist/ # Built types (.d.ts files)
24+
```
25+
26+
Key docs to read based on task:
27+
- `docs/getting-started.mdx` — setup guides
28+
- `docs/usage.mdx` — event handlers, threads, messages, channels
29+
- `docs/streaming.mdx` — AI streaming with AI SDK
30+
- `docs/cards.mdx` — JSX interactive cards
31+
- `docs/actions.mdx` — button/dropdown handlers
32+
- `docs/modals.mdx` — form dialogs (Slack only)
33+
- `docs/adapters/*.mdx` — platform-specific adapter setup
34+
- `docs/state/*.mdx` — state adapter config (Redis, ioredis, memory)
35+
36+
Also read the TypeScript types from `node_modules/chat/dist/` to understand the full API surface.
37+
38+
## Quick start
39+
40+
```typescript
41+
import { Chat } from "chat";
42+
import { createSlackAdapter } from "@chat-adapter/slack";
43+
import { createRedisState } from "@chat-adapter/state-redis";
44+
45+
const bot = new Chat({
46+
userName: "mybot",
47+
adapters: {
48+
slack: createSlackAdapter({
49+
botToken: process.env.SLACK_BOT_TOKEN!,
50+
signingSecret: process.env.SLACK_SIGNING_SECRET!,
51+
}),
52+
},
53+
state: createRedisState({ url: process.env.REDIS_URL! }),
54+
});
55+
56+
bot.onNewMention(async (thread) => {
57+
await thread.subscribe();
58+
await thread.post("Hello! I'm listening to this thread.");
59+
});
60+
61+
bot.onSubscribedMessage(async (thread, message) => {
62+
await thread.post(`You said: ${message.text}`);
63+
});
64+
```
65+
66+
## Core concepts
67+
68+
- **Chat** — main entry point, coordinates adapters and routes events
69+
- **Adapters** — platform-specific (Slack, Teams, GChat, Discord, GitHub, Linear)
70+
- **State** — pluggable persistence (Redis for prod, memory for dev)
71+
- **Thread** — conversation thread with `post()`, `subscribe()`, `startTyping()`
72+
- **Message** — normalized format with `text`, `formatted` (mdast AST), `raw`
73+
- **Channel** — container for threads, supports listing and posting
74+
75+
## Event handlers
76+
77+
| Handler | Trigger |
78+
|---------|---------|
79+
| `onNewMention` | Bot @-mentioned in unsubscribed thread |
80+
| `onSubscribedMessage` | Any message in subscribed thread |
81+
| `onNewMessage(regex)` | Messages matching pattern in unsubscribed threads |
82+
| `onSlashCommand("/cmd")` | Slash command invocations |
83+
| `onReaction(emojis)` | Emoji reactions added/removed |
84+
| `onAction(actionId)` | Button clicks and dropdown selections |
85+
| `onAssistantThreadStarted` | Slack Assistants API thread opened |
86+
| `onAppHomeOpened` | Slack App Home tab opened |
87+
88+
## Streaming
89+
90+
Pass any `AsyncIterable<string>` to `thread.post()`. Works with AI SDK's `textStream`:
91+
92+
```typescript
93+
import { ToolLoopAgent } from "ai";
94+
const agent = new ToolLoopAgent({ model: "anthropic/claude-4.5-sonnet" });
95+
96+
bot.onNewMention(async (thread, message) => {
97+
const result = await agent.stream({ prompt: message.text });
98+
await thread.post(result.textStream);
99+
});
100+
```
101+
102+
## Cards (JSX)
103+
104+
Set `jsxImportSource: "chat"` in tsconfig. Components: `Card`, `CardText`, `Button`, `Actions`, `Fields`, `Field`, `Select`, `SelectOption`, `Image`, `Divider`, `LinkButton`, `Section`, `RadioSelect`.
105+
106+
```tsx
107+
await thread.post(
108+
<Card title="Order #1234">
109+
<CardText>Your order has been received!</CardText>
110+
<Actions>
111+
<Button id="approve" style="primary">Approve</Button>
112+
<Button id="reject" style="danger">Reject</Button>
113+
</Actions>
114+
</Card>
115+
);
116+
```
117+
118+
## Packages
119+
120+
| Package | Purpose |
121+
|---------|---------|
122+
| `chat` | Core SDK |
123+
| `@chat-adapter/slack` | Slack |
124+
| `@chat-adapter/teams` | Microsoft Teams |
125+
| `@chat-adapter/gchat` | Google Chat |
126+
| `@chat-adapter/discord` | Discord |
127+
| `@chat-adapter/github` | GitHub Issues |
128+
| `@chat-adapter/linear` | Linear Issues |
129+
| `@chat-adapter/state-redis` | Redis state (production) |
130+
| `@chat-adapter/state-ioredis` | ioredis state (alternative) |
131+
| `@chat-adapter/state-memory` | In-memory state (development) |
132+
133+
## Changesets (Release Flow)
134+
135+
This monorepo uses [Changesets](https://github.com/changesets/changesets) for versioning and changelogs. Every PR that changes a package's behavior must include a changeset.
136+
137+
```bash
138+
pnpm changeset
139+
# → select affected package(s) (e.g. @chat-adapter/slack, chat)
140+
# → choose bump type: patch (fixes), minor (features), major (breaking)
141+
# → write a short summary for the CHANGELOG
142+
```
143+
144+
This creates a file in `.changeset/` — commit it with the PR. When merged to `main`, the Changesets GitHub Action opens a "Version Packages" PR to bump versions and update CHANGELOGs. Merging that PR publishes to npm.
145+
146+
## Webhook setup
147+
148+
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).

0 commit comments

Comments
 (0)