Skip to main content
embedWidget() returns a WidgetInstance with methods to control the agent programmatically. This lets you trigger conversations from buttons, links, application events, or any other logic in your app.

Methods

widget.open()

Opens the widget and makes it visible.

widget.close()

Closes the widget. The agent stays loaded in the background — reopening is instant.

widget.destroy()

Removes the widget from the DOM entirely and cleans up all resources. After calling destroy(), the instance cannot be reopened.

widget.sendMessage(message, options?)

Sends a user message to the agent. If the widget is closed, it opens automatically.

widget.setInput(message, options?)

Prefills the chat input bar without sending. The widget opens (if closed) and the user can review, edit, and submit the message themselves.

widget.preload()

Starts loading the agent iframe in the background so it’s ready instantly when the user opens the widget. Useful when you didn’t set preload: true in the initial options but want to trigger it based on user behavior.

Examples

Trigger from buttons

Preload on scroll

Load the agent in the background as the user scrolls near the bottom of the page:

Open after a delay

Clean up on navigation (SPA)

In a single-page application, destroy the widget when the user navigates away from the page:

Pending Messages

If you call sendMessage() or setInput() before the agent iframe has finished loading, the action is queued and executed automatically once the iframe is ready. You don’t need to wait for a “loaded” event.