Newer Version Available

This content describes an older version of this product. View Latest

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

Name Type Description
chatKey String The chatKey associated with the chat to which to send a custom event.
type String The name of the custom event you want to send to the chat window.
data String Additional data you want to send to the chat window along with the custom event.
callback function JavaScript method called upon completion of the method.

Sample Code–Visualforce

1<apex:page >
2    <apex:includeScript value="/support/console/53.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:

Name Type Description
success Boolean true if sending the custom event was successful; false if sending the custom event wasn’t successful.