getAgentState()

Returns the agent’s current Chat status, such as Online, Away, or Offline. Available in API version 29.0 or later.

Syntax 

1sforce.console.chat.getAgentState(callback:Function)

Arguments 

NameTypeDescription
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="testGetAgentState();return false;">Get Agent State</a> 
4
5    <script type="text/javascript">
6        function testGetAgentState() {
7            sforce.console.chat.getAgentState(function(result) {
8                if (result.success) {
9                    alert('Agent State:' + result.state);
10                } else {
11                    alert('getAgentState has failed');
12                }
13            });
14        }
15    </script>
16</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
stateStringString representing the current agent state—for example, Online, Away, or Offline.
successBooleantrue if getting the agent’s Chat status was successful; false if getting the agent’s Chat status wasn’t successful.