> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chatbotplatform.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Web Widget Channel

> Embed a chat launcher on your own website, identify signed-in users, and hand the bot tools that act for them

The **Web Widget** channel puts a chat launcher on any page of your site with a one-line script tag. Visitors chat with your bot in a panel that matches your light or dark theme, keep several conversations, and see unread badges. Your backend can tell the widget who the visitor is with a signed token, and can attach per-user MCP servers to every new conversation so an AI agent can act on their behalf.

Want the complete flow — web widget, AI agent and your product's own MCP server — set up end to end? Follow the guide [Embed an AI assistant backed by your product's MCP server](https://docs.chatbotplatform.io/guides/embedded-assistant-with-mcp.md). It is written for an AI agent to execute and flags every step that needs a human.

## Overview

A web widget channel gives you:

* **Embeddable launcher**: a script tag that renders a launcher button and chat panel on your pages
* **Visitor identity**: a short-lived HS256 token your backend signs so conversations are bound to your user ids
* **Access control**: anonymous visitors on or off, and an allow-list of origins the widget may load from
* **Multiple conversations**: visitors start, resume and close conversations; unread counts show on the launcher
* **Theming**: a light and a dark accent color, an optional header color per mode, following your site's theme automatically
* **Realtime delivery**: an optional WebSocket that pushes replies and typing the moment they happen, with polling as the automatic fallback (see [Realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md))
* **MCP servers for conversations**: a webhook your backend answers with the MCP servers to attach to each new conversation

The widget talks to a public, rate-limited API on the platform. Your pages never need to call that API directly; the script handles it.

## Create the channel

**1. Open your bot's channels**

In the dashboard, open your bot and click **Channels**, then **Add channel**.

**2. Choose Web Widget**

Select **Web Widget** in the platform picker.

**3. Name and style it**

Fill in the form:

| Field | What it does | Default |
| - | - | - |
| **Channel Name** | Internal name shown in your channel list | required |
| **Widget Title** | Header of the chat panel | bot name |
| **Agent name** | Sender name on the bot's bubbles, e.g. "Ava from Acme" | widget title |
| **Greeting** | First message visitors see when they open the chat | none |
| **Position** | Bottom right or bottom left | bottom right |
| **Accent color (light / dark)** | Launcher, header and visitor bubbles in each mode | `#1c1917` / `#e7e5e4` |
| **Header color (light / dark)** | Optional: the chat panel's header (its navbar) in each mode; empty keeps it on the accent | same as the accent |
| **Color scheme** | Auto (follow the site), Always light, Always dark | auto |
| **Push replies over a WebSocket** | [Realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md) of replies and typing, with polling as the fallback | on |

**4. Decide who can chat**

* **Allow anonymous visitors** — leave **off** when your site will identify users with a signed token; turn it **on** for public sites where anyone may chat.
* **Allowed origins** — one per line, such as `https://www.example.com` or `https://*.example.com`. Leave empty to allow any site.

**5. Save**

Click **Create Web Widget**. You land on the channel page with the embed snippet, the signing secret and, if the bot has no AI agent yet, the **Power this chat with an AI agent** section already open.

## Embed it on your site

Copy the snippet from the channel page and paste it before the closing `</body>` tag on every page where the launcher should appear:

```html theme={null}
<script src="https://app.chatbotplatform.io/widget/widget.js" data-widget-key="YOUR_WIDGET_KEY" async></script>
```

The **widget key** is shown under the snippet on the channel page. It is public — it only identifies the channel.

### Per-page overrides

Data attributes on the script tag override the channel settings for that page:

| Attribute | Overrides |
| - | - |
| `data-title` | Widget title |
| `data-agent-name` | Agent name on the bot's bubbles |
| `data-position` | `left` or `right` |
| `data-accent-color` | Light-mode accent |
| `data-dark-accent-color` | Dark-mode accent |
| `data-header-color` | Light-mode header background |
| `data-dark-header-color` | Dark-mode header background |
| `data-color-scheme` | `auto`, `light` or `dark` |
| `data-realtime` | `off` keeps this page on polling even when the channel pushes replies over a WebSocket |
| `data-fullscreen` | `off` hides the expand button on this page even when the channel offers [full screen](#full-screen-on-tablets-and-desktops); `on` offers it even when the channel does not |
| `data-user-token` | The signed identity token for the current user |

### Programmatic setup

Instead of data attributes you can load the script and call `ChatbotWidget.init()` yourself. This is the right choice for single-page apps that need to refresh identity tokens:

```html theme={null}
<script src="https://app.chatbotplatform.io/widget/widget.js" async></script>
<script>
  window.addEventListener('load', function () {
    ChatbotWidget.init({
      key: 'YOUR_WIDGET_KEY',
      agentName: 'Ava from Acme',
      // Called on load, and again when a token expires.
      getUserToken: async () => {
        const res = await fetch('/api/chat-widget-token');
        return (await res.json()).token;
      },
    });
  });
</script>
```

### JavaScript API

| Call | Effect |
| - | - |
| `ChatbotWidget.open()` | Open the panel |
| `ChatbotWidget.newConversation()` | Start a fresh conversation |
| `ChatbotWidget.openConversations()` | Show the visitor's conversation list |
| `ChatbotWidget.openConversation(id)` | Open one of the user's conversations by id (opens the panel); resolves with `opened`, `unavailable` or `error` — see [below](#open-a-conversation-by-id) |
| `ChatbotWidget.ready()` | Resolves once the widget has loaded (with the instance, or `null` when it could not load on this page) |
| `ChatbotWidget.closeConversation(id?)` | End (archive) a conversation: the one on screen when called without an id, or any of the user's conversations by id, without opening it; with an id it resolves with `{ status: 'closed' \| 'error', conversationId, closedAt }` — see [Archiving conversations from the list](#archiving-conversations-from-the-list) |
| `ChatbotWidget.renameConversation(name)` | Give the conversation on screen a name of the visitor's choosing (blank clears it); resolves with `{ status: 'renamed' \| 'error', conversationId, name }` — see [Naming conversations](#naming-conversations) |
| `ChatbotWidget.starConversation()` / `ChatbotWidget.unstarConversation()` | Pin the conversation on screen to the top of the list, or take the star off; both resolve with `{ status: 'starred' \| 'unstarred' \| 'error', conversationId, starred }` — see [Starring conversations](#starring-conversations) |
| `ChatbotWidget.unreadCount()` | Total unread bot replies across the visitor's conversations |
| `ChatbotWidget.typing()` | The ids of the conversations the bot is busy in right now (typing, or a reply is awaited); `[]` when idle |
| `ChatbotWidget.setColorScheme('dark' \| 'light' \| 'auto')` | Switch the theme at runtime |
| `ChatbotWidget.colorScheme()` | The resolved mode |
| `ChatbotWidget.transport()` | `'socket'` while replies are pushed over a WebSocket, `'poll'` otherwise |
| `ChatbotWidget.expand()` / `ChatbotWidget.collapse()` | Switch the open panel to the [full-screen layout](#full-screen-on-tablets-and-desktops) and back (only while the panel is open and the screen is 768px or wider); both return the layout now in use |
| `ChatbotWidget.layout()` | `'fullscreen'` while the panel fills the screen, `'compact'` otherwise |

The widget also fires events on `window` so your page can react without polling it — see [Events for your own UI](#events-for-your-own-ui) below.

### Events for your own UI

Build a badge in your header, a "the assistant is working" spinner or an activity log around the widget by listening for `chatbot-widget:*` events on `window`. Every event is a `CustomEvent`; the payload is `event.detail`. They fire while the panel is open **and while it is closed**, on both delivery modes (the WebSocket pushes replies and typing for every conversation; on polling the widget's background list poll carries the same, every 3–10 seconds, see [Realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md)). On polling, a hidden tab with the notification sound off pauses that poll and catches up when the tab is visible again.

| Event | When | `event.detail` |
| - | - | - |
| `chatbot-widget:message` | Once per bot reply the widget learns about, in any of the user's conversations | `{ conversationId, count, message, onScreen, unread }` — `count` replies landed in `conversationId` in this batch; `message` is the newest of them as `{ id, role, text, created_at }` (or `null`; `text` is the list's 140-character preview and `id` is `null` when the widget only learned about it from its conversation list); `onScreen` is whether the visitor was looking at that conversation (then it is already read); `unread` is `{ total, conversations: { [conversationId]: count } }` as it stands after this reply |
| `chatbot-widget:unread` | Whenever the unread total changes (a reply lands somewhere out of view, the visitor views a conversation) | `{ total, conversations: { [conversationId]: count } }` — `total` across the user's conversations, and only conversations with unread replies in the map; `Object.keys(detail.conversations).length` is the number of conversations with something unread |
| `chatbot-widget:typing` | When the bot starts or stops working on a reply in a conversation | `{ conversationId, typing: true \| false }` — one event per change, per conversation |
| `chatbot-widget:notify` | A reply landed while the chat was out of view and the notification ping was due | `{ conversationId, count, played }` |
| `chatbot-widget:open-conversation` | A conversation was opened by id, or could not be ([below](#open-a-conversation-by-id)) | `{ source, status, conversationId, error?, message? }` |
| `chatbot-widget:conversation-renamed` | The conversation on screen was given a name, or had it cleared ([Naming conversations](#naming-conversations)) | `{ conversationId, name }` — `name` is `null` when it was cleared |
| `chatbot-widget:conversation-starred` | The conversation on screen was starred or unstarred ([Starring conversations](#starring-conversations)) | `{ conversationId, starred, starredAt }` — `starredAt` is `null` when the star was removed |
| `chatbot-widget:conversation-closed` | A conversation was ended in this tab: from the chat view's **End conversation**, the list's swipe-to-archive button or your `closeConversation(id)` ([Archiving conversations from the list](#archiving-conversations-from-the-list)) | `{ conversationId, closedAt, source: 'chat' \| 'list' \| 'api' }` |
| `chatbot-widget:transport` | Delivery switched between the WebSocket and polling | `{ transport: 'socket' \| 'poll' }` |
| `chatbot-widget:layout` | The panel switched between its compact size and the full-screen layout (the visitor's button, your `expand()`/`collapse()`, a window resize across the 768px breakpoint, closing the panel) | `{ layout: 'compact' \| 'fullscreen' }` |
| `chatbot-widget:ready` | The widget finished loading (or could not) | `{ loaded: true \| false }` |

**What "typing" means.** `typing: true` is the same state the widget's own bouncing dots and *Typing…* status show: the bot has signalled it is composing (your integration's typing indicator, the agent loop's thinking) **or** the visitor just sent a message and the reply is still awaited (that wait ends when the reply lands, or after 90 seconds). A bot that never signals typing still produces a `true`/`false` pair around every reply to the visitor's own messages. Typing signals expire on their own after a few seconds unless the bot refreshes them, so a lost "stopped" never leaves your indicator on. `ChatbotWidget.typing()` returns the current state (an array of conversation ids) whenever you need it outside an event, e.g. on page load.

```js theme={null}
// An unread badge in your own header, kept right across page loads
// (the widget caches the counts, so the first event fires early).
const badge = document.querySelector('#support-badge');
const showUnread = (total) => { badge.textContent = total; badge.hidden = total === 0; };
window.addEventListener('chatbot-widget:unread', (e) => showUnread(e.detail.total));
window.addEventListener('chatbot-widget:ready', () => showUnread(ChatbotWidget.unreadCount()));

// Log every reply, wherever it lands.
window.addEventListener('chatbot-widget:message', (e) => {
  const { conversationId, count, message, onScreen, unread } = e.detail;
  console.log(`${count} new in ${conversationId}:`, message?.text, onScreen ? '(on screen)' : `(${unread.total} unread)`);
});

// A "working on it" indicator that survives the visitor closing the panel.
const spinner = document.querySelector('#assistant-working');
window.addEventListener('chatbot-widget:typing', () => {
  spinner.hidden = ChatbotWidget.typing().length === 0;
});
```

Older events keep their shapes: `chatbot-widget:unread` fires on every change of the total (not on every reply — a reply in the conversation on screen is read at once and leaves the total alone, which is why `chatbot-widget:message` exists), and `chatbot-widget:notify` is tied to the notification ping, so it stays quiet while the visitor looks at the chat or when the sound is off.

### Open a conversation by id

Deep-link a user into one of their conversations — from an order page, a notification email, a support ticket — with:

```js theme={null}
const result = await ChatbotWidget.openConversation(conversationId);
// result: { status: 'opened' | 'unavailable' | 'error', conversationId, error?, message? }
```

**Signature.** `ChatbotWidget.openConversation(conversationId: string): Promise<OpenResult>`. `conversationId` is the conversation's UUID: the one in the admin conversation URL, in the `conversation.id` field of the webhook payloads and in the Conversations API. The promise never rejects.

| `status` | What happened | What the visitor sees |
| - | - | - |
| `opened` | The conversation belongs to the current user on this widget | The panel opens (if it was closed) on that conversation; replies keep arriving as usual, closed conversations open read-only |
| `unavailable` | The API answered 404: the id belongs to another user, to another widget key, or does not exist. One answer for all three, so ids cannot be probed. `error` is `not_found` | A **“This conversation isn’t available”** screen with a **Start new chat** button in place of the messages. The other conversation's content is never shown; **Start new chat** starts a fresh conversation for the current user, the back button returns to their list |
| `error` | Anything else; `error` names it: `network`, `http_500` (any status), `session_expired`, `missing_id` (empty id), `busy` (another request in flight), `not_loaded` (the widget could not load on this page) | The current view stays, the widget's error strip shows `message` |

**Who may open what.** Access follows the widget's identity: the `sub` of the [user token](#identify-your-users), or the anonymous visitor id when the widget allows anonymous visitors. A conversation can only be opened by the identity that owns it, on the widget key that created it.

**Event.** Every outcome is also fired as `chatbot-widget:open-conversation` on `window`, so you can react without holding on to the promise. `event.detail` is the result above plus `source`: `'api'` for your call, `'list'` when the visitor tapped a conversation in the widget's own list.

```js theme={null}
window.addEventListener('chatbot-widget:open-conversation', (event) => {
  const { source, status, conversationId, error, message } = event.detail;
  if (status === 'unavailable') analytics.track('chat_deep_link_unavailable', { conversationId });
});
```

**When you can call it.** Any time after `widget.js` has executed. Calls made before the widget has finished mounting (it fetches its configuration first) are queued and run once it has; `ChatbotWidget.ready()` resolves at that moment. If your code may run before the script tag itself has loaded, call it from the script's `load` event:

```html theme={null}
<script src="https://app.chatbotplatform.io/widget/widget.js" data-widget-key="YOUR_WIDGET_KEY" async
        onload="const id = new URLSearchParams(location.search).get('conversation'); if (id) ChatbotWidget.openConversation(id);"></script>
```

## Identify your users

Without a token the widget treats the visitor as anonymous, which only works while **Allow anonymous visitors** is on. To bind conversations to your own user accounts, your backend signs a **JSON Web Token (HS256)** with the channel's **signing secret** (shown on the channel page; keep it server-side) and hands it to the page via `data-user-token`, `userToken` or `getUserToken`.

### Token claims

| Claim | Required | Meaning |
| - | - | - |
| `sub` | Yes | Stable user id in your app (string, up to 255 characters). Conversations are scoped to it. |
| `exp` | Yes | Expiry as a unix timestamp, at most 24 hours ahead. |
| `name` | No | Display name, shown with the user's messages. |
| `email` | No | The user's email address. |
| `iat` / `nbf` | No | Issued-at / not-before. `iat` may be at most 5 minutes in the future. |
| `attributes` | No | Free-form JSON object (up to 4 KB) — plan, role, account id. Stored with the conversation and passed to your integrations and MCP webhook. |

Only `alg: HS256` is accepted. Tokens signed with `none` or any other algorithm are rejected. An expired token returns `401` with `code: token_expired`; a bad one `code: token_invalid`; a missing one on a channel without anonymous access `code: token_required`. The widget calls `getUserToken` again on `token_expired`, so long-lived sessions keep working.

> [accordion] Sign a token — Node
>
> ```javascript theme={null}
> // npm install jsonwebtoken
> import jwt from 'jsonwebtoken';
>
> const widgetToken = jwt.sign(
>   {
>     sub: String(user.id),        // required, stable id in your app
>     name: user.name,             // optional
>     email: user.email,           // optional
>     attributes: { plan: 'pro' }, // optional, up to 4 KB of JSON
>   },
>   process.env.CHATBOT_WIDGET_SECRET, // the channel's signing secret
>   { algorithm: 'HS256', expiresIn: '1h' } // at most 24h
> );
> ```

> [accordion] Sign a token — PHP
>
> ```php theme={null}
> <?php
> // HS256, no library needed.
> function base64url(string $data): string {
>     return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
> }
>
> $secret = getenv('CHATBOT_WIDGET_SECRET'); // the channel's signing secret
> $claims = [
>     'sub'   => (string) $user->id,
>     'name'  => $user->name,
>     'email' => $user->email,
>     'iat'   => time(),
>     'exp'   => time() + 3600,
>     'attributes' => ['plan' => 'pro'],
> ];
> $header    = base64url(json_encode(['alg' => 'HS256', 'typ' => 'JWT']));
> $payload   = base64url(json_encode($claims));
> $signature = base64url(hash_hmac('sha256', "$header.$payload", $secret, true));
> $widgetToken = "$header.$payload.$signature";
> ```

> [accordion] Sign a token — Python
>
> ```python theme={null}
> # pip install pyjwt
> import os, time, jwt
>
> widget_token = jwt.encode(
>     {
>         "sub": str(user.id),
>         "name": user.name,
>         "email": user.email,
>         "iat": int(time.time()),
>         "exp": int(time.time()) + 3600,
>         "attributes": {"plan": "pro"},
>     },
>     os.environ["CHATBOT_WIDGET_SECRET"],
>     algorithm="HS256",
> )
> ```

**Regenerate** on the channel page rotates the signing secret. Every token signed with the old secret stops working immediately, so update your backend first and rotate right after.

## Conversations and unread badges

Each identified user can hold several conversations on a widget. The widget shows a list (open conversations first, past ones collapsed), lets the visitor start a new one or resume an old one, and marks a conversation closed when they end it — closed conversations are read-only, and sending into one returns `409` with `code: conversation_closed`.

### Naming conversations

A conversation is listed under the first message the visitor sent until they give it a name. The pencil button in the panel header opens a small form over the composer; the name is free-form text (up to 80 characters, trimmed, line breaks collapsed), replaces the first-message title in the list and the sidebar and takes the place of the widget title in the header while that conversation is open. Past (closed) conversations can be named too. Saving a blank name clears it, so the default title is back.

The name is stored on the conversation, so it follows the visitor across devices and page loads and shows on the conversation page in the dashboard. Your page can set it as well with `ChatbotWidget.renameConversation(name)` and hear about every change through the `chatbot-widget:conversation-renamed` event on `window` (`detail: { conversationId, name }`, `name` is `null` when it was cleared). Channels with [realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md) push the new name to the visitor's other tabs the moment it is saved.

### Starring conversations

The list orders conversations by their latest activity, so a conversation the visitor keeps coming back to can slip down as newer ones get replies. The star button in the panel header pins the open conversation to the top: starred conversations always sit above every unstarred one, newest activity first inside each group, and each shows a small star before its title. Tapping the star again takes it off. Starring is the visitor's own: a conversation belongs to one identified user, so nobody else sees or shares the star.

Ending a conversation always takes its star off — only open conversations are pinned, and past conversations never show a star button. The star is stored on the conversation, so it follows the visitor across devices and page loads, and the conversation page in the dashboard shows when it was starred. Your page can star and unstar the conversation on screen with `ChatbotWidget.starConversation()` and `ChatbotWidget.unstarConversation()` (both resolve with `{ status: 'starred' | 'unstarred' | 'error', conversationId, starred }`; starring an ended conversation answers `error: 'conversation_closed'`) and hear about every change through the `chatbot-widget:conversation-starred` event on `window` (`detail: { conversationId, starred, starredAt }`). Channels with [realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md) reorder the visitor's other tabs the moment a star changes.

### Archiving conversations from the list

A conversation can be ended straight from the list, without opening it: swiping an open conversation's row to the left (or dragging it with the mouse) slides it over and reveals a red **Archive** button at its right edge. Tapping Archive ends that conversation the way **End conversation** in the chat view does — it moves under **Past conversations**, becomes read-only and loses its star — and the list stays on screen. A short swipe snaps back, a tap on the revealed row or anywhere else in the list puts the button away (only a tap on another row opens that one), swiping the row back to the right closes it too, and one row shows its button at a time. Past conversations have no Archive button. There is no confirmation step: the swipe and the tap are the two deliberate steps, and a conversation that was ended cannot be reopened, so a visitor who wants to keep one just lets the row snap back.

Your page can do the same by id with `ChatbotWidget.closeConversation(id)` (resolves with `{ status: 'closed' | 'error', conversationId, closedAt }`, `closed` also for a conversation that had already ended) and hears about every conversation ended in this tab — from the chat view, the list or your own call — through the `chatbot-widget:conversation-closed` event on `window` (`detail: { conversationId, closedAt, source }`, `source` is `'chat'`, `'list'` or `'api'`). Channels with [realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md) move the conversation in the visitor's other tabs the moment it ends.

Unread bot replies are counted per conversation. The launcher shows the total while the panel is closed, the list shows a count per conversation, and viewing a conversation clears its count. Counts are cached in the browser so the badge is right on the next page load before the first poll. Your page can show its own badge from `ChatbotWidget.unreadCount()` and the `chatbot-widget:unread` / `chatbot-widget:message` events, and a progress indicator from `chatbot-widget:typing` — see [Events for your own UI](#events-for-your-own-ui).

In the dashboard, every widget conversation shows the identified user (id, name, email, attributes), the page it was started on, the name the visitor gave it, whether they starred it and whether it is closed.

New channels push replies, typing and unread counts over a WebSocket the moment they happen and fall back to polling by themselves whenever a socket cannot connect; older channels poll until you tick **Push replies over a WebSocket** under **Delivery** on the channel page. Details, host-page controls and the connection-count note are on [Realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md).

## Message formatting

Messages are written in Markdown and the widget renders it, in every bubble, the visitor's and the bot's alike. Nothing a visitor or a bot sends is ever treated as HTML: the text is escaped before any formatting is applied, so a `<script>` tag or an `onerror` attribute in a message is shown as those characters, never run. The widget has no Markdown library and no sanitizer to keep patched; its renderer can only produce the handful of tags listed here, and a link is only made clickable when its address is a web page (`http://` or `https://`), an email address (`mailto:`) or a phone number (`tel:`).

| You write | The widget shows |
| - | - |
| `**bold**`, `*italic*`, `~~struck~~` | **bold**, *italic*, ~~struck~~ |
| `` `code` `` | `code` |
| A fenced block: ` ```js ` … ` ``` ` | a code block (scrolls sideways, no highlighting) |
| `[the docs](https://example.com/docs)` | a link reading "the docs" |
| `https://example.com/docs?page=2` or `www.example.com` | the URL as a link |
| `[email us](mailto:help@example.com)`, `[call us](tel:+15551234567)` | a link that opens the visitor's mail or phone app |
| `support@example.com`, `<support@example.com>`, `mailto:…`, `tel:…` | the address as a link |
| `- item` / `1. item`, indented for nesting, `- [x] done` for a task | bullet, numbered and task lists |
| `> quoted` | a quote |
| `## Heading` | a heading, sized to fit a chat bubble |
| `\| Plan \| Price \|` with a `\|---\|---:\|` row under it | a table (scrolls sideways when wide) |
| `---` on its own line | a divider |
| `\*literal\*` | the character itself |

A single newline inside a paragraph is a line break, as chat readers expect; a blank line starts a new paragraph. Web links open in a new tab with `rel="noopener noreferrer"`; a `www.` host gets `https://`; `mailto:` and `tel:` links carry no `target`, so they hand off to the mail or phone app without leaving a blank tab behind (a `mailto:` address needs an `@`, a `tel:` number is digits with `+ - . ( )`, anything else stays text, and a bare phone number such as "call 555-0100" is never linked, only a `tel:` one); punctuation right after a URL and the closing bracket of a parenthesised one stay outside the link, and URLs inside `` `code` `` stay as they are. Images are not loaded: `![logo](https://example.com/logo.png)` becomes a link to the image, so a message can never make a visitor's browser fetch a URL of its choosing. Indented (four-space) code blocks are not supported — use fences. Plain-text messages look exactly as before.

The built-in echo bot's system prompt tells it what renders. Bots on an agent-loop or webhook integration get the same guidance from your system prompt: Markdown is rendered, prefer short paragraphs and lists, keep tables small, and never send raw HTML.

## Full screen on tablets and desktops

Tick **Let visitors expand the chat to full screen** under **Layout** on the channel page and the chat header gets an expand button on screens 768px and wider (tablets and desktops). Full screen fills the browser window: the visitor's conversations are listed on the left third, scrollable, with a **New conversation** button on top, and the open conversation takes the right two thirds. Everything else works as in the compact panel — unread counts, ending a conversation, typing, the notification ping.

The panel **reopens in the size the visitor closed it in**: close it in full screen and the next open — on this page or the next one — is full screen again, collapse first and it comes back compact. The choice is remembered in the visitor's browser (localStorage, next to their conversations, per signed-in user); a first-time visitor or one who cleared site data gets the compact panel. When the window shrinks below 768px while expanded, the panel drops back to compact and the button hides; if the window grows back while the panel is still open, full screen returns. Phones keep today's full-height panel and never show the button. With the setting off nothing changes for anyone.

Your page can hide the button per page with `data-fullscreen="off"` on the embed snippet or `ChatbotWidget.init({ fullscreen: false })` (and offer it on a page even when the channel does not with `"on"` / `true`), switch the layout with `ChatbotWidget.expand()` and `ChatbotWidget.collapse()` while the panel is open, read it with `ChatbotWidget.layout()`, and listen for `chatbot-widget:layout` on `window` (`event.detail.layout` is `'compact'` or `'fullscreen'`) to hide a sticky header of your own while the chat fills the screen.

## Light and dark mode

The widget ships both themes and you pick an accent per mode under **Colors**; text on the accent switches between white and near-black automatically for contrast. The panel header can have its own background per mode with **Header color (light mode)** and **Header color (dark mode)**: a `#rrggbb` value, or leave it empty (the **Use accent** button clears it) to keep the header on the accent, which is what every widget does until you set one. Text and buttons in the header pick white or near-black against that color the same way. Per page, `data-header-color` and `data-dark-header-color` on the embed snippet (or `headerColor` / `darkHeaderColor` in `ChatbotWidget.init()`) override them. With **Color scheme** on **Auto** the widget follows your site: a `dark` or `light` class or a `data-theme` attribute on `<html>`, a `color-scheme` pinned to one mode, and otherwise the visitor's system preference. It also reacts when your own theme toggle changes those. Force a mode per page with `data-color-scheme="dark"` or at runtime with `ChatbotWidget.setColorScheme()`.

The **Open preview page** button on the channel page shows the widget on a stand-in site with a **Light site / Dark site** toggle.

## MCP servers for conversations

Expand **MCP servers for conversations** on the channel page to name a webhook on your backend. When a visitor starts a **new** conversation, the platform POSTs a signed `conversation.started` payload describing the visitor, and your backend answers with the MCP servers (URL plus auth headers) to attach to that conversation — a CRM, an orders API, anything scoped to that user. An [agentic loop](https://docs.chatbotplatform.io/agentic-loops/overview.md) on the bot can then call those tools from the very first message.

* **Timeout and retry**: 10 seconds, retried once. A failing webhook never blocks the conversation; it simply starts without extra servers.
* **Signature**: `X-Chatbot-Timestamp` plus `X-Chatbot-Signature: v1=<hex HMAC-SHA256 of "timestamp.body">` with the **webhook secret** minted the first time you save a URL. Reject stale timestamps.
* **Response**: HTTP 200 with `{ "mcp_servers": [ { "name", "url", "headers": [ { "key", "value" } ] } ] }`. Up to 20 servers; an empty list is fine.
* **Preferences** (optional): the same response may add `"preferences": [ "User's timezone for dates and times: America/Chicago", … ]`, up to 20 strings of at most 1000 characters, which pre-fill the conversation's preferences so the agent knows them from its first reply. Texts already recorded are left alone and nothing is ever removed; the list is ignored while the bot's Preferences switch is off. Details and examples: [Embed an AI assistant backed by your product's MCP server → Preferences](https://docs.chatbotplatform.io/guides/embedded-assistant-with-mcp.md#preferences-optional).
* **Skills** (optional): the response may also add `"skills": [ { "name", "summary", "content" } ]`, up to 20 processes saved as [skills](https://docs.chatbotplatform.io/bots/channels/user-skills.md) of the person behind the conversation. Names they do not have yet are created; a skill they already have is never overwritten and one they deleted is not brought back. Ignored while the bot's Skills switch is off. Details: [Embed an AI assistant → Skills](https://docs.chatbotplatform.io/guides/embedded-assistant-with-mcp.md#skills-optional).
* **Static headers**: optional headers sent with every request, for example an API key your endpoint expects.
* **Send test request** fires a signed `conversation.test` with the saved URL and shows what your webhook answered.
* **Built-in test webhook**: no backend yet? Click **Use built-in test webhook**. The platform's own endpoint answers with the **Widget Identity** MCP server (`whoami`, `get-user-attribute`), so you can ask the bot "what is my email address?" and watch the whole pipeline work.

The admin conversation page has an **MCP servers** tab showing the discovery outcome and a **Re-run discovery** button.

### Skills

With **Skills** on for the bot (Behavior → Agent Context), a widget user can teach the agent a process once and ask for it in any later conversation. Skills follow the identity: the `sub` of the identity token, or the anonymous visitor id of the browser. A visitor links their Telegram or Slack account by sending `/link CODE` in the chat, or your page calls `ChatbotWidget.claimLinkCode(code)` (resolves `{ status: 'linked' | 'error', outcome, message, skillsNowAvailable, renamed }`, fires `chatbot-widget:linked`). See [Skills](https://docs.chatbotplatform.io/bots/channels/user-skills.md).

The full contract with payload and verification examples is in the guide: [Embed an AI assistant backed by your product's MCP server](https://docs.chatbotplatform.io/guides/embedded-assistant-with-mcp.md).

## Power it with an AI agent

The channel page opens with **Power this chat with an AI agent**. Enter a system prompt, pick a tool-capable model, paste your team's OpenRouter API key if it has none, choose the **Tools for each visitor** option (built-in test server, your webhook URL, or none), leave **Only the agent answers** ticked and click **Launch agent**. The platform creates an agentic-loop integration on the bot (or updates the one it created before), switches off competing integrations and points MCP discovery where you asked. The **Test your web chat** panel below it then lists what is still missing and lets you chat with the real widget as yourself.

## Troubleshooting

| Symptom | Check |
| - | - |
| Launcher does not appear | The script tag is on the page and the widget key is right. If **Allowed origins** is set, the page's origin must match. |
| `token_required` | Anonymous visitors are off and no token was provided. Pass a token or enable anonymous visitors. |
| `token_invalid` | Wrong secret, non-HS256 algorithm, `sub` missing, or `exp` more than 24 hours ahead. |
| Bot replies but does not know the user | The bot answers with a webhook/echo integration, not an agent, or the conversation pre-dates the MCP webhook. Launch the agent, then start a new conversation or click **Re-run discovery**. |
| **Send test request** fails with 401 | Your webhook verifies with an old secret. Copy the current one from the channel page. |

## Next steps

> [card] [Embed an AI assistant with MCP](https://docs.chatbotplatform.io/guides/embedded-assistant-with-mcp.md)
>
> Agent-executable guide from empty account to a live assistant using your product's tools

> [card] [Agentic Loops](https://docs.chatbotplatform.io/agentic-loops/overview.md)
>
> How the agent reasons and calls tools

> [card] [Realtime delivery](https://docs.chatbotplatform.io/bots/channels/web-widget-realtime.md)
>
> Push replies over a WebSocket, with polling as the fallback

> [card] [Other channels](https://docs.chatbotplatform.io/bots/channels/index.md)
>
> Telegram and Slack


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.