Customer Agent

JavaScript SDK

Methods available on the CustomerAgent browser singleton.

Command Function

CustomerAgent(command, ...args)

The command function also exposes method properties such as CustomerAgent.boot(...) and named ESM exports such as boot(...).

Methods

MethodSignatureReturnsEffect
boot(options: CustomerAgentOptions)CustomerAgentWidgetInitializes the Messenger singleton.
update(options: Partial<CustomerAgentOptions>)voidApplies public option updates.
identify(user: WidgetUser)voidUpdates visitor identity.
setContext(context: WidgetContextJson, options?: SetContextOptions)voidMerges or replaces user context.
show(target?: CustomerAgentTarget)voidOpens the Messenger target.
hide()voidCloses the Messenger.
toggle(target?: CustomerAgentTarget)voidToggles Messenger visibility.
openEntry(entryId: string)voidOpens a conversation entry id.
on(eventName: CustomerAgentEventName, handler)() => voidSubscribes to an SDK event.
getState()CustomerAgentState | nullReads current singleton state.
getSession()Promise<{ conversationId: string } | null>Ensures the support session.
getSupportState()CustomerAgentSupportState | nullReads support session state.
getInterviewState()CustomerAgentInterviewState | nullReads interview state.
getInterviewSession()CustomerAgentInterviewSession | nullReads the active interview session.
ensureInvitation()Promise<{ invitationId: string } | null>Creates or returns an invitation id.
startInvitation(invitationId: string)Promise<{ entryId: string; sessionId: string } | null>Starts an interview session.
chooseInvitation(invitationId: string, choice: "close" | "later")Promise<void>Records an invitation choice.
sendInterviewMessage(content: string)Promise<void>Sends an active interview message.
loadInterviewReward(sessionId?: string)Promise<unknown>Loads interview reward data.
shutdown()voidRemoves the Messenger singleton.

Method Details

boot

Initializes the Messenger singleton from CustomerAgentOptions and returns a CustomerAgentWidget controller for that instance. Calling boot again replaces the previous singleton.

update

Applies public option changes to the current singleton. The argument is Partial<CustomerAgentOptions>. context is accepted as an option field, but setContext is the dedicated context method. Updating mobile.mode recalculates the Messenger presentation; when an open non-mounted Messenger leaves fullscreen presentation, host page scrolling is restored.

identify

Updates visitor identity from a WidgetUser. Identity fields are also included in conversation context.

setContext

Updates WidgetContextJson. By default, plain object fields merge with existing context. Passing { merge: false } replaces the existing context object. Passing { ready } updates the context readiness flag.

show, hide, toggle, openEntry

show(target) opens the Messenger. hide() closes it. toggle(target) switches visibility and updates the target when one is provided. openEntry(entryId) opens a specific conversation entry. See Support and interview sessions for target shapes.

on

Subscribes a handler to a CustomerAgentEventName. The return value removes that handler. A widget.ready handler subscribed after readiness is emitted receives a replayed ready event.

getState

Returns the current CustomerAgentState, or null when no singleton exists.

getSession and getSupportState

getSession() ensures the support conversation session and resolves { conversationId }. getSupportState() reads the support state without starting a session. See Support state.

Interview methods

getInterviewState() reads interview availability/session state. getInterviewSession() returns the active interview session snapshot or null. ensureInvitation(), startInvitation(...), chooseInvitation(...), sendInterviewMessage(...), and loadInterviewReward(...) control the interview session surface. See Interview methods.

shutdown

Removes the current Messenger singleton.

Commands

CommandArgumentsReturn
"boot"CustomerAgentOptionsCustomerAgentWidget
"update"Partial<CustomerAgentOptions>void
"identify"WidgetUservoid
"setContext"WidgetContextJson, optional SetContextOptionsvoid
"show"Optional CustomerAgentTargetvoid
"hide"Nonevoid
"toggle"Optional CustomerAgentTargetvoid
"openEntry"stringvoid
"on"CustomerAgentEventName, handler() => void
"getState"NoneCustomerAgentState | null
"getSession"NonePromise<{ conversationId: string } | null>
"getSupportState"NoneCustomerAgentSupportState | null
"getInterviewState"NoneCustomerAgentInterviewState | null
"getInterviewSession"NoneCustomerAgentInterviewSession | null
"ensureInvitation"NonePromise<{ invitationId: string } | null>
"startInvitation"stringPromise<{ entryId: string; sessionId: string } | null>
"chooseInvitation"string, "close" | "later"Promise<void>
"sendInterviewMessage"stringPromise<void>
"loadInterviewReward"Optional stringPromise<unknown>
"shutdown"Nonevoid

CustomerAgentWidget

boot returns a controller for the current Messenger instance.

Top-level state reads return null when no singleton exists. Widget controller methods are typed as instance methods; reads that require an initialized singleton throw CustomerAgent widget is not initialized. if the controller cannot resolve one. getInterviewSession() can return null when the widget is initialized and no interview session is active.

MethodSignatureEffect
chooseInvitation(invitationId: string, choice: "close" | "later") => Promise<void>Records an invitation choice.
ensureInvitation() => Promise<{ invitationId: string }>Creates or returns an invitation id.
getInterviewState() => CustomerAgentInterviewStateReads interview state.
getInterviewSession() => CustomerAgentInterviewSession | nullReads active interview session.
getSession() => Promise<{ conversationId: string }>Resolves the support session.
getState() => CustomerAgentStateReads instance state.
getSupportState() => CustomerAgentSupportStateReads support state.
hide() => voidCloses the Messenger.
identify(user: WidgetUser) => voidUpdates visitor identity.
on(eventName: CustomerAgentEventName, handler) => () => voidSubscribes to an event.
openEntry(entryId: string) => voidOpens a conversation entry id.
loadInterviewReward(sessionId?: string) => Promise<unknown>Loads interview reward data.
sendInterviewMessage(content: string) => Promise<void>Sends an active interview message.
setContext(context: WidgetContextJson, options?: SetContextOptions) => voidUpdates user context.
show(target?: CustomerAgentTarget) => voidOpens the Messenger target.
shutdown() => voidRemoves the Messenger instance.
startInvitation(invitationId: string) => Promise<{ entryId: string; sessionId: string }>Starts an interview session.
toggle(target?: CustomerAgentTarget) => voidToggles Messenger visibility.
update(options: Partial<CustomerAgentOptions>) => voidApplies public option updates.

CustomerAgentState

FieldTypeMeaning
activeEntryIdstring | undefinedActive conversation entry id.
activeTargetCustomerAgentTarget | undefinedActive Messenger target.
appIdstringCustomer Agent app id.
isOpenbooleanMessenger visibility.
isReadybooleanWhether the Messenger can be opened.
interviewCustomerAgentInterviewStateCurrent interview state.
launcher.targetConfiguredbooleanWhether a launcher target was configured.
launcher.targetConnectedbooleanWhether the configured target is connected.
supportCustomerAgentSupportStateCurrent support state.
widgetIdstringRuntime instance id.

On this page