Liveblocks

Chat SDK adapter backed by Liveblocks Comments. Maps Liveblocks rooms, threads, and comments to the Chat SDK channel, thread, and message model.

Vendor-official adapter maintained by Liveblocks, not Vercel or Chat SDK contributors. For feature requests, bug reports, and support, file an issue on the adapter's repo.

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 -y

The 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-adapter

Quick start

lib/bot.ts
import { Chat } from "chat";
import { createMemoryState } from "@chat-adapter/state-memory";
import {
  createLiveblocksAdapter,
  type LiveblocksAdapter,
} from "@liveblocks/chat-sdk-adapter";

const bot = new Chat<{ liveblocks: LiveblocksAdapter }>({
  userName: "MyBot",
  adapters: {
    liveblocks: createLiveblocksAdapter({
      apiKey: process.env.LIVEBLOCKS_SECRET_KEY,
      webhookSecret: process.env.LIVEBLOCKS_WEBHOOK_SECRET,
      botUserId: "my-bot-user",
      botUserName: "MyBot",
    }),
  },
  state: createMemoryState(),
});

bot.onNewMention(async (thread, message) => {
  await thread.adapter.addReaction(thread.id, message.id, "👀");
  await thread.post(`Hello, ${message.author.userName}!`);
});

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

  1. Create a Liveblocks project with rooms using Comments.
  2. In the dashboard, copy a secret key (sk_...) for server-side REST API calls.
  3. Create a webhook signing secret (whsec_...) and configure webhooks to subscribe to:
    • commentCreated
    • commentReactionAdded
    • commentReactionRemoved
  4. Choose a stable botUserId that 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

PropTypeDefaultDescription
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?LoggerConsoleLogger("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:

EventRole
commentCreatedDrives Chat SDK message processing
commentReactionAddedDrives reaction handlers
commentReactionRemovedDrives reaction handlers

Forward webhook requests to bot.webhooks.liveblocks:

app/api/webhooks/liveblocks/route.ts
import { after } from "next/server";
import { bot } from "@/lib/bot";

export async function POST(request: Request) {
  return bot.webhooks.liveblocks(request, {
    waitUntil: (task) => after(() => task),
  });
}

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:

lib/bot.ts
const adapter = createLiveblocksAdapter({
  apiKey: process.env.LIVEBLOCKS_SECRET_KEY,
  webhookSecret: process.env.LIVEBLOCKS_WEBHOOK_SECRET,
  botUserId: "my-bot-user",

  resolveUsers: async ({ userIds }) => {
    const users = await getUsersFromDatabase(userIds);
    return users.map((user) => ({
      name: user.fullName,
      avatar: user.avatarUrl,
    }));
  },

  resolveGroupsInfo: async ({ groupIds }) => {
    const groups = await getGroupsFromDatabase(groupIds);
    return groups.map((group) => ({ name: group.displayName }));
  },
});

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:

await thread.adapter.addReaction(thread.id, message.id, "👍");
await thread.adapter.addReaction(thread.id, message.id, "thumbs_up");

Thread IDs

Thread IDs take the form liveblocks:{roomId}:{threadId}, and channel IDs take the form liveblocks:{roomId}.

encodeThreadId

adapter.encodeThreadId(data: { roomId: string; threadId: string }): string;
const encoded = adapter.encodeThreadId({
  roomId: "my-room",
  threadId: "th_abc123",
});
// "liveblocks:my-room:th_abc123"

decodeThreadId

adapter.decodeThreadId(threadId: string): { roomId: string; threadId: string };

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

FeatureSupported
Post message
Message replies
Edit message
Delete message
File uploadsAttachments
Streaming
Scheduled messages

Rich content

FeatureSupported
Card formatFlattened to text
Buttons
Link buttons
Select menus
TablesFlattened to text
Charts
Fields
Images in cards
Modals

Conversations

FeatureSupported
Slash commands
MentionsUsers + groups
Add reactionsUnicode emoji
Remove reactionsUnicode emoji
Typing indicator
Mark as read
Message edit events
Message delete events
DMs
Ephemeral messages
User lookupresolveUsers
Parent subject
Native client
Custom API endpoint

Message history

FeatureSupported
Fetch messages
Fetch single message
Fetch thread info
Fetch channel messages
List threads
Fetch channel info
Post channel message

Resources

See all guides and templates on the resources page.