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.
onAgentSend()
Registers a function to call when an agent sends a chat message through the
Salesforce console. This method intercepts the message and occurs before it is sent to the
chat visitor. Available in API version 29.0 or later.
Syntax
1sforce.console.chat.onAgentSend(chatKey:String, callback:Function)Arguments
| Name | Type | Description |
|---|---|---|
| chatKey | String | The chatKey associated with the chat for which to call a function when the agent sends a message. |
| 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 var theMessage = result.content;
6 alert('The agent is attempting to send the following message: ' + result.content);
7 sforce.console.chat.sendMessage(chatKey, theMessage)
8 alert('The following message has been sent: ' + theMessage);
9 }
10 //Get the value for 'myChatKey' from the sforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.
11 //These values are for example purposes only
12 var chatKey = 'myChatKey';
13 sforce.console.chat.onAgentSend(chatKey, eventHandler);
14 </script>
15</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 |
|---|---|---|
| content | String | The text of the agent’s message. |
| name | String | The name of the agent who is attempting to send the message as it appears in the chat log. |
| type | String | The type of message that was received—for example, agent. |
| timestamp | Date/Time | The date and time the agent attempted to send the chat message. |
| success | Boolean | true if firing event was successful; false if firing event wasn’t successful. |