Skip to main content
When you embed the Ansa widget using the script tag, a 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:
The 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.
Parameters:

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.
Returns: boolean

ansa.isReady()

Returns whether the widget has finished initializing.
Returns: boolean

ansa.showBubbles(messages, duration?)

Shows notification bubble(s) near the widget button. Great for proactive engagement.
Parameters:

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.
Parameters: See Triggering Forms for complete form schema reference.

ansa.trigger(eventName, data?)

Fires a custom event that can trigger automations.
Parameters: 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.
Parameters: 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).
Returns: string — Unique visitor identifier

ansa.registerFormSchema(schemas)

Registers client-side form schema providers. Forms are generated dynamically based on context.
Parameters: The schema provider receives:
  • args: Arguments passed from the agent tool call
  • user: User context ({ visitorId, userId?, userMetadata?, conversationId? })

ansa.hasFormSchema(name)

Checks if a form schema provider is registered.
Returns: 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