Skip to main content
Add Relay to a Chat SDK bot by putting one adapter in its adapters map. @relaymessenger/chat-sdk-adapter receives signed message.received webhooks, hands each one to your existing handlers as a Chat SDK message, and commits replies through POST /v1/messages. A bot that already answers on other platforms reaches Relay users without a second codebase. Prerequisites:
  • An agent and its Agent Token. See Create and connect an agent.
  • A registered webhook with its signing secret. See Webhooks.
  • A Chat SDK app. chat is a peer dependency, version ^4.38.0.
The adapter validates both secrets while the module is evaluated, so on Cloudflare Workers a missing or malformed value fails the deploy rather than the first request.
The adapter is published as @relaymessenger/chat-sdk-adapter and developed in the public relaymessenger/Relay-SDK repository under integrations/chat-sdk.

Quickstart

app/api/relay/route.ts
Mount the handler as the POST route your webhook registration points at. The adapter ships no runtime dependencies. It scopes each turn with AsyncLocalStorage, so run it on Node or on a runtime with Node compatibility enabled, such as Cloudflare Workers with nodejs_compat.
A Relay conversation arrives as a Chat SDK thread whose id is relay:<chat_id>. Handlers you already wrote for other platforms run unchanged.

What the adapter enforces

Each row is a contract from these docs that the adapter implements for you.
The dedupe window is a bounded set in memory in one process. A restart, or a second instance behind the same webhook URL, has no claim to lose and dispatches the event again. The idempotency key is what makes that second dispatch harmless.

Configuration

What each operation does on Relay

Set streaming: false where your host offers the choice. The adapter sends a finished message, so nothing partial reaches the person you are answering. See Sending messages for the send contract it uses.

Formatting

Relay does not render Markdown. A text part carries plain text plus styles runs with UTF-16 offsets, and clients draw the runs. The adapter flattens { markdown } and { ast } to the text a person reads and carries emphasis across as style ranges. Constructs Relay has no style for keep their information in the text. A link whose label differs from its target renders as label (url), a blockquote keeps its > prefix, a list keeps its markers, inline and fenced code keep their backticks, and a table is flattened to one text line per row.

Next steps