SDK & widget reference
Every attribute the script tag reads and the two JavaScript methods the widget exposes.
Script attributes
The widget reads these attributes from the script tag that loads it. Start from the snippet in your dashboard's API Key page, which sets them for you.
| Attribute | Required | What it does |
|---|---|---|
| data-key | Required | Your widget key (pk_live_…). Without it the widget logs a warning in the browser console and does not load. |
| data-api | Optional | The repliyo API base URL. Included in the dashboard snippet, so copy the snippet rather than setting this by hand. |
| data-ws | Optional | The repliyo WebSocket URL. Also included in the dashboard snippet. |
| data-user-token | Optional | A signed token identifying the logged-in visitor. See Authentication. |
JavaScript methods
Once loaded, the widget exposes window.repliyo with two methods:
- •
identify(token)— tells the widget who the visitor is, using a signed token from your server, and reconnects as that user. - •
reset()— drops the identity and reconnects anonymously. Call it on logout.
Example
// After the visitor logs in (token signed on your server)
window.repliyo.identify(userToken);
// After the visitor logs out
window.repliyo.reset();The widget connects to repliyo the first time the chat is opened, so calling identify() before then is always safe. How to create the token is covered in Authentication.
In the browser
- •The widget is a single dependency-free file, loaded asynchronously so it doesn’t block your page.
- •It stores a visitor’s session ID in localStorage so a conversation continues across page loads.
- •Messages are rendered as Markdown, with all visitor and model text HTML-escaped first.
- •Answers drawn from your documents show their source documents under the reply.
- •If your site sets a Content-Security-Policy, it must allow the widget script and connections to the repliyo API and WebSocket URLs from your snippet.
Next
Return to the docs overview, or see how repliyo handles data on the Security page.
