Question

The routing workflow using triggers described in the article Automatically route chats to departments does not take into account a specific department’s online status. Is it possible to show the Web Widget as online for Chat on my webpage only if a certain department is online?

Answer

Disclaimer: This article is provided for instructional purposes only. Zendesk does not support or guarantee the code. Post any issues you have in the comments section or try searching for a solution online.
Tip: This article provides code to use for the Web Widget (Classic) in a Support account. To check which widget you have with your account, see the article: Which widget do I have with my Zendesk account?

It is not natively possible to display the widget when specific departments are online, but you can create a custom script with the use of Zendesk API.  With a custom script, you can configure the Web Widget (Classic) to present Chat only when a specific department is online.  The script will identify a change in the account’s department status and the API will update the settings for the Web Widget (Classic) as desired based on the current department status.

Below is an example API script that uses this method. This example shows the Web Widget as online for Chat only when the CRM department is online. If the department's CRM status is not online, Chat is suppressed. When Chat has been suppressed only other enabled features of the Web Widget (Classic) are shown to the visitor. For example, the contact form or help center search.

<script id="ze-snippet" 
src="https://static.zdassets.com/ekr/snippet.js?key=ACCOUNT_KEY"> </script>

<script>
zE('webWidget:on', 'chat:departmentStatus', function(dept) {
if (dept.name === 'CRM' && dept.status === 'online') {
zE('webWidget', 'updateSettings', {
webWidget: {
chat: {
departments: {
enabled: [''],
select: 'CRM'
},
suppress: false
}
}
});
} else if (dept.name === 'CRM' && dept.status !== 'online') {
zE('webWidget', 'updateSettings', {
webWidget: {
chat: {
suppress: true
}
}
});
}
});
</script>
Powered by Zendesk