Chatasist
Open App
Developers/Embed the widget

Embed the widget

Add the Chatasist live-chat widget to your website.

The website widget is a single <script> tag. It loads from the widget Worker domain and renders a launcher plus an iframe panel.

Minimal embed#

Add this before the closing </body> tag, replacing CHANNEL_UUID with your widget channel's UUID (from Settings → Channels → Website widget):

<script
  type="module"
  src="https://widget.chatasist.com/embed.js"
  data-chatasist="CHANNEL_UUID"
  data-chatasist-lang="en"
></script>

The widget is served from widget.chatasist.com. The embed script revalidates on every load, so a fresh deploy reaches visitors without a cache-buster on your tag.

Configuration attributes#

All options are set as data- attributes on the script tag:

AttributePurpose
data-chatasistRequired. The widget channel UUID.
data-chatasist-langWidget interface language. Supported: az, en, ru, tr (defaults to en). Also forwarded so the AI agent replies in the same language.
data-chatasist-session-jwtBind the session to a known customer (see below).
data-chatasist-customer-tokenA token your own backend issues for the signed-in customer, forwarded to your MCP server on live lookups (see below).
data-chatasist-hide-launcherHide the default launcher button.
data-chatasist-triggerCSS selector for custom elements that open the widget.
data-chatasist-trigger-eventEvent name to open the widget programmatically.
data-chatasist-open-viaReflects how the panel was last opened.

Interface language. data-chatasist-lang translates the whole widget interface — launcher, buttons, placeholders, tab labels, status text, and error messages — into Azerbaijani (az), English (en), Russian (ru), or Turkish (tr). Any other value falls back to English for the interface. The same language is used for the AI agent's opening greeting and its replies, so the conversation matches what the visitor sees. When you omit data-chatasist-lang, the widget and the greeting both default to English. Set it to the visitor's language (for example from your site's locale) to localize the chat end to end.

Authenticating a known customer#

For anonymous visitors no extra setup is needed. To bind the session to a customer you already know, supply a session JWT:

  • Short-lived: POST /api/v1/widget/session-jwt
  • Long-lived (cwt_): POST /api/v1/customers/{id}/widget-embed-token

Pass the result as data-chatasist-session-jwt="…", or set window.__CHATASIST = { widgetId, baseUrl, sessionJwt } before embed.js loads. If the JWT only becomes available after login, set the attribute then — the embed watches the script tag and rebinds automatically without a page reload. You can also call window.ChatasistWidget.setSessionJwt('cwt_…').

Issue widget tokens via the API

Authenticate, then mint per-customer widget embed tokens.

Passing a customer token to your MCP server#

If you connect your own data through an MCP server, you can have the AI agent's live lookups carry a token your backend understands — so your server authenticates the customer itself instead of trusting an identifier alone.

Issue that token however your app already does (a signed JWT, a session token — whatever your MCP server validates) and pass it as:

<script
  src="https://widget.chatasist.com/embed.js"
  data-chatasist="YOUR_CHANNEL_UUID"
  data-chatasist-customer-token="the-token-your-backend-issued"
></script>

or window.__CHATASIST = { widgetId, customerToken: '…' } before embed.js loads.

The widget sends it to Chatasist as the X-Customer-Token header, and Chatasist forwards it unchanged to your MCP server under the same header on every tools/call for that customer — alongside the server's own credential, not in place of it. Your server reads X-Customer-Token, validates it, and scopes the lookup to that customer.

The visitor's country#

Chatasist also forwards where the visitor is browsing from, as Cloudflare resolved it on the widget request, under the X-User-Country header — a two-letter ISO code such as AZ. Nothing is needed on your side to send it.

Use it to answer for the right region: price in the local currency, hide what you cannot ship there, or pick a warehouse. The header is simply absent when the country could not be resolved (Cloudflare's XX) or the visitor came through Tor (T1), so treat a missing header as "unknown", never as a default country.

Refreshing the token before it expires#

Customer tokens are usually short-lived. When yours is about to expire, mint a fresh one and hand it to the widget — no reload, and the open conversation is untouched:

window.ChatasistWidget.setCustomerToken('the-freshly-minted-token');

Every request the widget makes after that carries the new token. Pass null to clear it.

If a token does expire first, nothing breaks: your MCP server answers 401, Chatasist repeats the lookup without the token, and the customer is asked to confirm by code instead. Refreshing on time simply spares them that step.

This is separate from data-chatasist-session-jwt. The session JWT tells Chatasist which customer this is; the customer token is an opaque value Chatasist never inspects and only relays to your MCP server. Send whichever you need — or both.