Serves the chat widget as a script to embed on your site. It needs no credentials. The widget itself talks to the API through Start widget chat, Send widget chat message and End widget chat, using the public key from its script tag.
Embed#
<script src="https://api.tried.com.au/widget.js" data-public-key="public_key_c6190cdfff21015a05ac4e386d1158ce" async></script>Script tag attributes#
| Attribute | Required | Description |
|---|---|---|
data-public-key |
Yes | The public key. Without it the widget logs Tried widget: data-public-key is missing to the console and does not render. |
data-title |
No | Header text and button label. Default Chat with us. |
data-color |
No | Button, header and visitor bubble colour. Default #18181b. |
data-api |
No | API base URL. Default: the API's PUBLIC_API_BASE. |
data-recaptcha-site-key |
No | reCAPTCHA v3 site key. Default: RECAPTCHA_SITE_KEY on the API, if set. When there is a site key, the widget loads reCAPTCHA and sends a token with action chat_start when a chat starts. |
data-recaptcha-mock-score |
No | Testing only, used when there is no site key: sends mock:<score> as the token, which a mocked reCAPTCHA check scores as that value. |
What the widget does#
- Adds a round button at the bottom right of the page.
- On the first open, gets a reCAPTCHA token if it has a site key, then calls
POST /public/chat/startwithpublic_keyandrecaptcha_token, and shows any greeting. - Sends each message with
POST /public/chat/{chat_id}/messageand shows the agent's replies. - On
pagehide, ends the chat withnavigator.sendBeacontoPOST /public/chat/{chat_id}/end.
The widget does not send dynamic_variables. To pass them, call Start widget chat from your own UI.
Request#
No parameters.
Example request#
curl "https://api.tried.com.au/widget.js"const res = await fetch("https://api.tried.com.au/widget.js");
const script = await res.text();import requests
script = requests.get("https://api.tried.com.au/widget.js").textResponse#
200 OK with Content-Type: application/javascript and Cache-Control: public, max-age=300. The body is the widget script with the API base URL and the reCAPTCHA site key filled in as defaults.
Errors#
| Status | When |
|---|---|
429 |
Per-IP rate limit exceeded. See Rate limits. |
See Errors for the body format.