Chat sdk

From openai/plugins · View interactive version

Chat sdk is an AI agent skill from the GitHub repository openai/plugins. Vercel Chat SDK expert guidance. Use when building multi-platform chat bots — Slack, Telegram, Microsoft Teams, Discord, Google Chat, GitHub, Linear — with a single codebase. Covers the Chat class, adapters, threads, messages, cards, modals, streaming, state management, and webhook setup.

How to use this skill

Skill file

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 docs
node_modules/chat/dist/index.d.ts          # core API types
node_modules/chat/dist/jsx-runtime.d.ts    # JSX runtime types
node_modules/chat/docs/contributing/       # adapter-authoring docs
node_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:

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

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

Event handlers

| Handler | Trigger |

|---------|---------|

| onNewMention | Bot @-mentioned in an unsubscribed thread |

| onDirectMessage | New DM in an unsubscribed DM thread |

| onSubscribedMessage | Any 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 |

| onAssistantThreadStarted | Slack assistant thread opened |

| onAssistantContextChanged | Slack assistant context changed |

| onAppHomeOpened | Slack App Home opened |

| onMemberJoinedChannel | Slack 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.

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:

Cards and modals (JSX)

Set jsxImportSource: "chat" in tsconfig.json.

Card components:

Modal components:

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

| Platform | Package | Factory |

|---------|---------|---------|

| Slack | @chat-adapter/slack | createSlackAdapter |

| Microsoft Teams | @chat-adapter/teams | createTeamsAdapter |

| Google Chat | @chat-adapter/gchat | createGoogleChatAdapter |

| Discord | @chat-adapter/discord | createDiscordAdapter |

| GitHub | @chat-adapter/github | createGitHubAdapter |

| Linear | @chat-adapter/linear | createLinearAdapter |

| Telegram | @chat-adapter/telegram | createTelegramAdapter |

| WhatsApp Business Cloud | @chat-adapter/whatsapp | createWhatsAppAdapter |

Official state adapters

| State backend | Package | Factory |

|--------------|---------|---------|

| Redis | @chat-adapter/state-redis | createRedisState |

| ioredis | @chat-adapter/state-ioredis | createIoRedisState |

| PostgreSQL | @chat-adapter/state-pg | createPostgresState |

| Memory | @chat-adapter/state-memory | createMemoryState |

Community adapters

Coming-soon platform entries

Building a custom adapter

Read these published docs first:

Also inspect:

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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.