aquaculture-chatbot-widget
Version:
A customizable chatbot widget for aquaculture consultation
2 lines (1 loc) • 1.32 kB
JavaScript
(function(e){typeof define=="function"&&define.amd?define(e):e()})(function(){"use strict";var o=Object.defineProperty;var h=(e,t,i)=>t in e?o(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var a=(e,t,i)=>h(e,typeof t!="symbol"?t+"":t,i);class e{constructor(i={}){a(this,"config");a(this,"iframe");this.config=i,this.iframe=document.createElement("iframe"),this.setupIframe()}setupIframe(){var i,s;this.iframe.style.position="fixed",this.iframe.style.bottom=((i=this.config.position)==null?void 0:i.bottom)||"20px",this.iframe.style.right=((s=this.config.position)==null?void 0:s.right)||"20px",this.iframe.style.border="none",this.iframe.style.width="350px",this.iframe.style.height="500px",this.iframe.style.maxHeight="80vh",this.iframe.style.zIndex="1000",this.iframe.style.display="block",this.iframe.style.backgroundColor="transparent",this.iframe.src="YOUR_DEPLOYED_WIDGET_URL",window.addEventListener("message",this.handleMessage.bind(this))}handleMessage(i){var s;if(i.origin===new URL(this.iframe.src).origin){const{type:n}=i.data;switch(n){case"CHATBOT_READY":(s=this.iframe.contentWindow)==null||s.postMessage({type:"CONFIG",data:this.config},"*");break}}}mount(i){i?i.appendChild(this.iframe):document.body.appendChild(this.iframe)}unmount(){this.iframe.remove()}}window.ChatbotWidget=e});