NAV Navbar
javascript

.getAgentStatusAsync()

SnapEngage.getAgentStatusAsync(function (online) {
    if (online) {
        console.log('chat is online/available');
    } else {
        console.log('chat is offline');
    }
});

Check whether or not you have agents online and your live chat is available.

Parameters

Parameter Type Description
Anonymous Function Function This callback function uses a required parameter "online" which is a boolean. Inside the function, you can check the value of the "online" parameter, which will evaluate to true if agents are online and chat is available, or false if no agents are online and/or chat is not available.

Common reasons for chat being unavailable include: All agents are paused, or it is outside of the widget's configured "Hours of Operation".

Example getAgentStatusAsync() Usage

Hide the chat button if chat is unavailable
SnapEngage.getAgentStatusAsync(function (online) {
    if (!online) {
        SnapEngage.hideButton();
    }
});

Hide the SnapEngage button when your agents are offline/unavailable.

Hide a custom inline button if chat is unavailable
// Using Javascript
SnapEngage.getAgentStatusAsync(function (online) {
    if (!online) {
        document.getElementById('myInlineButtonId').style.display = 'none';
    }
});

// Using jQuery
SnapEngage.getAgentStatusAsync(function (online) {
    if (!online) {
        $('#myInlineButtonId').hide();
    }
});

If you have a custom button image that you've embedded into your site, you may want to show or hide it if the widget is online or offline. This is how you would do that.

Check agent status every three minutes
var threeMinutes = 3 * 60 * 1000;
var tid = setTimeout(checkChatStatus, threeMinutes);

// Check the widget status every three minutes
function checkAgentStatus() {
    SnapEngage.getAgentStatusAsync(function(online) {
        if (online) {
            SnapEngage.showButton();
        } else {
            SnapEngage.hideButton();
        }
    });

    // Recursive call
    clearTimeout(tid);

    // Set another three minute time out
    tid = setTimeout(checkAgentStatus, threeMinutes);
}

As you may have guessed, you can call .getAgentStatusAsync() asynchronously.