Skip to content

Instantly share code, notes, and snippets.

@Sarapulov
Last active January 12, 2017 10:14
Show Gist options
  • Save Sarapulov/cc4b0574cc87d236471679a80eefb805 to your computer and use it in GitHub Desktop.
Save Sarapulov/cc4b0574cc87d236471679a80eefb805 to your computer and use it in GitHub Desktop.
Zopim logic for handling departments
<!-- the web widget -->
<script>
window.zEmbed||(function(){
var queue = [];
window.zEmbed = function() { queue.push(arguments); }
window.zE = window.zE || window.zEmbed;
document.zendeskHost = 'mycompany.zendesk.com';
document.zEQueue = queue;
}());
</script>
<script src="https://assets.zendesk.com/embeddable_framework/main.js" data-ze-csp="true" async defer></script>
<script>
var runWidgetLogic = (function() {
'use strict';
var module = {};
module.init = function(HCSearch, chat, contactForm) {
if (zE) configureWidget(HCSearch, chat, contactForm);
else {
console.log("ERROR: No Widget running on the page.");
return;
}
};
function configureWidget(HCSearch, chat, contactForm) { // API configuration
var widgets = { webWidget: {} },
customizelabels = $.extend({}, widgets.webWidget, {
launcher: {
label: { '*': 'Have a Question?' }, // Web Widget button text
chatLabel: { '*': 'Chat' } // Chat button text - When the Help Center Search option is disabled
},
helpCenter: {
chatButton: { '*': 'Chat with a person now' }, // Chat button text - when the Help Center Search option is enabled
title: { '*': 'Brand Help Centre' } // Web Widget header text
}
});
widgets.webWidget = customizelabels;
if (!HCSearch) widgets.webWidget = $.extend({}, widgets.webWidget, { helpCenter: { suppress: true } });
if (!chat) widgets.webWidget = $.extend({}, widgets.webWidget, { chat: { suppress: true } }); else zopimConfig();
if (!contactForm) widgets.webWidget = $.extend({}, widgets.webWidget, { contactForm: { suppress: true } });
window.zESettings = widgets;
}
zE(function() {
zE.setHelpCenterSuggestions({ labels: ['top_suggestions'] });
});
function zopimConfig() {
zE(function() {
$zopim(function() {
var zl = $zopim.livechat;
zl.setOnConnected(function() {
var department_status = zl.departments.getDepartment('Department Name');
if (department_status.status == 'offline') zl.setStatus('offline'); // Set the account status to 'offline'
else {
zl.concierge.setAvatar("path_to/concierge_image.png");
zl.setLanguage('en'); // Set language to English:
zl.window.setTitle('Brand Support'); // Set the Window Title:
zl.addTags("brand_name"); // set the tag
zl.departments.filter(''); // Hide the Drop-down list option in the Pre-Chat Form to select the Department
zl.departments.setVisitorDepartment('Department Name'); // Automatically set the Department
}
});
});
});
}
return module;
}());
/**
* Change the widget settings.
* jQuery is required
* @params {boolean} HCSearch - enable HC Search?
* @params {boolean} chat - enable chat?
* @params {boolean} contactForm - enable contact form?
*/
runWidgetLogic.init(true, false, false);
</script>
<!-- End of the web widget -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment