Liveblocks
Chat SDK adapter backed by Liveblocks Comments. Maps Liveblocks rooms, threads, and comments to the Chat SDK channel, thread, and message model.
Create a new bot
Scaffold a Next.js bot with the Liveblocks adapter using create-chat-sdk:
pnpm create chat-sdk@latest my-bot --adapter liveblocks memory -yThe generated app uses the Memory state adapter for local development. To add the adapter to an existing app, start at Install.
Install
pnpm add @liveblocks/chat-sdk-adapterQuick start
The adapter maps Liveblocks rooms to Chat SDK channels, comment threads to Chat SDK threads, and individual comments to messages, so subscriptions, handlers, posts, and reactions work as they do with any other adapter.
Platform setup
- Create a Liveblocks project with rooms using Comments.
- In the dashboard, copy a secret key (
sk_...) for server-side REST API calls. - Create a webhook signing secret (
whsec_...) and configure webhooks to subscribe to:commentCreatedcommentReactionAddedcommentReactionRemoved
- Choose a stable
botUserIdthat matches how your app identifies users. It can be a real user ID in your system or a dedicated bot ID you issue.
Point your Liveblocks webhook URL at the route that forwards requests to bot.webhooks.liveblocks (see Webhooks).
Configuration
| Prop | Type | Default | Description |
|---|---|---|---|
apiKey? | string | Liveblocks secret key (`sk_...`) for REST API calls. | |
webhookSecret? | string | Webhook signing secret (`whsec_...`) from the Liveblocks dashboard. | |
botUserId? | string | User ID used when the bot creates, edits, or reacts to comments. Must match your app's user identifiers. | |
botUserName? | string | "liveblocks-bot" | Display name for the bot. |
resolveUsers? | (args: { userIds: string[] }) => Promise<UserInfo[]> | Resolves user IDs for @mentions. Return one entry per input id in order, or `undefined` to skip. | |
resolveGroupsInfo? | (args: { groupIds: string[] }) => Promise<GroupInfo[]> | Resolves group IDs for @mentions. Same ordering rules as `resolveUsers`. | |
logger? | Logger | ConsoleLogger("info") | Chat SDK-compatible logger. |
Resolver return types follow the @liveblocks/core user and group metadata shapes (U["info"], DGI).
Webhooks
The adapter handles these Liveblocks webhook events:
| Event | Role |
|---|---|
commentCreated | Drives Chat SDK message processing |
commentReactionAdded | Drives reaction handlers |
commentReactionRemoved | Drives reaction handlers |
Forward webhook requests to bot.webhooks.liveblocks:
The adapter verifies each request's signature with webhookSecret and returns 401 for an invalid request. Passing waitUntil lets work continue after the response is sent in serverless environments such as Vercel.
Resolving mentions
When comments contain @mentions, supply resolveUsers, and optionally resolveGroupsInfo, so the adapter can resolve the mentioned IDs:
Message format
Liveblocks Comments use a simpler body model than full Markdown. The adapter converts outbound Chat SDK content and flattens structure that the body model can't represent.
Comment bodies support paragraphs with bold, italic, code, strikethrough, links, and @mentions of users and groups.
The adapter flattens headings, bullet and numbered lists, code blocks, tables, and raw HTML to plain text or paragraphs. Tables render as ASCII inside a paragraph. Card payloads become markdown or plain text, or their fallbackText, and lose their interactivity.
Reactions
Pass Unicode emoji directly, or names such as thumbs_up that normalize to emoji where supported. Unknown custom IDs can fail API validation:
Thread IDs
Thread IDs take the form liveblocks:{roomId}:{threadId}, and channel IDs take the form liveblocks:{roomId}.
encodeThreadId
decodeThreadId
Throws if the format is invalid. Room IDs may contain : because the last : separates the threadId, which means Liveblocks thread IDs themselves must not contain :.
Feature support
Messaging
| Feature | Supported |
|---|---|
| Post message | |
| Message replies | |
| Edit message | |
| Delete message | |
| File uploads | Attachments |
| Streaming | |
| Scheduled messages |
Rich content
| Feature | Supported |
|---|---|
| Card format | Flattened to text |
| Buttons | |
| Link buttons | |
| Select menus | |
| Tables | Flattened to text |
| Charts | |
| Fields | |
| Images in cards | |
| Modals |
Conversations
| Feature | Supported |
|---|---|
| Slash commands | |
| Mentions | Users + groups |
| Add reactions | Unicode emoji |
| Remove reactions | Unicode emoji |
| Typing indicator | |
| Mark as read | |
| Message edit events | |
| Message delete events | |
| DMs | |
| Ephemeral messages | |
| User lookup | resolveUsers |
| Parent subject | |
| Native client | |
| Custom API endpoint |
Message history
| Feature | Supported |
|---|---|
| Fetch messages | |
| Fetch single message | |
| Fetch thread info | |
| Fetch channel messages | |
| List threads | |
| Fetch channel info | |
| Post channel message |
Resources
- Liveblocks Chat SDK Bot: a Next.js bot that responds to @mentions and reactions in Liveblocks comment threads (source).
- Liveblocks Chat SDK AI Bot: the same stack with an AI-powered reply flow (source).
- Full walkthrough: Get started with a Chat SDK bot using Liveblocks and Next.js.
- How to build an agent for Liveblocks with Chat SDK and AI SDK: build an AI agent that replies to @-mentions in Liveblocks comment threads with streamed responses and tool calling. Uses Chat SDK, the Liveblocks adapter, AI SDK's ToolLoopAgent, and Redis for thread subscriptions and distributed locking.
See all guides and templates on the resources page.