Messenger methods
UI controls and state on a mounted CustomerAgentWidget.
mountWidget(options) from @customer-agent/sdk/widget attaches the Messenger and
returns Promise<CustomerAgentWidget>. A supplied client is required. Session and message actions
belong to that client; see Headless client.
Methods
| Method | Arguments | Returns | Effect |
|---|---|---|---|
getState | None | CustomerAgentWidgetState | Reads this mount's cached UI snapshot. |
subscribe | listener: () => void | () => void | Observes UI snapshot changes; returns an unsubscribe function. |
on | Event name, handler | () => void | Observes widget events and business events forwarded from its client. |
show | Optional CustomerAgentTarget | void | Opens the panel and selects a target when supplied. |
hide | None | void | Closes the panel. |
toggle | Optional CustomerAgentTarget | void | Toggles the panel, updating the target when supplied. |
update | Partial presentation options | void | Updates this mount's appearance and launcher. |
unmount | None | void | Removes this instance and its listeners, restoring host attributes and scroll state. |
UI controls reject use after unmount by throwing an error. unmount() is idempotent; calling it
again cannot remove a later Messenger. The client keeps running. getState() remains readable
with isReady: false, isOpen: false, and a cleared launcher anchor after unmount.
The mounting promise confirms attachment. Shell readiness is published separately in UI state and
widget.ready; a ready handler registered after readiness receives one asynchronous replay.
The conversation panel is lazy, and widget readiness does not mean a support session has started.
UI State
| Field | Type | Meaning |
|---|---|---|
appId, widgetId | string | Identifiers from the supplied client. |
isOpen | boolean | Panel visibility. |
isReady | boolean | The minimal Messenger shell is ready. |
activeTarget | Optional CustomerAgentTarget | Current one-shot opening target. |
activeEntryId | Optional string | Current conversation route entry. |
launcher.targetConfigured | boolean | A custom target was configured. |
launcher.targetConnected | boolean | The custom target is currently resolved. |
launcher.anchor | HTMLElement | null | The connected custom target or SDK-created launcher host. |
Business state is available from client.getState(), not copied into the widget snapshot. Closing
the panel clears its one-shot target and retains navigation memory for a later trigger reopen.
openOnInit opens during mounting without emitting widget.opened.
Updates
update accepts presentation fields from Messenger options. A different
client or mount requires a new mounting call. openOnInit applies only at mount time. Updating
launcher replaces that object: include its target when retaining a custom target while changing
placement or offset. header, theme, and other nested presentation objects are replaced rather
than deeply merged.
A non-embedded mobile fullscreen Messenger locks host scrolling while open. It restores scrolling when hidden, unmounted, or changed to bottom-sheet presentation. Embedded Messengers do not lock the host document.
Targets
See Support and interview sessions for supported targets. Calling a client business action does not implicitly open the Messenger; use its widget handle to select and show the resulting conversation.
show({ type: "support", scene: "retention" }) opens the loading panel while its client creates
or restores the requested scene. On creation failure, the panel selects ordinary support. The
method returns void; request status is observable through the client's scene state. Hiding,
unmounting or selecting another target prevents a late failure from overriding that navigation.