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.

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

1<apex:page >
2    <apex:includeScript value="/support/console/68.0/integration.js"/>
3    <a href="#" onClick="testSendMessage();">Send Message</a> 
4
5    <script type="text/javascript">
6
7        function testSendMessage() {
8            //Get the value for 'myChatKey'from the sforce.console.chat.getDetailsByPrimaryTabId() or other chat methods. 
9            //These values are for example purposes only
10            var chatKey = 'myChatKey';
11            var text ='This is sample text to send as a message';
12            sforce.console.chat.sendMessage(chatKey, text, sendMessageSuccess);
13        }
14        
15        function sendMessageSuccess(result) {
16            //Report whether getting the chat log was successful
17            if (result.success == true) {
18                alert('Message Sent');
19            } else {
20                alert('Sending the message was not successful');
21            }
22        };
23    
24
25    </script>
26</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
success Boolean true if sending the message was successful; false if sending the message wasn’t successful.