Can I configure the Web Widget (Classic) to present Chat on my webpage only when a specific department is online?

Show Chat in the Web Widget (Classic) only when a specific department is online

Disclaimer: This article is provided for instructional purposes only. Zendesk doesn't support or guarantee the code. Post any issues in the comments section or try to find a solution online.

Tip: This article provides code for the Web Widget (Classic) in a Zendesk account. To check which widget you have, see Which widget do I have with my Zendesk account?

Yes. By default, the widget doesn't appear only when specific departments are online, but you can add a custom script with the Zendesk API. With a custom script, you configure the Web Widget (Classic) to show Chat only when a specific department is online. The script detects a change in the department status of the account and the API updates the Web Widget (Classic) settings based on the current status.

The example below applies this method. It shows the Web Widget as online for Chat only when the CRM department is online. If the CRM department isn't online, the script suppresses Chat. When the script suppresses Chat, the Web Widget (Classic) shows only other features that you turned on for the visitor, such as the contact form or help center search.

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


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
}
}
});
}
});
