setAgentInput()

Sets the string of text in the agent’s text input area in the chat log of a chat with a specific chat key.Available in API version 29.0 or later.

Syntax 

1sforce.console.chat.setAgentInput(chatKey:String, text:String, callback:Function)

Arguments 

NameTypeDescription
chatKeyStringThe chatKey associated with the chat for which to set the agent’s input text.
textStringThe string of text which you want to set into an agent’s input.
callbackfunctionJavaScript 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="testSetAgentInput();">Set Agent Input</a> 
4
5    <script type="text/javascript">
6
7        function testSetAgentInput() {
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 example text to set the agent input'
12            sforce.console.chat.setAgentInput(chatKey, text, setAgentInputSuccess);
13        }
14        
15        function setAgentInputSuccess(result) {
16            //Report whether setting the agent's input was succesful
17            if (result.success == true) {
18                alert('The text in the agent input has been updated');
19            } else {
20                alert('Setting the agent input was not Succesful');
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:

NameTypeDescription
successBooleantrue if setting the agent’s input was successful; false if setting the agent’s input wasn’t successful.