Newer Version Available
sendMessage()
Sends a new chat message from the agent to a chat with a specific chat key. Available in API version 29.0 or
later.
Syntax
1sforce.console.chat.sendMessage(chatKey:String, message:String, callback:Function)Arguments
| Name | Type | Description |
|---|---|---|
| chatKey | String | The chatKey of the chat where the agent’s message is sent. |
| message | String | The message you would like to send from the agent to the customer in a chat. |
| 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 <a href="#" onClick="testSendMessage();">Send Message</a>
20
21 <script type="text/javascript">
22
23 function testSendMessage() {
24 //Get the value for 'myChatKey'from the sforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.
25 //These values are for example purposes only
26 var chatKey = 'myChatKey';
27 var text ='This is sample text to send as a message';
28 sforce.console.chat.sendMessage(chatKey, text, sendMessageSuccess);
29 }
30
31 function sendMessageSuccess(result) {
32 //Report whether getting the chat log was successful
33 if (result.success == true) {
34 alert('Message Sent');
35 } else {
36 alert('Sending the message was not successful');
37 }
38 };
39
40
41 </script>
42</apex:page>