Advanced options & JavaScript API

Customize script tag attributes or control the widget programmatically with init().

Advanced options

OptionValueDefaultNotes
botIdstringrequiredBot ID. Also accepts data-bot-id on the script tag. An ID passed to init() takes priority.
scriptThe <script> elementnonePass script: this in manual init() to apply the data attributes below. Without it, data attributes are ignored.
apiBaseAPI origin, without /api/v1data-api-base, then build defaultOnly needed when the widget should use a different API origin.
open (alias defaultOpen)booleanfalseStart with the chat panel open.
onOpenChange(open)functionnoneCalled when the panel opens or closes. Manual init() only.
containerDOM element; selector and ID strings are not supportednone (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.

AttributeValue
data-primary-color#RGB or #RRGGBB; invalid values use #0f766e.
data-positionleft or right (default: right).
data-greetingText, maximum 200 characters.
data-bot-nameText, 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();