How to listen Salesforce Chat End Event from Experience Cloud Site?

How to listen Salesforce Chat End Event from Experience Cloud Site?

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.

If you want to listen Salesforce Chat End Event from your external website instead of Salesforce Experience Cloud Site, then check the following.

The following steps are for listening Salesforce Chat End or Close events from the Experience Cloud Site.

Steps:

1. Create a JavaScript file(extension of the file should be js) with the following Chat Snippet Code.

window._snapinsSnippetSettingsFile = ( function() {

    console.log( 
		"Static Resource file loaded" 
	);

	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' 
		);

	} );
    
})();

2. Upload the JavaScript file in Salesforce Static Resource.

3. Make a not of the Static Resource Name. In the Experience Cloud Site Builder, update the “Snippet Settings File” with the Static Resource Name in the Embedded Service Chat component properties.

Leave a Reply