onCustomEvent()

Registers a function to call when a custom event takes place during a chat. Available in API version 29.0 or later.

Syntax 

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

Arguments 

NameTypeDescription
chatKeyStringThe chatKey associated with the chat for which to call a function when a custom event takes place.
typeStringThe name of the custom event you want to listen for. This should match the name of the custom event sent from the chat window.
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    <script type="text/javascript">
4        var eventHandler = function (result) {
5            alert('A new custom event has been received of type ' + result.type + ' and with data: ' + result.data );
6        }
7        //Get the value for 'myChatKey' from the sforce.console.chat.getDetailsByPrimaryTabId() or other chat methods. 
8        //These values are for example purposes only
9        var chatKey = 'myChatKey';
10        var type = 'myCustomEventType';
11        sforce.console.chat.onCustomEvent(chatKey, type, eventHandler);
12    </script>
13</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
typeStringThe type of the custom event that was sent to this chat; corresponds to the type argument of the liveagent.chasitor.sendCustomEvent() method used to send this event from the chat window.
dataStringThe data of the custom event that was sent to this chat; corresponds to the data argument of the liveagent.chasitor.sendCustomEvent() method used to send this event from the chat window.
sourceStringThe source of the custom event that was sent to this chat; corresponds to either the agent or the chat visitor, depending on who triggered the custom event.
timestampDate/TimeThe time and date the event was received.
successBooleantrue if firing event was successful; false if firing event wasn’t successful.