# Web widget

> One script tag, signed visitor sessions, every visitor in the inbox.

URL: https://chatwork.io/en/docs/widget
Section: Platform

```html
<script src="https://chatwork.io/widget.js" data-tenant="your-slug" async></script>
```

The widget is served by the bridge; `data-tenant` selects the tenant. On load it asks for a signed visitor session (`POST /api/v1/tenants/{slug}/widget/session`, rate-limited per IP and slug), caches it in `localStorage` and sends it as a bearer token on every message.

## What happens to a message

`POST /api/v1/tenants/{slug}/inbound` runs the same pipeline as every other channel: control check, quota reservation, Chatwork Router routing, model call, delivery. The conversation is created or appended on the tenant's Chatwork inbox (awaited, not fire-and-forget); if the inbox is unreachable the visitor still gets the reply and a failed `inbound_mirror` event is stored for replay.

The response includes `agent` and `routing` (the decision, candidates and citations), which you can use to show "answered by Dot Orders" in your own UI.

## Contracts

- `GET /api/v1/tenants/{slug}/public` returns the company name and inbox id, never keys or invoices.
- A widget token is valid only for its slug, its visitor id and `channel_type = web_widget`.
- `window.DiamondDotWidget.{open, close, setTenant}` and the `localStorage` keys `diamond_dot_visitor_id`, `diamond_dot_widget_session` are frozen identifiers (customer pages depend on them).
