Skip to content

Instantly share code, notes, and snippets.

@Toinne
Created January 21, 2022 16:49
Show Gist options
  • Save Toinne/c83f4a42350dd1d2b9ee36445027285f to your computer and use it in GitHub Desktop.
Save Toinne/c83f4a42350dd1d2b9ee36445027285f to your computer and use it in GitHub Desktop.
<!-- This goes into the head of the page -->
<script>
!function(s,r,o){var a,p,i,c=[],u=[];s[o]={init:function(){a=arguments;var n={then:function(e){return u.push({type:"t",next:e}),n},catch:function(e){return u.push({type:"c",next:e}),n}};return n},on:function(){c.push(arguments)},render:function(){p=arguments},destroy:function(){i=arguments}},s.__onWebMessengerHostReady__=function(e){if(delete s.__onWebMessengerHostReady__,s[o]=e,a)for(var n=e.init.apply(e,a),t=0;t<u.length;t++){var r=u[t];n="t"===r.type?n.then(r.next):n.catch(r.next)}p&&e.render.apply(e,p),i&&e.destroy.apply(e,i);for(t=0;t<c.length;t++)e.on.apply(e,c[t])};var e=new XMLHttpRequest;e.addEventListener("load",function(){try{var e;if((e="string"==typeof this.response?JSON.parse(this.response):this.response).url){var n=r.getElementsByTagName("script")[0],t=r.createElement("script");t.async=!0,t.src=e.url,n.parentNode.insertBefore(t,n)}}catch(e){}}),e.open("GET","https://chat-engagor.netdna-ssl.com/loader.json",!0),e.responseType="json",e.send()}(window,document,"ClarabridgeChat");
</script>
<!-- This initializes the chat -->
<script>
ClarabridgeChat.on('widget:opened', () => {
ClarabridgeChat.startConversation();
});
ClarabridgeChat.init({
integrationId: '61e68aef2b26e800ebba93a4'
}).then(() => {
ClarabridgeChat.setDelegate({
beforeSend(message) {
message.metadata = {
...message.metadata,
originTitle: 'Chat with Jane',
originUrl: window.location.href
};
return message;
}
});
ClarabridgeChat.open();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment