ansa object is automatically exposed on the window object. This API lets you programmatically control the widget — open/close the chat, show forms, identify users, and trigger automations.
Basic Setup
Add the embed script to your page:ansa object is available immediately after the script loads:
API Reference
ansa.open(message?)
Opens the chat widget. Optionally pre-fill the input with a message.
ansa.close()
Closes the chat widget.
ansa.toggle()
Toggles the widget between open and closed states.
ansa.isOpen()
Returns whether the widget is currently open.
boolean
ansa.isReady()
Returns whether the widget has finished initializing.
boolean
ansa.showBubbles(messages, duration?)
Shows notification bubble(s) near the widget button. Great for proactive engagement.
ansa.hideBubbles()
Hides any visible notification bubbles.
ansa.showForm(form, options?)
Displays a form in the widget. Can reference a server-side form by name or provide a client-side schema.
See Triggering Forms for complete form schema reference.
ansa.trigger(eventName, data?)
Fires a custom event that can trigger automations.
See Custom Events for setting up event-based triggers.
ansa.identify(identity)
Sets the current user’s identity. This personalizes the chat experience and pre-fills forms.
See Identity for personalization use cases.
ansa.resetUser()
Clears the current user identity (e.g., on logout).
ansa.getVisitorId()
Returns the anonymous visitor ID (persisted in localStorage).
string — Unique visitor identifier
ansa.registerFormSchema(schemas)
Registers client-side form schema providers. Forms are generated dynamically based on context.
The schema provider receives:
args: Arguments passed from the agent tool calluser: User context ({ visitorId, userId?, userMetadata?, conversationId? })
ansa.hasFormSchema(name)
Checks if a form schema provider is registered.
boolean
ansa.registerFormHandler(name, handler) Legacy
Registers a form submission handler for server-side forms.
ansa.unregisterFormHandler(name) Legacy
Removes a registered form handler.
ansa.hasFormHandler(name) Legacy
Checks if a form handler is registered.
Configuration
Script Parameters
Configure the widget via URL parameters:Window Config
Alternatively, set config before loading the script:Common Patterns
Open Chat on Button Click
Open Chat with Context
Identify User on Login
Proactive Engagement
Custom Chat Trigger
React Integration
Next Steps
Triggering Forms
Display and handle forms programmatically
Identity
Personalize conversations with user data