Skip to content

Instantly share code, notes, and snippets.

@Sarapulov
Last active November 19, 2018 13:24
Show Gist options
  • Save Sarapulov/bedc724db6d524072f661720a883d657 to your computer and use it in GitHub Desktop.
Save Sarapulov/bedc724db6d524072f661720a883d657 to your computer and use it in GitHub Desktop.
Zendesk Web Widget API JS wrapper
//// OPTION 1 /////
function ww(prop, params, action) {
return zE('webWidget' + (action ? ':' + action : ''), prop, params);
}
ww('prefill', {
name: {
value: 'isamu',
readOnly: true // optional
},
email: {
value: '[email protected]',
readOnly: true // optional
},
phone: {
value: '61431909749',
readOnly: true // optional
}
})
ww('open', function() {
console.log("The widget has been opened!");
},'on')
ww('display','','get');
//// OPTION 2 /////
var ww = {
"do": function(prop, params ){ return zE('webWidget', prop, params) },
"on": function(prop, params){ return zE('webWidget:on', prop, params) },
"get": function(prop, params){ return zE('webWidget:get', prop, params) }
};
ww.do('prefill', {
name: {
value: 'isamu',
readOnly: true // optional
},
email: {
value: '[email protected]',
readOnly: true // optional
},
phone: {
value: '61431909749',
readOnly: true // optional
}
});
ww.on('open', function() {
console.log("The widget has been opened!");
});
ww.get('display');
//// OPTION 3 /////
var ww = {
"do": function(prop, params, action){ return zE('webWidget' + (action ? ':' + action : ''), prop, params); },
"on": function(prop, params){ return ww.do(prop, params, 'on') },
"get": function(prop, params){ return ww.do(prop, params, 'get') }
};
ww.do('prefill', {
name: {
value: 'isamu',
readOnly: true // optional
},
email: {
value: '[email protected]',
readOnly: true // optional
},
phone: {
value: '61431909749',
readOnly: true // optional
}
});
ww.on('open', function() {
console.log("The widget has been opened!");
});
ww.get('display');
/// FULL WRAPPER EXAMPLE
(function(ww){
ww = {"do": function(prop, params, action){ return zE('webWidget' + (action ? ':' + action : ''), prop, params); },"on": function(prop, params){ return ww.do(prop, params, 'on') },"get": function(prop, params){ return ww.do(prop, params, 'get') }};
ww.do('updateSettings',{
webWidget: {
chat: {
departments: {
enabled: ['Learning as a Lifestyle'],
selected: 'Learning as a Lifestyle'
}
}
}
});
})({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment