Listen for State Changes and Events
You can add listeners for state changes and events during a chat session and respond accordingly. For instance, when the client ends a session, you can display a dialog to the user.
The legacy chat product is scheduled for retirement on February 14, 2026, and is in maintenance mode until then. During this phase, you can continue to use chat, but we no longer recommend that you implement new chat channels. To avoid service interruptions to your customers, migrate to Messaging for In-App and Web before that date. Messaging offers many of the chat features that you love plus asynchronous conversations that can be picked back up at any time. Learn about chat retirement in Help.
-
Create a
SessionStateListenerimplementation to handle session state changes.In Java:
In Kotlin:
This implementation handles state changes (
onSessionStateChange) and why the session ended (onSessionEnded). For information on other session states and reasons for ending, seeChatSessionStateandChatEndReason. -
Create a
ChatEventListenerimplementation if you want to listen for additional events.This listener isn’t required, but it can be used to listen for events such as: when an agent joins (
agentJoined), when a message is sent (processedOutgoingMessage), when a message is received (didReceiveMessage).In Java:
In Kotlin:
-
Create a
SessionInfoListenerimplementation if you want to get session information.In Java:
In Kotlin:
-
Instantiate your listener instances from your
Applicationclass.In Java:
In Kotlin:
It’s important to have the listener at the
Applicationscope to ensure that the session is trackable throughout the lifetime of the application rather than just within anActivity. -
When you configure and start a session, add the listeners that you implemented. Add the event listener (
ChatEventListener) to the chat UI configuration object. Add the session info listener (SessionInfoListener) and the session state listener (SessionStateListener) to the chat UI client.In Java:
In Kotlin:
See Also