Widget JavaScript API
The objects, functions, messages and events the Botello widget exposes to your page.
- Plans
- All plans
- Channels
- Website
Once loaded, the Botello script exposes a small interface to your page: a configuration object, a function to tell it which customer is signed in, a message to close the panel and an event when a visitor leaves their contact details. This page is the complete reference: nothing else is public.
Syncing the widget with your customers’ login, closing the chat from your own interface, measuring leads in your analytics tools.
Before you start
- The widget is installed: see Embed code and options.
- For customer identity, verified visitors are enabled for your workspace: see Verified visitors.
Overview
| Item | Type | Direction | Purpose |
|---|---|---|---|
window.BotelloSettings | object | page → widget | Configuration read once, when the script loads |
window.Botello.identify(token) | function | page → widget | Set or clear the signed-in customer’s identity, at any time |
"botello-close-widget" | postMessage message | page → widget | Close the panel if it is open |
botello:lead | DOM event on window | widget → page | A visitor left their contact details |
window.BotelloSettings
An object you define before the script tag. It is read only once, when the script runs: changing it afterwards has no effect (use Botello.identify).
Prop
Type
<script>
window.BotelloSettings = { identityToken: "<?= $identityToken ?>" };
</script>
<script src="https://admin.botello.ch/widget.js" data-project-id="YOUR-CHATBOT-ID"></script>window.Botello.identify(token)
Gives the widget the customer’s identity token, or clears it. Available as soon as the script has run, even before the bubble is displayed and even if the assistant is disabled: an early call never throws.
Prop
Type
- Return value: none (
undefined). - The token is passed to the chat iframe via
postMessage, only to Botello’s origin, never in a URL. It then accompanies every visitor message. - An invalid token shows no error to the visitor: it is simply treated as unverified. To find out why a token is rejected, use the Check tool (see Verified visitors).
// After a successful login: fetch a fresh token from YOUR server.
async function onLogin() {
const { identityToken } = await fetch('/api/botello-token', { credentials: 'include' }).then((r) => r.json());
window.Botello?.identify(identityToken);
}
// On logout.
function onLogout() {
window.Botello?.identify(null);
}Call identify after the script has loaded
The script creates window.Botello.identify when it runs. Before that, the function does not exist: use window.Botello?.identify(…), or pass the token through window.BotelloSettings if the customer is already signed in at load time.
Close the panel
Send the text message "botello-close-widget" to your own window. If the panel is open, it closes; otherwise nothing happens.
window.postMessage('botello-close-widget', '*');Useful for example when you open your own modal (cart, login) and want to free up the screen.
There is no public function to open the panel or to send a message on the visitor’s behalf.
The botello:lead event
When a visitor leaves their contact details in the widget, the script dispatches a CustomEvent named botello:lead on window. It contains no personal data: only where the contact details were left.
Prop
Type
window.addEventListener('botello:lead', (event) => {
console.log('Botello lead from', event.detail.source);
});The event is only dispatched by Botello’s own iframe: another page or script cannot fake it via postMessage. Examples for GA4, Google Tag Manager and Meta Pixel: see Analytics events.
Internal messages
The script and the iframe exchange other messages (botello-page-context, botello-identity, botello-toggle-ping, Shopify cart…). They are internal, may change without notice, and must not be used or faked by your page.
Troubleshooting
| What you see | Likely cause | Fix |
|---|---|---|
TypeError: window.Botello is undefined | identify called before the script loaded | Use window.Botello?.identify(…) after loading, or window.BotelloSettings |
| The customer stays unverified | Token missing, expired, or signed with another secret | Test the token with the Check tool |
BotelloSettings changed but nothing happens | The object is only read at load time | Call window.Botello.identify(token) |
botello:lead never fires | Listener added on document instead of window, or order-tracking form | Listen on window. The order-tracking form does not count as a lead |