Widget JS API

Once the embed script has loaded, it exposes a small global object you can call from your own code. This is how you integrate the widget with your own UI (custom buttons, SPA navigation, language toggles, personalized context).

window.aiSupportWidget

interface AiSupportWidget {
  open(): void;
  close(): void;
  toggle(): void;
  reset(): void;
  isOpen(): boolean;
  setLanguage(lang: 'EN' | 'PT'): void;
  setUserData(data: Record<string, unknown>): void;
}

open()

Opens the chat if it's closed. No-op if already open.

document.getElementById('my-help-button').addEventListener('click', () => {
  window.aiSupportWidget.open();
});

close()

Closes the chat if it's open.

toggle()

Open if closed, close if open.

reset()

Reloads the iframe to a fresh chat — new conversation, new session. Useful when the user logs out or switches accounts.

isOpen()

Returns true if the chat panel is currently visible.

setLanguage(lang)

Switches the widget language at runtime. Accepts 'EN' or 'PT'. This reloads the iframe under the new language. See Languages.

setUserData(data)

Sends arbitrary structured data into the chat so the AI can use it as context (see below).

window.aiSupportWidgetData

You can also set a global variable before the script loads; the widget will pick it up on iframe load and send it to the chat:

<script>
  window.aiSupportWidgetData = {
    name: 'Jane Doe',
    email: '[email protected]',
    plan: 'Pro',
    lastOrder: { id: 'ORD-1234', status: 'shipped' }
  };
</script>
<script
  src="https://lxaira.com/api/widget/script?projectId=YOUR_PROJECT_ID"
  async
></script>

After the widget is loaded you can update it at any time with:

window.aiSupportWidget.setUserData({
  name: 'Jane Doe',
  email: '[email protected]',
  plan: 'Pro',
  lastOrder: { id: 'ORD-1234', status: 'shipped' }
});

The widget delivers the object to the iframe via postMessage with type WIDGET_USER_DATA. The AI has access to it as context for answering questions like "what plan am I on?" or "what's the status of my last order?" — without ever hitting your backend.

window.aiSupportWidgetLang

If you want to pre-set the language without calling setLanguage, assign a global before the script loads:

<script>window.aiSupportWidgetLang = 'PT';</script>

Accepted values: 'EN', 'PT'.

Custom trigger button (no floating button)

Set the widget trigger to custom under Settings → Widget → Trigger. The floating button won't render. Then wire your own button to window.aiSupportWidget.open().

Widget JS API — Docs — Aira