> ## 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.

# Realtime delivery

> Push bot replies, typing and unread counts to the Web Widget over a WebSocket, with polling as the automatic fallback

By default the Web Widget **polls** the platform: after a visitor sends a message it asks for the conversation every 1.5 seconds for a while, then every 5 seconds, and it refreshes the conversation list in the background to keep unread badges current. That works everywhere, but a reply can sit for up to a few seconds before the visitor sees it, and idle visitors keep making requests.

**Realtime delivery** opens one WebSocket per browser tab instead. Replies, typing and closed conversations arrive the moment they happen, and connected visitors drop to an occasional safety check. It is a per-channel setting: **new web widget channels have it on**, and channels created before realtime delivery existed keep polling until you tick the box.

Turning it on never breaks a chat. Whenever a socket cannot connect — a corporate proxy that blocks WebSockets, a full cluster, a network blip — the widget stays on polling exactly as before, and switches back to the socket as soon as it can.

## Check or change it

**1. Open the channel page**

In the dashboard, open your bot, click **Channels** and pick the web widget channel.

**2. Look under Delivery**

Under **Delivery**, **Push replies over a WebSocket (realtime)** is ticked on every channel created recently; tick it on older channels, or untick it to keep a channel on polling, and save. The channel list shows a **Realtime** badge next to every channel that has it on.

**3. Check the readiness panel**

**Test your web chat** at the top of the channel page lists a *Realtime delivery* row. It reads **on (Reverb)** when everything is in place. A warning there means the platform server the widget talks to has no WebSocket cluster attached yet: the setting is kept and takes effect once one is, and visitors stay on polling until then.

**4. Try it**

Start the test chat and send a message. The reply appears without a visible delay, and `ChatbotWidget.transport()` in the browser console returns `'socket'`.

## What changes for visitors

| | Polling (default) | Realtime |
| - | - | - |
| Bot reply appears | On the next poll, up to a few seconds later | As soon as it is written, typically well under a second |
| "Typing" indicator | Starts and stops on the next poll | Starts the moment the bot starts, clears the moment the reply lands |
| Unread badges in other tabs | On the next list refresh | Pushed at once |
| Idle visitor with the panel closed | A list request every few seconds | One safety check per minute |
| A conversation closed in another tab | Noticed on the next poll | Noticed at once |
| A conversation named or starred in another tab | Noticed on the next poll | Noticed at once |

Everything else is unchanged: the same conversations, the same identity tokens, the same unread badges and notification ping.

## When the socket opens

The widget only connects when there is something to deliver:

* A socket opens when the visitor **opens the panel**, or on page load when they **have chatted before** on this site. A first-time visitor who never opens the chat never uses a connection.
* One socket per browser tab. It is tied to the visitor's identity, so swapping the identity token (a sign-in or sign-out in your app) reconnects it.
* **Background tabs keep their socket** so the notification ping and unread badges keep working while the visitor is elsewhere.
* Closing the tab, or the session expiring, closes it.

While the socket is up, the widget still fetches the open conversation every 30 seconds and the conversation list every 60 seconds as a safety net, and it catches up with one fetch every time the socket (re)connects. Long replies that do not fit in a single WebSocket frame are fetched the same way, so nothing is ever lost.

## Fallback to polling

The widget decides on its own, per tab, and needs nothing from your page:

| Situation | What happens |
| - | - |
| The channel's toggle is off (older channels, or unticked on purpose) | Polling, as before |
| The platform has no WebSocket cluster attached | Polling; the setting takes effect once one is attached |
| WebSockets blocked by a proxy or firewall | Polling, with reconnect attempts in the background |
| The socket drops mid-conversation | Polling at the usual pace until the reconnect succeeds (1–30 seconds, with backoff) |
| The cluster is at its connection limit | New sockets fail the handshake; those visitors stay on polling |
| The page goes offline and back | Reconnects as soon as the browser reports it is online again |

## Host-page controls

You can keep a page on polling, read which transport is active, and react when it changes.

### Keep a page on polling

Add `data-realtime="off"` to the embed snippet:

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

Or, with [programmatic setup](https://docs.chatbotplatform.io/bots/channels/web-widget.md#programmatic-setup):

```js theme={null}
ChatbotWidget.init({
  key: 'YOUR_WIDGET_KEY',
  realtime: false,
});
```

Both only turn the socket **off** for that page; they cannot turn it on for a channel whose toggle is off.

### Read the active transport

```js theme={null}
ChatbotWidget.transport(); // 'socket' or 'poll'
```

`'socket'` means replies are being pushed right now. `'poll'` covers everything else: the toggle is off, the socket is still connecting, or it dropped and polling has taken over.

### React to changes

The widget fires `chatbot-widget:transport` on `window` every time the transport switches:

```js theme={null}
window.addEventListener('chatbot-widget:transport', (event) => {
  console.log('widget transport is now', event.detail.transport); // 'socket' | 'poll'
});
```

Use it, for example, to show a "live" dot in your own UI, or to log how often visitors fall back to polling.

## Connections and cost

The platform's WebSocket capacity is provisioned as a maximum number of **concurrent connections**, and every open chat tab on every site that has the toggle on counts as one while the visitor has the panel open or has chatted before, including background tabs. Messages are not metered.

Before switching a busy site on, estimate the peak number of visitors who have the chat open at the same time. If you expect it to be large, enable the channel first on a lower-traffic page (or keep high-traffic pages on polling with `data-realtime="off"`) and ask us about capacity. If the limit is reached, nobody loses the chat; the visitors who could not connect simply stay on polling.

## Troubleshooting

| Symptom | Check |
| - | - |
| `ChatbotWidget.transport()` stays `'poll'` | The toggle is on and the readiness row reads **on (Reverb)**. The page does not carry `data-realtime="off"`. The browser can open WebSockets (try from another network). |
| Readiness row warns about the server | The platform server has no WebSocket cluster attached yet. Your setting is kept; visitors stay on polling until it is. |
| Replies arrive but typing never shows | Typing is still controlled by the bot's **Typing indicators** behavior; the socket only delivers it faster. |
| The transport flips back and forth | A proxy is closing idle connections; the widget reconnects with backoff and polls in between. Visitors see every reply either way. |

## Next steps

> [card] [Web Widget channel](https://docs.chatbotplatform.io/bots/channels/web-widget.md)
>
> Embedding, identity tokens, conversations and theming

> [card] [Bot Behaviors](https://docs.chatbotplatform.io/bots/behaviors/index.md)
>
> Typing indicators, debouncing and reply detection


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