Trigger webchat
Trigger webchat
Introduction
There are occasions, where you might want to trigger the webchat yourself.
For example, an action has happened on your webpage, and you want to trigger a set invitation to bring the customer into your chat or where, you want to create your own button your website, and when a customer clicks on this you launch the webchat
Script config
Here is an example of what to set when you want to launch the invitation
function (chatApp) {
var myProxy = {
onAppStart: function() { // execute desired logic} ,
onOpenInvitation: function() { // execute desired logic console.log('open invitation') },
}
Here is an example of what to set when you want to launch the webchat
function (chatApp) {
var myProxy = {
onAppStart: function() { // execute desired logic} ,
onOpenChatWindow: function() { // execute desired logic console.log('open chat window') },
}
To add this, you need to add it at the bottom of the script in this area here
})(
--ADD THE FUNCTION CHATAPP CODE HERE
);
</script>
Then, the full script will look like this
<!-- Place this code snippet anywhere you want the button to appear in your page. If no button has been configured in the chat script, it will not show up nor take any space. -->
<div id="__8x8-chat-button-container-script_1333070733643e5b8fa7a791.52161248"></div>
<!-- This script will not interfere with the button layout, you just need to include it in the same page. It must also be within the <body> section of the page, preferably just before the ending tag. -->
<script type="text/javascript">
(function(c, f, ef){
var typeofC = Object.prototype.toString.call(c);
var props = (typeofC === '[object Object]' && c) || {};
var cb = f || (typeofC === '[object Function]' && c);
var config = {
scriptUuid: "script_1333070733643e5b8fa7a791.52161248",
tenant: "Y2hyaXNjcm9tYmllZGVtbzAx",
channelName: "WebChatChannel",
channelUuid: "Ak3ULjXFQx-unSA6ebdW8A",
domain: "https://vcc-eu11.8x8.com",
buttonContainerId: "__8x8-chat-button-container-script_1333070733643e5b8fa7a791.52161248",
align: "right",
};
var url = new URL("https://cloud8-cc-geo.8x8.com/vcc-chat-channels/public/webchat/discovery");
var params = { domain: config.domain, tenant: config.tenant, channelUuid: config.channelUuid };
url.search = new URLSearchParams(params).toString();
fetch(url)
.then(response => response.json())
.then(data => config.domain = !data.domain ? config.domain : data.domain)
.catch(error => console.warn('Failed to retrieve override domain, will continue using ', config.domain, error))
.finally(() => loadChat());
function loadChat() {
var se = document.createElement("script");
se.type = "text/javascript";
se.async = true;
se.src = props.loaderURL || (config.domain + "/CHAT/common/js/chatv3.js");
Object.keys(config).forEach(function (k) { se.dataset[k] = config[k] });
Object.keys(props).forEach(function (k) { se.dataset[k] = props[k] });
function handleInitEvent(e) {
var initFn = e.detail.init;
initFn(config, cb);
se.removeEventListener('init', handleInitEvent)
}
function handleErrorEvent(e) {
ef && ef(e);
se.removeEventListener('customerror', handleErrorEvent);
}
se.addEventListener('init', handleInitEvent);
se.addEventListener('customerror', handleErrorEvent);
var os = document.getElementsByTagName("script")[0];
os.parentNode.insertBefore(se, os);
}
})(function (chatApp) {
var myProxy = {
onAppStart: function() { // execute desired logic} ,
onOpenInvitation: function() { // execute desired logic console.log('open invitation') },
}
);
</script>
Updated 29 days ago