Skip to Content
GuidesDevelopersResources
Website and widget

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.

Best for

Syncing the widget with your customers’ login, closing the chat from your own interface, measuring leads in your analytics tools.

Before you start

Overview

ItemTypeDirectionPurpose
window.BotelloSettingsobjectpage → widgetConfiguration read once, when the script loads
window.Botello.identify(token)functionpage → widgetSet or clear the signed-in customer’s identity, at any time
"botello-close-widget"postMessage messagepage → widgetClose the panel if it is open
botello:leadDOM event on windowwidget → pageA 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

Customer already signed in when the page loads
<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).
Single-page app: login and logout
// 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 seeLikely causeFix
TypeError: window.Botello is undefinedidentify called before the script loadedUse window.Botello?.identify(…) after loading, or window.BotelloSettings
The customer stays unverifiedToken missing, expired, or signed with another secretTest the token with the Check tool
BotelloSettings changed but nothing happensThe object is only read at load timeCall window.Botello.identify(token)
botello:lead never firesListener added on document instead of window, or order-tracking formListen on window. The order-tracking form does not count as a lead

Frequently asked questions

Learn more

Was this page helpful?
Checked against the product on 14 November 2026 Suggest a fix

On this page