Possibility to get the agents' visible status via an API

Answered

9 Comments

  • Kristian Gerardsson

    Made a stupid little script to check.. (requires jQuery)

     


    <script>
    window.zendeskChatStatusInterval = window.setInterval(function() {
    var $chatElement = $('.zopim');
    if ($chatElement.length > 0) {
    window.clearInterval(window.zendeskChatStatusInterval);
    var online = $chatElement.filter(':visible').length > 0;
    $('.chat-status').removeClass('hidden').text(online ? 'Online' : 'OFFLINE').addClass(online ? 'label--green' : 'label--red');
    $('.chat-status-loader').remove();
    }
    }, 500);
    </script>

    0
  • Yunen Yeo

    Hi Kristian,

    If you just want to show an online/offline tag on your contact us page, will the account/department status do? We do have those APIs available.

    Account JS API:

    $zopim.livchat.setOnStatus(callback)

    Department JS API:

    $zopim.livechat.departments.getAllDepartments();

     

     

    0
  • Kristian Gerardsson

    Hi. Did not know that departments had the status, i missed that somehow :)

    I also assumed the setOnStatus callback only ran when the status CHANGED, however, reading closely, it says that it's also run once when set.

    This was exactly what I needed :) Thanks!

    For anyone else reading this, here's my new small script:

     

    <script>
    window.clearInterval(window.zendeskChatStatusInterval);
    window.zendeskChatStatusInterval = window.setInterval(function() {
    //Wait until $zopim and its `livechat` is initialized
    if (typeof $zopim === 'undefined' || typeof $zopim.livechat === 'undefined') {
    return;
    }

    $zopim.livechat.setOnStatus(function(status) {
      setOnlineLabel(status === 'online');
    });

    window.clearInterval(window.zendeskChatStatusInterval);
    }, 250);

    function setOnlineLabel(online) {
      // Do something what the DOM
    }
    </script>

    2
  • Al

    Thank you Kristian. This is exactly what I needed! :)

    I can now add a link to "Chat Now" or "Contact Us" depending on status. 

    0
  • Phil

    Super useful, thanks Kristian!

    0
  • Yuchen Zhong

    Is it possible to do the same with iOS and Android SDK? We would like to hide the chat button if no agents are available. 

    It doesn't look like it is possible without starting chat first. We have this `isAccountOnline` in the `ZDCChatAPI`. But it always false before starting the chat. And `connectionStatus` on the same object will be `ZDCConnectionStatusUninitialized`. 

    API Reference:

     

    https://github.com/zendesk/zendesk_sdk_chat_ios/blob/8476fd1e4fc07093eb51872efe3e538eb836b820/ZopimChatSample/ZopimChatSample/Frameworks/ZDCChatAPI.framework/Headers/ZDCChatAPI.h#L79

    1
  • Ramin Shokrizadeh
    Zendesk Product Manager

    Hi Yuchen,

    Currently, it is not possible with the mobile SDK because it requires a websocket connection first to get the account status. There are no REST endpoints to get the account status to solve this use case unfortunately. 

    You could look at using the endpoint from real time metrics to see the number of agents online and build some custom logic to show/hide the button as a potential workaround: https://developer.zendesk.com/rest_api/docs/chat/apis#rest-api

    -Ramin

    0
  • Kevin

    So is the recommendation to use sockets in order to determine if agents are available?

    0
  • Ramin Shokrizadeh
    Zendesk Product Manager

    Yes. That would get you the number of agents by status, not the status of specific agents.

    0

Please sign in to leave a comment.

Powered by Zendesk