Skip to content

Widget API

Programmatic control of the widget from your website's JavaScript. Everything under window.adaptcx (the current global name — see note below).

Contents

  • init — bootstrapping the widget
  • Methods — every method available
  • Events — event listeners
  • Context — passing page context to bots

Overview

The widget attaches to window.adaptcx at load time. Every interaction with the widget from your site's JavaScript happens through this global.

javascript
window.adaptcx.init({ deploymentKey: 'dep_xxx' });
window.adaptcx.on('message', (data) => console.log('New message:', data));
window.adaptcx.sendMessage('Hello');
window.adaptcx.open();

Type

typescript
interface AdaptCXAPI {
  init: (config: WidgetConfig) => void
  open: () => void
  close: () => void
  toggle: () => void
  sendMessage: (message: string) => void
  toggleFullscreen: () => void
  endSession: () => void
  on: (event: string, callback: EventCallback) => void
  off: (event: string, callback: EventCallback) => void
  destroy: () => void
  setContext: (context: PageContext) => void
  getContext: () => PageContext | null
}

Async loading

If the widget script loads asynchronously, calls made before it loads are queued and replayed:

html
<script>
  window.adaptcxQueue = window.adaptcxQueue || [];
  window.adaptcxQueue.push(['init', { deploymentKey: 'dep_xxx' }]);
  window.adaptcxQueue.push(['setContext', { page: 'checkout' }]);
</script>
<script async src="https://widget.<your-org>.<env>.adaptcx.ai/widget.iife.js"></script>

Once the widget loads, it processes the queue in order.

Backward compatibility with window.omnibot

window.adaptcx is the canonical global. window.omnibot continues to work as a backward-compat alias — both names point at the same object, so every method behaves identically on either global.

Existing customer embeds using window.omnibot.init(...) don't need to be updated. New embeds should use window.adaptcx.* (that's what all docs + generated snippets now emit).

See also

AdaptCX — product documentation