sendCustomEvent()

Sends a custom event to the client-side chat window for a chat with a specific chat key. Available in API version 29.0 or later.

Syntax 

1sforce.console.chat.sendCustomEvent(chatKey:String, type:String, data:String, callback:Function)

Arguments 

NameTypeDescription
chatKeyStringThe chatKey associated with the chat to which to send a custom event.
typeStringThe name of the custom event you want to send to the chat window.
dataStringAdditional data you want to send to the chat window along with the custom event.
callbackfunctionJavaScript method called upon completion of the method.

Sample Code–Visualforce 

1<apex:page >
2    <apex:includeScript value="/support/console/68.0/integration.js"/>
3    <a href="#" onClick="testSendCustomEvent();">Send Custom Event</a> 
4
5    <script type="text/javascript">
6
7        function testSendCustomEvent() {
8            //Get the value for 'myChatKey'from the sforce.console.chat.getDetailsByPrimaryTabId() or other chat methods. 
9            //These values are for example purposes only
10            var chatKey = 'myChatKey';
11            var type = 'myCustomEventType'
12            var data = 'myCustomEventData'
13            sforce.console.chat.sendCustomEvent(chatKey, type, data, sendCustomEventSuccess);
14        }
15        
16        function sendCustomEventSuccess(result) {
17            //Report whether sending the custom event was successful
18            if (result.success == true) {
19                alert('The customEvent has been sent');
20            } else {
21                alert('Sending the customEvent was not successful');
22            }
23        };
24    
25    </script>
26</apex:page>

Response 

This method is asynchronous so it returns its response in an object in a callback method. The response object contains the following properties:

NameTypeDescription
successBooleantrue if sending the custom event was successful; false if sending the custom event wasn’t successful.