How to listen Salesforce Chat Close Event?

How to listen Salesforce Chat Close Event?

Salesforce Chats can be ended by

  1. Agents
  2. BOTs
  3. Visitors

embedded_svc.addEventHandler() can be used for listening onChatEndedByChasitor, onChatEndedByAgent and onChatEndedByChatbot events.

Sample Code:

embedded_svc.addEventHandler( 
    "onChatEndedByChasitor", 
    function( data ) {
    
    console.log( 
        'Chat was ended by the Visitor' 
    );

} );
 
embedded_svc.addEventHandler(
    "onChatEndedByAgent", 
    function( data ) {
    
    console.log( 
        'Chat was ended by the Agent' 
    );

} );
 
embedded_svc.addEventHandler(
    "onChatEndedByChatbot", 
    function( data ) {

    console.log( 
        'Chat was ended by the BOT' 
    );

} );

embedded_svc.addEventHandler() should be added before the embedded_svc.init().

Leave a Reply