hide custom chat button when no are agents online | Community
Skip to main content

hide custom chat button when no are agents online

  • February 27, 2019
  • 4 replies
  • 0 views

Hello,

Firstly, I apologise if this has already been covered off as I suspect it probably has.

Alongside the Zendesk button, we have custom chat button on our hc that fires the chat button on click

           <button id="chat_submit" class="button" onclick=" $zopim.livechat.button.show();
           $zopim.livechat.window.show();
           $zopim.livechat.bubble.show();" style="display: none;">Chat</button>

This works fine, accept that when no agents are online it still fires the chat button with a un helpful message (it won’t trigger the offline Get Help widget that the ZD button does). I have added an image of what happens (apologies for quality, it was supplied to me), may be worth noting it looks like this was taken while the user was on a mobile.

Ideally, what I'd like to be able to do is hide this button when no agents are online, I see that there is a

$zopim.livechat.button.hide function in the Javascript API, but I assume this only works for the Zendesk button?

Is there a way I can for example add display:none; to #chat_submit when no agents are online? For an example please see
ask.library.unisa.edu.au

Thanks for your help

Sam

This topic has been closed for replies.

4 replies

  • February 28, 2019

Hi Sam,

Since you are using the Web Widget, you will need to wrap the JS code in a zE function.

You can look at this post to learn more: https://support.zendesk.com/hc/en-us/articles/115007912068-Using-the-Chat-widget-JavaScript-API

Thanks,

Ramin


  • Author
  • February 28, 2019

@Ramin

 

thanks for this, I will take a look


  • Author
  • February 28, 2019

@Ramin

thanks for your help, I managed to get it working with

// JavaScript source code
$(document).ready(function () {
zE(function () {

$zopim(function () {


$zopim.livechat.setOnStatus(check);


function check(status) {
if (status == 'offline') {
$("#div").css({ "display": "none" });
}

else if (status == 'online') {
$("#div").css({ "display": "inline-block" });
}
}


});

});

});

 

The only question is I am not sure if the (document).ready is actually doing anything here? I doesn't seem to affect the functionality, can you comment?

 

Sam


  • February 28, 2019

Hi Sam, 

Don't think it is required, usually the zE function is all that is required.

-Ramin