How to control chat availability on different sites using departments


  • Jennifer Rowe

    Yay! Thanks for sharing the first tip in our community, Jacob! And it's a great one! I'm sure it will help others. Thanks for sharing!

  • fernando.silveira

    In my case, appears at console browser:  "Uncaught TypeError: Cannot read property 'status' of undefined".

    here's a peace of a code

    $zopim.livechat.setOnConnected(function() {
    $zopim.livechat.setOnStatus(function () {
    var department_status = $zopim.livechat.departments.getDepartment(departamento);
    if (department_status.status == 'offline') {
    // Set the account status to 'offline'
    // hide the widget or similar
    } else {
    // The department is Online (At least one agent in that dept is Online)
    // Hide the Drop-down list option in the Pre-Chat Form to select the Department
    }, 30000);
    // Automatically set the Department



  • Jerry Adams

    I'm try to use the above code on one of our sites to determine if the specific dept is online and display the Chat.

    We have two groups - Customer Care and Dealer so in my case I'm installing the code on the Dealer site to test when I login to chat they both start which I I would expect since the site for the Customer Care group uses the Zentalk Chat code installed with the app so it is not checking groups.

    If I have a Customer Care agent logon I would think that the Dealer site would not display the Chat but it does.

    this is on Shopify so I don't know if I'm missing something.





  • Jacob J Christensen

    Hi Jerry,

    The above code lets you appear as offline when there are no agents available in the Zendesk chat department specified.

    You mention groups, so I'm unsure if you mean Zendesk Support groups - that won't work for this kind of setup.

    If you really mean Departments and it's still not working, it could be a few things.

    Lets say your Dealer department is spelled exactly like that, what you'd need to do is insert the following script right after you chat embed code:

    $zopim(function() {
    $zopim.livechat.setOnStatus(function(e) {
    if (e === 'offline') return;
    var dep = $zopim.livechat.departments.getDepartment('Dealer');


    For your other site you would need the same code, only the Dealer part switched to whatever you've named that other Department.

    Hope that helps you out.

  • Jerry Adams

    This script work well when I put in the correct location - thanks for the missing piece.

    How can this be modified to also check when the agent comes back online without refreshing the page?

  • Jacob J Christensen

    Good to hear it Jerry!

    I'm afraid I don't know the answer to your question - my understanding is that the widget is updating (and thereby re-checking the conditions) quite frequently, but that is just my guess. 


Please sign in to leave a comment.

Powered by Zendesk