1 line
8.6 KiB
JavaScript
1 line
8.6 KiB
JavaScript
(window.zowieJsonp=window.zowieJsonp||[]).push([[7],{51:function(e,n,t){"use strict";t.r(n),t.d(n,"getConversationId",function(){return j}),t.d(n,"saveConversationId",function(){return _}),t.d(n,"keepAlive",function(){return z}),t.d(n,"setup",function(){return O});var i=t(7),a=t(2),o=t(1),c="chatbot",r=void 0,s=!1,d=function(e){return"zowie-zendesk-conv-in-progress-"+e},u=function(e){return"true"===window.localStorage.getItem(e)},l=function(e,n){return window.localStorage.setItem(e,String(n))};var v=void 0,f=void 0,m=function(){var e=document.location.host.split("."),n=e.length,t="."+e.slice(n-2,n).join(".");document.cookie="__zlcmid=;path=/;domain="+t+";expires=Thu, 01 Jan 1970 00:00:01 GMT"},h=function(){return window.location.href.includes("glamira")||window.location.href.includes("sharkgaming.dk")||window.location.href.includes("sharkgaming.se")||window.location.href.includes("sharkgaming.no")||window.location.href.includes("cobbtuning.com")&&void 0!==window.require?new Promise(function(e,n){window.require(["https://dev.zopim.com/web-sdk/latest/web-sdk.js"],function(n){e(n)})}):new Promise(function(e,n){try{var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://dev.zopim.com/web-sdk/latest/web-sdk.js",t.addEventListener("load",function(n){e(window.zChat)}),t.addEventListener("error",function(e){n("Failed to load Zendesk Chat script: "+JSON.stringify(e))}),document.body.appendChild(t)}catch(e){n("Failed to add Zendesk Chat script: "+JSON.stringify(e))}})};function g(e,n){for(var t=e.split(","),i=t[0].match(/:(.*?);/)[1],a=atob(t[1]),o=a.length,c=new Uint8Array(o);o--;)c[o]=a.charCodeAt(o);return new File([c],n,{type:i})}function p(e,n,t,i,o){var c=o+"/instances/"+n+"/conversations/"+e+"/messages/announcement";Object(a.c)(c,{text:t,visibility:i})}function b(e,n,t){var i=t+"/instances/"+n+"/conversations/"+e+"/agent-not-available";return Object(a.c)(i,{})}function k(e,n,t,i){"chatbot"!==c&&setTimeout(function(){return y(e,n,t,!1,[],i)},1e3)}function y(e,n,t,i,o,r){if("chatbot"!==c){var s=r+"/instances/"+t+"/conversations/"+n+"/messages";Object(a.a)(s).then(function(c){var s=c.data;if(i){var d=s.map(function(n){if(void 0!==n.text){var t=new Date(n.time),i=t.getHours(),a="0"+t.getMinutes(),o="0"+t.getSeconds(),c=i+":"+a.substr(-2)+":"+o.substr(-2);return n.author+" ("+c+"): "+n.text}return void 0!==n.fileData&&void 0!==n.fileName?void e.sendFile(g(n.fileData,n.fileName)):void 0}).join("\n\n"),u=o.map(function(e){return"tier"===e.key||"Tier"===e.key?"30-day GMV: $"+e.value:e.key+": "+e.value}).join("\n"),l=d;""!==l&&u.length>0&&"ac6b077fad4543ee898035e7eaf905eb"===t&&(l+="\n\n\nProperties:\n",l+=u),""!==l&&e.sendChatMsg(l)}else s.forEach(function(n){void 0!==n.text?e.sendChatMsg(n.text):void 0!==n.fileData&&void 0!==n.fileName&&e.sendFile(g(n.fileData,n.fileName))});if(s.length>0)return function(e,n,t,i){var o=i+"/instances/"+n+"/conversations/"+e+"/messages/seen";return Object(a.c)(o,{time:t})}(n,t,s[s.length-1].time,r).finally(function(){k(e,n,t,r)});k(e,n,t,r)})}}function I(e,n,t,a,r){if(["f4b3c2093a744fdc9eaaf0c00f4d7d3b","7a761b8ef2ea41369f7c8fe9bee9996e","1d1f478a1fd74e0393d44f9bb7c51b2f","2bc4073a42304812874885c0ca806f2a"].includes(n)){Object(o.g)("Checking department status: ",t,a);var s=u(d(e));if(void 0!==a)"offline"!==a.status||s||(b(e,n,r).finally(function(){c="chatbot"}),clearInterval(v),i.a.logger.info("livechat-zendesk-event-chat_departmentoffline",{instanceId:n,conversationId:e}));else void 0!==t.find(function(e){return"offline"!==e.status})||s||(b(e,n,r).finally(function(){c="chatbot"}),clearInterval(v),i.a.logger.info("livechat-zendesk-event-chat_departmentoffline",{instanceId:n,conversationId:e}))}}function w(e,n,t,i){(function(e,n,t){var i=t+"/instances/"+n+"/conversations/"+e+"/state";return Object(a.a)(i).then(function(e){return e.data}).catch(function(){return{owner:"chatbot",metadata:void 0}})})(n,t,i).then(function(s){var d=s.owner,u=s.metadata;if("zendesk"===d&&"chatbot"===c){c="zendesk";var l=e.getAllDepartments();if(Object(o.g)("Available departments: ",l),u){var v=l.find(function(e){return e.name===u});v?(e.setVisitorDefaultDepartment(v.id),I(n,t,l,v,i)):I(n,t,l,void 0,i)}else I(n,t,l,void 0,i);(function(e,n,t){var i=t+"/instances/"+n+"/conversations/"+e+"/metadata";return Object(a.a)(i).then(function(e){return e.data}).catch(function(){return{}})})(n,t,i).then(function(a){var o={};void 0!==a.name&&(o.display_name=a.name),void 0!==a.email&&(o.email=a.email),void 0!==a.phoneNumber&&(o.phone=a.phoneNumber),e.setVisitorInfo(o),y(e,n,t,!0,a.customProperties,i)}).catch(function(){y(e,n,t,!0,[],i)}).finally(function(){r=setTimeout(function(){return w(e,n,t,i)},500)})}else"chatbot"===d&&"zendesk"===c?(c="chatbot",r=setTimeout(function(){return w(e,n,t,i)},500)):r=setTimeout(function(){return w(e,n,t,i)},500)})}function j(e){return localStorage.getItem("zowie-zendesk-"+e+"-conversationId")}function _(e,n){localStorage.setItem("zowie-zendesk-"+e+"-conversationId",n)}function z(e){var n=e.accountKey,t=e.conversationId,a=e.instanceId;h().then(function(e){i.a.logger.info("livechat-zendesk-keepalive-load-success",{instanceId:a,conversationId:t,accountKey:n}),e.init({account_key:n})}).catch(function(e){Object(o.f)(e),i.a.logger.error("livechat-zendesk-keepalive-load-failed",{instanceId:a,conversationId:t,accountKey:n,errorRoot:e})})}function O(e,n){var t=e.accountKey,u=e.conversationId,g=e.instanceId,b=e.apiBaseUrl+"/api/v1/chat-integration-zendeskchat";void 0!==r&&clearTimeout(r),s=!1,c="chatbot",j(g)!==u&&(m(),_(g,u)),h().then(function(e){Object(o.g)("Zowie - Zendesk - SDK loaded"),i.a.logger.info("livechat-zendesk-load-success",{instanceId:g,conversationId:u,accountKey:t}),e.on("connection_update",function(n){Object(o.g)("Zowie - Zendesk - connection_update",n),i.a.logger.info("livechat-zendesk-event-connection_update",{instanceId:g,conversationId:u,accountKey:t,status:n}),"connected"===n&&!1===s&&(s=!0,r=setTimeout(function(){return w(e,u,g,b)},1e3))}),e.on("chat",function(e){"chat.msg"===e.type&&e.msg&&"visitor"!==e.nick&&s?(Object(o.g)("Zowie - Zendesk - chat_message",e),function(e,n,t,i,o,c){var r=t?t.replace("agent:",""):void 0,s=c+"/instances/"+n+"/conversations/"+e+"/messages/text";Object(a.c)(s,{text:i,userId:r,time:o})}(u,g,e.nick,e.msg,e.timestamp,b)):"chat.file"===e.type&&"visitor"!==e.nick&&e.attachment&&s?(Object(o.g)("Zowie - Zendesk - chat_visitor",e),function(e,n,t,i,o,c){var r=t?t.replace("agent:",""):void 0,s=c+"/instances/"+n+"/conversations/"+e+"/messages/file";Object(a.c)(s,{url:i,mime:o,userId:r})}(u,g,e.nick,e.attachment.url,e.attachment.mime_type,b)):"chat.queue_position"===e.type&&e.queue_position&&s?e.queue_position>0&&(p(u,g,"Current queue position: "+e.queue_position,"TEMPORARY",b),clearInterval(v),void 0!==e.queue_position&&(f=e.queue_position,v=setInterval(function(){p(u,g,"Current queue position: "+f,"TEMPORARY",b)},3e4))):"chat.memberjoin"===e.type&&"visitor"!==e.nick&&e.display_name&&s?(Object(o.g)("Zowie - Zendesk - chat_memberjoin",e),p(u,g,e.display_name+" joined.","PERSISTENT",b),function(e,n,t){var i=t+"/instances/"+n+"/conversations/"+e+"/agent-joined";Object(a.c)(i,{})}(u,g,b),l(d(u),!0),clearInterval(v),i.a.logger.info("livechat-zendesk-event-chat_memberjoin",{instanceId:g,conversationId:u,accountKey:t,event:e})):"chat.memberleave"===e.type&&"visitor"!==e.nick&&e.display_name&&s?(Object(o.g)("Zowie - Zendesk - chat_memberleave",e),p(u,g,e.display_name+" left.","PERSISTENT",b),l(d(u),!1),clearInterval(v),i.a.logger.info("livechat-zendesk-event-chat_memberleave",{instanceId:g,conversationId:u,accountKey:t,event:e})):"typing"===e.type&&!0===e.typing&&"visitor"!==e.nick&&s?function(e,n,t){var i=t+"/instances/"+n+"/conversations/"+e+"/messages/typing";Object(a.c)(i,{})}(u,g,b):"chat.memberleave"===e.type&&"visitor"===e.nick&&s&&(function(e,n,t){var i=t+"/instances/"+n+"/conversations/"+e+"/end-chat";return Object(a.c)(i,{})}(u,g,b).finally(function(){c="chatbot",l(d(u),!1)}),clearInterval(v),i.a.logger.info("livechat-zendesk-event-chat_memberleave",{instanceId:g,conversationId:u,accountKey:t,event:e}))}),e.on("agent_update",function(e){e.nick&&function(e,n,t,i,o,c){var r=t?t.replace("agent:",""):void 0,s=c+"/instances/"+n+"/conversations/"+e+"/messages/user-metadata";Object(a.c)(s,{name:i,imageUrl:o,userId:r})}(u,g,e.nick,e.display_name,e.avatar_path,b)}),e.on("error",function(e){i.a.logger.error("livechat-zendesk-event-error",{instanceId:g,conversationId:u,accountKey:t,event:e})}),e.init({account_key:t})}).catch(function(e){Object(o.f)(e),i.a.logger.error("livechat-zendesk-load-failed",{instanceId:g,conversationId:u,accountKey:t,errorRoot:e,errorRetry:n}),(void 0===n||n<10)&&setTimeout(function(){O({accountKey:t,conversationId:u,instanceId:g},n?n+1:1)},250)})}}}]); |