Advanced options & JavaScript API
Customize script tag attributes or control the widget programmatically with init().
Advanced options
| Option | Value | Default | Notes |
|---|---|---|---|
botId | string | required | Bot ID. Also accepts data-bot-id on the script tag. An ID passed to init() takes priority. |
script | The <script> element | none | Pass script: this in manual init() to apply the data attributes below. Without it, data attributes are ignored. |
apiBase | API origin, without /api/v1 | data-api-base, then build default | Only needed when the widget should use a different API origin. |
open (alias defaultOpen) | boolean | false | Start with the chat panel open. |
onOpenChange(open) | function | none | Called when the panel opens or closes. Manual init() only. |
container | DOM element; selector and ID strings are not supported | none (floating widget on the page) | Mounts inside this element and removes its existing children. The launcher still appears. The parent needs position: relative and an explicit height. Initializing the same element again does not apply new options. |
Callbacks such as onOpenChange work only with manual init(), not with the <script> tag install.
Data attributes
These attributes override dashboard settings.
| Attribute | Value |
|---|---|
data-primary-color | #RGB or #RRGGBB; invalid values use #0f766e. |
data-position | left or right (default: right). |
data-greeting | Text, maximum 200 characters. |
data-bot-name | Text, maximum 40 characters. |
<script src="YOUR_WIDGET_URL" defer data-bot-id="YOUR_BOT_ID" data-primary-color="#0F766E" data-greeting="Hello!"></script>JavaScript API
ChatbotWidget.init(options) returns a Promise that resolves to a widget instance, or null if setup fails (it never throws). Always check the result.
open(): Open the chat panel.close(): Close the chat panel.resetChat(): Clear the visitor's local chat history. Nothing is deleted from the backend.destroy(): Remove the widget, for example on an SPA route change.
const widget = await window.ChatbotWidget.init({ script: document.currentScript, botId: 'YOUR_BOT_ID' });
if (widget) widget.open();