惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MyScale Blog
MyScale Blog
U
Unit 42
M
MIT News - Artificial intelligence
小众软件
小众软件
P
Proofpoint News Feed
雷峰网
雷峰网
L
LangChain Blog
S
SegmentFault 最新的问题
腾讯CDC
F
Fortinet All Blogs
A
About on SuperTechFans
WordPress大学
WordPress大学
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
Recent Announcements
Recent Announcements
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog

Chat SDK Documentation

History | Chat SDK History | Chat SDK List a vendor-official adapter | Chat SDK Approvals | Chat SDK Vercel Connect | Chat SDK Teams Low-Level APIs | Chat SDK CLI | Chat SDK Platform Adapters | Chat SDK State Adapters | Chat SDK Cards | Chat SDK Getting Started | Chat SDK Introduction | Chat SDK Modals | Chat SDK Slack Low-Level APIs | Chat SDK Streaming | Chat SDK Testing | Chat SDK Overview | Chat SDK toAiMessages | Chat SDK Cards | Chat SDK Overview | Chat SDK Markdown | Chat SDK Modals | Chat SDK AI SDK Tools | Chat SDK Types | Chat SDK Message Subject | Chat SDK Conversation History | Chat SDK Transcripts | Chat SDK Slack bot with Next.js and Redis Actions | Chat SDK Direct Messages | Chat SDK
Creating a Chat Instance | Chat SDK
Vercel · 2026-04-06 · via Chat SDK Documentation

Initialize the Chat class with adapters, state, and configuration options.

The Chat class is the main entry point for your bot. It coordinates adapters, routes events to your handlers, and manages thread state.

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

bot.onNewMention(async (thread) => {
  await thread.subscribe();
  await thread.post("Hello! I'm listening to this thread.");
});

Each adapter factory auto-detects credentials from environment variables (SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET, REDIS_URL, etc.), so you can get started with zero config. Pass explicit values to override.

Register multiple adapters to deploy your bot across platforms simultaneously:

import { Chat } from "chat";
import { createSlackAdapter } from "@chat-adapter/slack";
import { createTeamsAdapter } from "@chat-adapter/teams";
import { createDiscordAdapter } from "@chat-adapter/discord";
import { createRedisState } from "@chat-adapter/state-redis";

const bot = new Chat({
  userName: "mybot",
  adapters: {
    slack: createSlackAdapter(),
    teams: createTeamsAdapter(),
    discord: createDiscordAdapter(),
  },
  state: createRedisState(),
});

Your event handlers work identically across all registered adapters — the SDK normalizes messages, threads, and reactions into a consistent format.

OptionTypeDefaultDescription
userNamestringrequiredDefault bot username across all adapters
adaptersRecord<string, Adapter>requiredMap of adapter name to adapter instance
stateStateAdapterrequiredState adapter for subscriptions and locking
loggerLogger | LogLevel"info"Logger instance or log level ("debug", "info", "warn", "error", "silent")
dedupeTtlMsnumber300000TTL in ms for message deduplication (5 minutes)
concurrency"drop" | "queue" | "debounce" | "burst" | "concurrent" | ConcurrencyConfig"drop"Strategy for overlapping messages on the same thread
streamingUpdateIntervalMsnumber500Update interval in ms for post+edit streaming
fallbackStreamingPlaceholderTextstring | null"..."Placeholder text while streaming starts. Set to null to skip
onLockConflict'drop' | 'force' | (threadId, message) => 'drop' | 'force'"drop"Behavior when a thread lock is already held. 'force' releases the existing lock and re-acquires it, enabling interrupt/steerability for long-running handlers

Use getAdapter to access platform-specific APIs when you need functionality beyond the unified interface:

import type { SlackAdapter } from "@chat-adapter/slack";

const slack = bot.getAdapter("slack") as SlackAdapter;
await slack.setSuggestedPrompts(channelId, threadTs, [
  { title: "Get started", message: "What can you help me with?" },
]);

For typed access to the platform's native API client, use the SDK-named getter on each adapter:

const slack = bot.getAdapter("slack").webClient; // WebClient
const linear = bot.getAdapter("linear").linearClient; // LinearClient
const github = bot.getAdapter("github").octokit; // Octokit

The previous .client getter still works as a deprecated alias on all three adapters.

See getAdapter for multi-tenant constraints.

The webhooks property provides type-safe handlers for each registered adapter. Wire these up to your HTTP framework's routes:

import { bot } from "@/lib/bot";

export const POST = bot.webhooks.slack;
import { bot } from "@/lib/bot";

export const POST = bot.webhooks.teams;

The Chat instance initializes lazily on the first webhook. You can also initialize manually:

For graceful shutdown (e.g. in serverless teardown), call shutdown:

Register a singleton when you need to access the Chat instance from multiple files:

const bot = new Chat({ /* ...config */ }).registerSingleton();
export default bot;
import { Chat } from "chat";

const bot = Chat.getSingleton();

Open a DM thread with a user by passing their platform user ID or an Author object:

const dm = await bot.openDM("U123ABC");
await dm.post("Hey! Just wanted to follow up on your request.");

Get a channel directly by its ID:

const channel = bot.channel("slack:C123ABC");
await channel.post("Announcement: deploy complete!");