Skip to content

Embedding & JavaScript API

The OmniBots widget is loaded with a single script tag and initialized through the omnibot global object. This page covers the full JavaScript API, configuration options, theme system, launcher styling, and info message (teaser bubble) configuration.

Quick Start

Add the widget script to your page and call omnibot.init() with your deployment key:

html
<!-- Load the widget -->
<script src="https://omnibots-widget.web.app/widget.iife.js" defer></script>

<script>
  // Wait for the script to load, then initialize
  window.addEventListener('load', () => {
    omnibot.init({
      deploymentKey: 'your-deployment-key',
      position: 'bottom-right',
      offset: { x: 20, y: 20 },
      zIndex: 9999,
      autoOpen: false,
      metadata: {
        page_label: 'pricing',
        user_tier: 'enterprise'
      }
    });
  });
</script>
imageWebsite with the initialized OmniBots widget showing the launcher button in the bottom-right corner and the chat window open with a welcome message
Widget after initialization on a website

Async Loading

The widget supports queued commands for async script loading. Commands pushed to window.omnibotQueue before the script loads will be processed automatically once the widget initializes.

WidgetConfig

The omnibot.init() method accepts a WidgetConfig object:

PropertyTypeDefaultDescription
deploymentKeystring(required)Unique key identifying the bot deployment
position'bottom-right' | 'bottom-left''bottom-right'Corner of the screen for the widget
offset{ x: number, y: number }{ x: 20, y: 20 }Pixel offset from the corner
zIndexnumber9999CSS z-index for the widget container
autoOpenbooleanfalseAutomatically open the chat window on load
metadataRecord<string, unknown>undefinedInitial page context metadata (see PageContext)

JavaScript API Methods

The omnibot global object exposes the following methods:

Widget Lifecycle

MethodDescription
init(config)Initialize the widget with the given configuration. Logs a warning if called more than once.
destroy()Unmount the widget, remove its DOM container, and clear all event listeners.

Window Control

MethodDescription
open()Open the chat window.
close()Close the chat window.
toggle()Toggle the chat window open or closed.
toggleFullscreen()Toggle between normal and fullscreen mode.

Messaging

MethodDescription
sendMessage(msg)Send a text message on behalf of the user. The message appears in the chat and is sent to the backend.
endSession()End the current conversation session. Clears messages and starts fresh.

Page Context

MethodDescription
setContext(ctx)Update the page context. Merged with existing context and sent to the backend for flow routing decisions.
getContext()Return the current PageContext object, or null if no context is set.

Event Handling

MethodDescription
on(event, callback)Subscribe to a widget event.
off(event, callback)Unsubscribe from a widget event.

Events

Subscribe to events using omnibot.on(event, callback):

Widget Lifecycle

EventPayloadDescription
readynoneWidget has been initialized and is ready
opennoneChat window opened
closenoneChat window closed
fullscreennoneEntered fullscreen mode
fullscreen:exitnoneExited fullscreen mode
connectednoneWebSocket connected to the backend
disconnectednoneWebSocket disconnected
error{ message }An error occurred

Messaging

EventPayloadDescription
message:sent{ message, attachments? }User sent a message. message is the text string, attachments is an optional array of file attachments
message:receivedChatMessageBot or agent message received
conversation:startednoneA new conversation session began
session:endnoneConversation session ended

Escalation & Agents

EventPayloadDescription
escalationEscalationMessageConversation escalated to live agent
escalation:endednoneLive agent escalation ended
escalation:failed{ reason }Escalation attempt failed
agent:joined{ agent_name }A live agent joined the conversation
agent:messageChatMessageLive agent sent a message
queue:update{ position, estimated_wait }Queue position update during escalation

Audio & Video

EventPayloadDescription
audio:configAudioConfigMessageAudio configuration received from backend
audio:receivedaudio dataAudio response received (for TTS)
audio:transcription{ text }Speech-to-text transcription received
tts:playingnoneText-to-speech audio started playing
video:invite{ session_id, room_id }Agent initiated a video call
video:endednoneVideo call ended

Other

EventPayloadDescription
prechat:submitVisitorInfoPre-chat form submitted
feedback:submitted{ message_id, rating }User submitted message feedback
context:updatedPageContextPage context was updated
hub:confighub configHub/department configuration received
hub:agent_switch{ agent }Switched to a different agent in hub mode
custom:event{ event_name }Custom event from popup menu item
js
omnibot.on('message:received', (msg) => {
  console.log('Bot said:', msg.content);
});

omnibot.on('ready', () => {
  console.log('Widget is ready');
});

omnibot.on('message:sent', (data) => {
  console.log('User said:', data.message);
});

PageContext

Page context allows you to pass information about the current page to the bot's flow engine. The flow can use context fields (such as page_label) to route conversations to different branches.

ts
interface PageContext {
  page_label?: string;    // Label for current page (e.g., "billing", "support")
  page_url?: string;      // Current page URL
  page_title?: string;    // Current page title
  user_id?: string;       // Logged-in user ID
  user_tier?: string;     // User subscription/tier level
  [key: string]: unknown; // Any additional custom fields
}

Context can be set at initialization via metadata or updated at any time:

js
// Set at init
omnibot.init({
  deploymentKey: 'abc123',
  metadata: { page_label: 'checkout', user_tier: 'pro' }
});

// Update later (e.g., on SPA route change)
omnibot.setContext({ page_label: 'account-settings' });

Context Merging

Calling setContext() merges the new fields with the existing context. To clear a field, explicitly set it to null.

Theme System

The widget's visual appearance is controlled by the WidgetTheme object, which is configured per-bot in the Operations Portal and delivered to the widget at runtime via WebSocket. The theme maps to over 40 CSS custom properties using the --ob- prefix.

imageAnnotated widget diagram with arrows mapping theme color properties to UI parts: primary_color to header, user_bubble_color to user messages, bot_bubble_color to bot messages, button colors to action buttons
Theme properties mapped to widget UI elements

Core Theme Properties

PropertyTypeDefaultDescription
primary_colorstring'#6366F1'Primary brand color used for header, buttons, and accents
header_backgroundstring(uses primary_color)Header background color
header_text_colorstring'#FFFFFF'Header text color
user_bubble_colorstring(uses primary_color)Background color of user message bubbles
user_text_colorstring'#FFFFFF'Text color inside user bubbles
bot_bubble_colorstring'#FFFFFF'Background color of bot message bubbles
bot_text_colorstring'#1F2937'Text color inside bot bubbles
system_bubble_colorstring'#E5E7EB'Background color of system messages
system_text_colorstring'#6B7280'Text color of system messages

Font Properties

PropertyTypeDefaultDescription
font_familystringSystem font stackFont family for the widget
font_sizestring'14px'Base font size
font_weightstring'400'Base font weight
header_font_sizestring'16px'Header title font size

Bubble Styling

PropertyTypeDefaultDescription
bubble_border_radiusstring'16px'Border radius for message bubbles
bot_bubble_border_colorstringtransparentBorder color for bot bubbles
bot_bubble_border_widthstring'0'Border width for bot bubbles
user_bubble_border_colorstringtransparentBorder color for user bubbles
user_bubble_border_widthstring'0'Border width for user bubbles

Background Colors

PropertyTypeDescription
widget_background_colorstringOverall widget background
message_area_background_colorstringMessage list area background

Button Styling

These properties control quick reply buttons, action buttons, and link buttons:

PropertyTypeDescription
button_background_colorstringBackground color of action buttons
button_text_colorstringText color of action buttons
button_border_colorstringBorder color of action buttons
button_border_radiusstringBorder radius of action buttons
button_hover_background_colorstringHover background for action buttons
button_font_sizestringButton font size
button_font_familystringButton font family
button_font_weightstringButton font weight
button_paddingstringButton padding (default: '8px 14px')
button_text_alignstringText alignment within buttons (default: 'center')
button_margin_topstringTop margin for button container
button_margin_bottomstringBottom margin for button container
button_margin_leftstringLeft margin for button container
button_margin_rightstringRight margin for button container
link_button_background_colorstringBackground for URL buttons
link_button_text_colorstringText color for URL buttons
link_button_border_colorstringBorder color for URL buttons
link_button_border_radiusstringBorder radius for URL buttons

Toolbar

PropertyTypeDescription
toolbar_heightstringCustom height for the widget toolbar/header area

Feedback Button Styling

PropertyTypeDescription
feedback_submit_background_colorstringSubmit button background in feedback form
feedback_submit_text_colorstringSubmit button text color
feedback_submit_border_radiusstringSubmit button border radius
feedback_close_background_colorstringClose button background in feedback form
feedback_close_text_colorstringClose button text color
feedback_close_border_radiusstringClose button border radius

Widget Size

The widget window dimensions are configurable:

PropertyTypeDefaultDescription
widthnumber380Widget width in pixels
heightnumber600Widget height in pixels
max_height_percentnumber90Maximum height as a percentage of the viewport
ts
interface WidgetSizeConfig {
  width?: number;            // Default: 380px
  height?: number;           // Default: 600px
  max_height_percent?: number; // Default: 90% of viewport
}

Launcher Style

The floating launcher button can be customized:

PropertyTypeDefaultDescription
sizenumber60Launcher button diameter in pixels
icon_type'default' | 'custom' | 'text''default'Icon style for the launcher
custom_icon_urlstringundefinedURL to a custom image icon (when icon_type is 'custom')
text_iconstringundefinedText or emoji displayed as the icon (when icon_type is 'text')
edge'left' | 'right''right'Which side of the screen the launcher appears on
offset_xnumber20Horizontal offset from the edge in pixels
offset_ynumber20Vertical offset from the bottom in pixels
border_radiusnumber30Border radius in pixels (half of size = circle)
shadowbooleantrueWhether to show a drop shadow
ts
interface LauncherStyleConfig {
  size?: number;
  icon_type?: 'default' | 'custom' | 'text';
  custom_icon_url?: string;
  text_icon?: string;
  edge?: 'left' | 'right';
  offset_x?: number;
  offset_y?: number;
  border_radius?: number;
  shadow?: boolean;
}

Info Message (Teaser Bubble)

The info message is a teaser bubble that appears above the launcher button to proactively engage visitors. It can display a message and optional action buttons.

PropertyTypeDefaultDescription
enabledbooleanfalseWhether the info message is enabled
messagestringText content of the teaser bubble
delay_secondsnumber3Delay before showing the bubble
show_once_per_sessionbooleantrueOnly show once per browser session
background_colorstringBubble background color
text_colorstringBubble text color
border_radiusstringBubble border radius
max_widthstringMaximum width of the bubble
show_close_buttonbooleanWhether to show a close (X) button
buttonsInfoMessageButton[][]Action buttons inside the bubble
button_background_colorstringButton background color
button_text_colorstringButton text color
button_border_radiusstringButton border radius

Info Message Buttons

Each button in the info message supports three action types:

ActionDescription
open_chatOpens the chat window
urlOpens a URL in a new tab
postbackSends a payload to the bot as if the user typed it
ts
interface InfoMessageButton {
  label: string;
  action: 'open_chat' | 'url' | 'postback';
  url?: string;      // For 'url' action
  payload?: string;   // For 'postback' action
}

Full Example

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>My Website</title>
</head>
<body>
  <h1>Welcome to our site</h1>

  <!-- Load the OmniBots widget -->
  <script src="https://omnibots-widget.web.app/widget.iife.js" defer></script>

  <script>
    window.addEventListener('load', () => {
      // Initialize the widget
      omnibot.init({
        deploymentKey: 'deploy_abc123xyz',
        position: 'bottom-right',
        offset: { x: 24, y: 24 },
        zIndex: 10000,
        autoOpen: false,
        metadata: {
          page_label: 'homepage',
          page_url: window.location.href,
          page_title: document.title,
          user_id: 'usr_12345',
          user_tier: 'premium'
        }
      });

      // Listen for events
      omnibot.on('ready', () => {
        console.log('OmniBots widget is ready');
      });

      omnibot.on('message:sent', (data) => {
        console.log('User said:', data.message);
      });

      omnibot.on('message:received', (msg) => {
        console.log('Received:', msg.content);
      });

      omnibot.on('session:end', () => {
        console.log('Chat session ended');
      });

      // Example: Open chat from a custom button
      document.getElementById('help-btn')?.addEventListener('click', () => {
        omnibot.open();
        omnibot.sendMessage('I need help with my order');
      });

      // Example: Update context on SPA navigation
      window.addEventListener('popstate', () => {
        omnibot.setContext({
          page_url: window.location.href,
          page_title: document.title
        });
      });
    });
  </script>

  <button id="help-btn">Need Help?</button>
</body>
</html>

Deployment Key

Never expose a deployment key for a bot that has access to sensitive internal systems. Deployment keys are public-facing and should be scoped to visitor-facing bots only.

OmniBots AI Bot Platform