Today, we’re releasing a new adapter for Chat SDK that lets you build
cross-platform bots that can respond in [Liveblocks comment threads](/comments).
With a single codebase, you can power bots across 10+ platforms, including
Slack, Microsoft Teams, Discord—and now Liveblocks.

## Trigger AI workflows from other platforms

One common use case for [Chat SDK](https://chat-sdk.dev/) is triggering AI
workflows from external apps like Slack. Picture this: you’ve built a realtime
app with Liveblocks that lets users create table-based documents. From Slack,
you can `@mention` your bot, and ask it to create a new document.

<Figure caption="Triggering the bot’s “Create document” tool from Slack">
  <MuxVideo
    playbackId="yxkCTXis2DvHcQ7IDikBD02oDLtjdBsYS01eR2001NJhe00"
    alt="Triggering an AI change from Slack"
    static={true}
  />
</Figure>

With the addition of the Liveblocks adapter for Chat SDK, you can now `@mention`
the same bot inside Liveblocks comment threads, and it behaves identically to
Slack—all powered by a single codebase.

<Figure caption="Triggering the bot’s “Edit document” tool from Liveblocks">
  <MuxVideo
    playbackId="8QnWe24fLCdp00Mcdvm01YCx32ZkmQeyio00USRq13RGA8"
    alt="Triggering an AI change from Liveblocks comments"
    static={true}
  />
</Figure>

## Liveblocks adapter

Chat SDK exposes simple TypeScript events and methods, which you can wire into
your adapters. For example, here’s how to create a bot that automatically
replies when it’s mentioned.

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

Each adapter translates these events into platform-specific actions, so your bot
logic stays platform-agnostic. With the Liveblocks adapter configured, this code
produces an automated reply inside a comment thread.

<Figure>
  <MuxVideo
    playbackId="bCjVXncIObcad1NmiTPle00jadtHpEsFdrBOd00B2WsjE"
    alt="Liveblocks Comments bot"
    static={true}
  />
</Figure>

You can register multiple adapters simultaneously, allowing a single bot to
operate across platforms.

### Setting up the adapter

To get started, create an instance of the Liveblocks adapter with
[`createLiveblocksAdapter`](/docs/api-reference/liveblocks-chat-sdk-adapter) and
pass it into `new Chat`. You’ll need Liveblocks secret keys and a webhook
configured in your dashboard.

```ts
import { Chat } from "chat";
import { createLiveblocksAdapter } from "@liveblocks/chat-sdk-adapter";
import { createMemoryState } from "@chat-adapter/state-memory";

// +++
const liveblocks = createLiveblocksAdapter({
  apiKey: "{{SECRET_KEY}}",
  webhookSecret: "whsec_...",
  botUserId: "__bot__",
  botUserName: "Liveblocks Bot",
});
// +++

const bot = new Chat({
  userName: "Liveblocks Bot",
  // +++
  adapters: { liveblocks },
  // +++
  state: createMemoryState(),
});

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

Find more information in our
[Chat SDK documentation](/docs/api-reference/liveblocks-chat-sdk-adapter) or try
our [Chat SDK bot example](/examples/chat-sdk-bot/nextjs-chat-sdk-bot).

### Adding AI to your bot

You can add AI to your bot in different ways. One approach is to wait until the
bot is mentioned, and then subscribe to the thread and automatically reply to
all subsequent messages.

<Figure>
  <MuxVideo
    playbackId="EkKkxgjKNVSE73Q9b71DMhD1B7MzXNQ7f12tusOUNRk"
    alt="Liveblocks Comments AI bot"
    static={true}
  />
</Figure>

To set up a bot that replies to all comments after its first mention in a
thread, use `thread.subscribe` and `bot.onSubscribedMessage`.

```ts
// First mention in the thread, subscribe to thread and reply
bot.onNewMention(async (thread, message) => {
  await thread.subscribe();
  const response = await __generateAIResponse__(message.text);
  await thread.post(response);
});

// On receiving later thread messages, reply
bot.onSubscribedMessage(async (thread, message) => {
  const response = await __generateAIResponse__(message.text);
  await thread.post(response);
});
```

Our [Chat SDK AI bot example](/examples/chat-sdk-ai-bot/nextjs-chat-sdk-ai-bot)
shows how to set up a bot that replies when mentioned, and describes how to set
up a subscription inside `bot.ts`.

## Get started now

To get started, follow our Next.js quickstart and deploy your first
cross-platform bot in minutes.

<ButtonLink href="/docs/get-started/nextjs-chat-sdk-bot" size="lg">
  Get started now
</ButtonLink>

## Contributors

<Contributors gitHubUsernames={["nimeshnayaju"]} />