Newer Version Available
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
| Name | Type | Description |
|---|---|---|
| chatKey | String | The chatKey associated with the chat for which to call a function when a custom event takes place. |
| type | String | The name of the custom event you want to listen for. This should match the name of the custom event sent from the chat window. |
| callback | function | JavaScript method called upon completion of the method. |
Sample Code–Visualforce
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page >
18 <apex:includeScript value="/support/console/29.0/integration.js"/>
19 <script type="text/javascript">
20 var eventHandler = function (result) {
21 alert('A new custom event has been received of type ' + result.type + ' and with data: ' + result.data );
22 }
23 //Get the value for 'myChatKey' from the sforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.
24 //These values are for example purposes only
25 var chatKey = 'myChatKey';
26 var type = 'myCustomEventType';
27 sforce.console.chat.onCustomEvent(chatKey, type, eventHandler);
28 </script>
29</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 |
|---|---|---|
| type | String | The 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. |
| data | String | The 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. |
| source | String | The 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. |
| timestamp | Date/Time | The time and date the event was received. |
| success | Boolean | true if firing event was successful; false if firing event wasn’t successful. |