setAgentState()

Sets an agent’s Chat status, such as Online, Away, or Offline. Available in API version 29.0 or later.

Syntax 

1sforce.console.chat.setAgentState(state:String, (optional)callback:Function)

Arguments 

NameTypeDescription
stateStringChat status you want to set the agent to—for example, Online, Away, or Offline.
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="testSetAgentState('Online');return false;">Set Agent Status to Online</a> 
4    <script type="text/javascript">
5        function testSetAgentState(state) {
6            sforce.console.chat.setAgentState(state, function(result) {
7                if (result.success) {
8                    alert('Agent State Set to Online');
9                } else {
10                    alert('setAgentState has failed');
11                }
12            });
13        }
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:

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