Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
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
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:
| 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. |