Context Events in Enhanced Web Chat v2
This method of passing context events is only available in Enhanced Web Chat v2. For more information, see Enhanced Chat in Salesforce Help.
The optional utilAPI method enables you to pass information like the current page or a recent search to the agent. See the reference for setSessionContext.
The input parameter to setSessionContext must follow the exact schema shown in the example. Valid variables are limited to currentPage and search; both are optional.
Call embeddedservice_bootstrap.utilAPI.setSessionContext only after onEmbeddedMessagingReady fires; do not call it in initEmbeddedMessaging.
You can set context variables and send a user utterance in a single call using sendTextMessage. This ensures the context is available immediately when the message is processed by the agent.
You can access the context variables sent from the client in your topic and action instructions using $AgentContext. For example, use {!$AgentContext.value.currentPage} to reference the current page in an action input.
You can use event handlers in both setSessionContext() and sendTextMessage() methods to perform actions after the operation completes.
thenevent handler— If the context is set successfully, you can use this handler to, for example, update the UI or record analytics.catchevent handler— If there's an error setting the context, you can use this handler to, for example, retry or display an error message.finallyevent handler— This handler runs after the attempt to set context completes, whether it succeeds or fails. Use this handler to run any clean-up actions.