How to control chat availability on different sites using departments | Community
Skip to main content

How to control chat availability on different sites using departments

  • May 13, 2016
  • 7 replies
  • 0 views

Jacob20

Credit for this solution goes to Ramin Shokrizadeh.

The use case

My use case involves sites in different countries, but the solution could work equally well if you need to control online/offline status between brands or some other setup.

I wanted to make sure that I could show chat as offline for sites in one country, when that country had a holiday, without having to shut down chat for all other countries that were not on holiday.

The solution

So, the solution for me was to have departments based on countries, and all the chat agents who can service this country (and only this country) be members of this Department.

The example script below is for our swedish sites, the Department is named SWEDEN, it should be appended to the Zendesk Web Widget embed code.

Make sure that the name is spelled exactly the same in script and on the Department form! On the Departments overview all names appear CAPITALIZED, but that may not be the case when edited.

<script>
zE(function(){
$zopim(function() {
$zopim.livechat.departments.setVisitorDepartment('SWEDEN');
$zopim.livechat.departments.filter('');
$zopim.livechat.setOnStatus(function(e) {
if (e === 'offline') return;
var dep = $zopim.livechat.departments.getDepartment('SWEDEN');
if(dep.status=="offline"){
$zopim.livechat.setStatus('offline');
}
});
});
});
</script>

Other scripts should be made for each country and Department you service using Zopim chat.

So the way this works is (with the above in place)

When they are having a holiday in Sweden and the swedish support staff are having a day off (everyone in the Department SWEDEN are offline), sites in Sweden will show chat as offline.

And sites in countries where Department agents are online will still show chat as online.

7 replies

Jennifer16

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!


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'
$zopim.livechat.setStatus('offline');
jQuery('.botao-chat-container').addClass('esconder');
// hide the widget or similar
$zopim.livechat.hideAll();
} else {
$zopim.livechat.setStatus('online');
// 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
$zopim.livechat.departments.filter('');
setTimeout(function(){
jQuery('.botao-chat-container').removeClass('esconder');
}, 30000);
// Automatically set the Department
$zopim.livechat.departments.setVisitorDepartment(departamento);

}

});
});


  • November 28, 2018

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.

 

 

 

 


Jacob20
  • Author
  • November 29, 2018

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:

<script>
zE(function(){
$zopim(function() {
$zopim.livechat.departments.setVisitorDepartment('Dealer'); 
$zopim.livechat.departments.filter('');
$zopim.livechat.setOnStatus(function(e) {
if (e === 'offline') return;
var dep = $zopim.livechat.departments.getDepartment('Dealer');
if(dep.status=="offline"){
$zopim.livechat.setStatus('offline');

});
});
});
</script>

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.


  • November 29, 2018

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?


Jacob20
  • Author
  • November 30, 2018

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. 


  • September 30, 2019

I have a similar setup, where we are using multi brand and have departments set to control them on each site.  What I am wanting to do is have one of my brands with multiple departments available for the end user to select.

Right now my brands work as Department 1 & Department 2.

On my one brand I want users to see the options for Department 1, 3, and 4.  I want to leave the other brand to still just be Department 2.

$zopim.livechat.setOnConnected(function() {
var department_status = $zopim.livechat.departments.getDepartment('Department1');
$zopim.livechat.departments.filter('');
$zopim.livechat.departments.setVisitorDepartment('Department1');

 

Is it as simple as changing the code to be  $zopim.livechat.departments.getDepartment('Department1', 'Department3, 'Department4) ?  Then this will enable the dropdown to show the 3 options?