Reset Chat when Agent ends Salesforce Enhanced Chat Session
Salesforce Enhanced Chat sessions persist asynchronously, causing UX challenges when agents end chats but the chat window stays active for users. This leads to users unknowingly starting new sessions when typing after an agent ended the conversation. A practical solution involves using a JavaScript event listener on the embedded messaging status to detect when the agent ends the chat and then clearing the session via the userVerificationAPI to reset the chat on the client side. The article provides sample code and advises replacing blocking alerts with custom UI and properly handling the widget post-clear to improve user experience.
- Use onEmbeddedMessagingSessionStatusUpdate event to monitor chat session state changes.
- Clear chat session client-side with embeddedservice_bootstrap.userVerificationAPI.clearSession() when agent ends chat.
- Replace window.alert with custom UI notifications for better UX after session reset.
- Remove or conditionally disable console logging in production to protect session data.
- Consider widget state handling post-clear to avoid immediate new session starts by users.
How to Reset the Chat When an Agent Ends a Salesforce Enhanced Chat Session? With the transition from legacy Live Agent to Salesforce Enhanced Chat (also known as Messaging for In-App and Web, or MIAW), developers and architects have access to a much more robust, asynchronous messaging framework. However, this asynchronous nature introduces new UX challenges that require custom JavaScript handling to ensure a smooth customer journey. One of the most common challenges is managing the session state when a support agent formally closes the conversation. The Problem: The Asynchronous Disconnect In Salesforce Enhanced Chat, messaging sessions are designed to be persistent. When an agent ends the conversation in the Service Console, the Messaging Session is immediately closed on the agent’s side, and the Omni-Channel capacity is freed up. However, on the user side, the chat widget remains active.