@robylon/web-react-sdk 1.1.40-staging.1 → 1.1.41-staging.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((i="undefined"!=typeof globalThis?globalThis:i||self).RobylonChatbot={})}(this,(function(i){"use strict";var t,n,o,e=function(){return e=Object.assign||function(i){for(var t,n=1,o=arguments.length;o>n;n++)for(var e in t=arguments[n])({}).hasOwnProperty.call(t,e)&&(i[e]=t[e]);return i},e.apply(this,arguments)};function r(i,t,n,o){return new(n||(n=Promise))((function(e,r){function s(i){try{d(o.next(i))}catch(i){r(i)}}function a(i){try{d(o.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?e(i.value):(t=i.value,t instanceof n?t:new n((function(i){i(t)}))).then(s,a)}d((o=o.apply(i,t||[])).next())}))}function s(i,t){var n,o,e,r={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(d){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(r=0)),r;)try{if(n=1,o&&(e=2&a[0]?o.return:a[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,a[1])).done)return e;switch(o=0,e&&(a=[2&a[0],e.value]),a[0]){case 0:case 1:e=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!((e=(e=r.trys).length>0&&e[e.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!e||a[1]>e[0]&&a[1]<e[3])){r.label=a[1];break}if(6===a[0]&&r.label<e[1]){r.label=e[1],e=a;break}if(e&&r.label<e[2]){r.label=e[2],r.ops.push(a);break}e[2]&&r.ops.pop(),r.trys.pop();continue}a=t.call(i,r)}catch(i){a=[6,i],o=0}finally{n=e=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,d])}}}"function"==typeof SuppressedError&&SuppressedError,function(i){i.WIDGET="WIDGET",i.POPOVER="POPOVER",i.EMBED="EMBED"}(t||(t={})),function(i){i.RIGHT="Right",i.LEFT="Left"}(n||(n={})),function(i){i.TEXT="TEXT",i.IMAGE="IMAGE",i.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(o||(o={}));var a=function(i,t){void 0===t&&(t=.5);var n,o,e,r,s=function(i){i=i.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(i,t,n,o){return t+t+n+n+o+o}));var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}}(i);return(n=s.r,o=s.g,e=s.b,.2126*(r=[n,o,e].map((function(i){return(i/=255)>.03928?Math.pow((i+.055)/1.055,2.4):i/12.92})))[0]+.7152*r[1]+.0722*r[2])>t?"#0E0E0F":"#FFFFFF"},d={log:function(){},error:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.error.apply(console,i)},warn:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.warn.apply(console,i)},info:function(){}};d.log("Raw API_URL:","https://stage-api.robylon.ai");var u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};d.log("CONFIG",u);var l,c,h=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},v=function(){return{copilotUrl:u.copilotUrl||"https://app.robylon.ai",environment:u.environment||"production",apiUrl:u.apiUrl||"https://app.robylon.ai"}};!function(i){i.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",i.CHATBOT_BUTTON_CLICKED="CHATBOT_BUTTON_CLICKED",i.CHATBOT_OPENED="CHATBOT_OPENED",i.CHATBOT_CLOSED="CHATBOT_CLOSED",i.CHATBOT_APP_READY="CHATBOT_APP_READY",i.CHATBOT_LOADED="CHATBOT_LOADED",i.CHAT_INITIALIZED="CHAT_INITIALIZED",i.SESSION_REFRESHED="SESSION_REFRESHED",i.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED"}(l||(l={})),function(i){i.CHAT_MOVED="CHAT_MOVED",i.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(c||(c={}));var f,p="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",m="21px",w=function(){function i(i){this.resizeObserver=null,this.config=i,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount(),this.setupResizeListener()}return i.prototype.render=function(){var i=this;v().copilotUrl;var t=this.config,n=t.config,e={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97)",transform:t.isIframeVisible?"scale(0.85)":"scale(1)",fontFamily:p};n.launcher_type===o.IMAGE&&Object.assign(e,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:n.brand_colour}),this.applyResponsiveStyles(e),this.buttonElement.className="message-bubble-container",this.buttonElement.innerHTML="",this.buttonElement.appendChild(this.createLauncherElement()),this.buttonElement.onclick=function(){i.config.toggleIframe()}},i.prototype.createLauncherElement=function(){var i,t,n=this.config,e=n.config,r=n.isIframeVisible,s=v().copilotUrl;switch(console.log("config in floating button",e),e.launcher_type){case o.TEXT:return this.createTextLauncher();case o.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case o.IMAGE:default:if(r){var a=document.createElement("div");return a.innerHTML='\n <svg\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n >\n <path\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </svg>\n ',a}var d=document.createElement("img");return d.src=e.launcher_type?(null===(t=null===(i=e.images)||void 0===i?void 0:i.launcher_image_url)||void 0===t?void 0:t.url)||"".concat(s,"/chatbubble.png"):e.image_url||"".concat(s,"/chatbubble.png"),d.alt="Chat",Object.assign(d.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),d}},i.prototype.createTextLauncher=function(){var i=this.config.config,t=i.brand_colour,n=i.launcher_properties,o=document.createElement("div");Object.assign(o.style,{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:t,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box"});var e=document.createElement("div");Object.assign(e.style,{flex:"1",minWidth:"0"});var r=document.createElement("p");return Object.assign(r.style,{margin:"0",color:a(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:m,fontFamily:p,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),r.textContent=(null==n?void 0:n.text)||"",e.appendChild(r),o.appendChild(e),o},i.prototype.createTextualImageLauncher=function(){var i,t,n,o,e,r,s=v().copilotUrl,d=this.config.config,u=d.brand_colour,l=d.launcher_properties,c=d.image_url,h=document.createElement("div");Object.assign(h.style,{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:u,display:"flex",alignItems:"center",paddingLeft:"20px",paddingRight:"0",paddingTop:"9px",paddingBottom:"9px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",gap:"8px",boxSizing:"border-box"});var f=document.createElement("div");Object.assign(f.style,{flex:"1",minWidth:"0"});var w=document.createElement("p");Object.assign(w.style,{margin:"0",color:a(u),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:m,fontFamily:p,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),w.textContent=(null==l?void 0:l.text)||"";var b=document.createElement("div");Object.assign(b.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var g=document.createElement("img");return g.src=(null===(t=null===(i=null==this?void 0:this.config)||void 0===i?void 0:i.config)||void 0===t?void 0:t.launcher_type)?(null===(r=null===(e=null===(o=null===(n=null==this?void 0:this.config)||void 0===n?void 0:n.config)||void 0===o?void 0:o.images)||void 0===e?void 0:e.launcher_image_url)||void 0===r?void 0:r.url)||"".concat(s,"/chatbubble.png"):c||"".concat(s,"/chatbubble.png"),g.alt="Chat",Object.assign(g.style,{width:"100%",height:"100%",objectFit:"cover"}),f.appendChild(w),b.appendChild(g),h.appendChild(f),h.appendChild(b),h},i.prototype.applyResponsiveStyles=function(i){var t,n,o,r,s,a,d,u=560>(null===window||void 0===window?void 0:window.innerWidth),l=this.config.config,c="string"==typeof this.config.sideSpacing?""===this.config.sideSpacing||isNaN(+this.config.sideSpacing)?void 0:+this.config.sideSpacing:this.config.sideSpacing,h="string"==typeof this.config.bottomSpacing?""===this.config.bottomSpacing||isNaN(+this.config.bottomSpacing)?void 0:+this.config.bottomSpacing:this.config.bottomSpacing,v=("string"==typeof this.config.position?"left"===this.config.position.toLowerCase()?"Left":"right"===this.config.position.toLowerCase()?"Right":void 0:this.config.position)||(null===(o=l.interface_properties)||void 0===o?void 0:o.position)||"Right",f=null!==(s=null!=c?c:null===(r=l.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,p=null!==(d=null!=h?h:null===(a=l.interface_properties)||void 0===a?void 0:a.bottom_spacing)&&void 0!==d?d:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var m=e(e({},i),u?((t={position:"fixed",bottom:"".concat(p,"px")})[v.toLowerCase()]="".concat(f,"px"),t):((n={bottom:"0"})[v.toLowerCase()]="0",n));Object.assign(this.buttonElement.style,m)},i.prototype.handleResize=function(){var i={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",borderRadius:this.config.config.launcher_type&&this.config.config.launcher_type!==o.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===o.IMAGE&&Object.assign(i,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:this.config.config.brand_colour}),this.applyResponsiveStyles(i)},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.getElement=function(){return this.buttonElement},i.prototype.mount=function(){var i=this;requestAnimationFrame((function(){var t,n;null===(n=(t=i.config).onEvent)||void 0===n||n.call(t,{type:l.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),i.config.onInternalEvent(l.CHATBOT_BUTTON_LOADED)}))},i.prototype.update=function(i){this.config.isIframeVisible,this.config=e(e({},this.config),i),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render()},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},i}(),b=function(){var i;return(null===(i=navigator.userAgentData)||void 0===i?void 0:i.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},g=function(){var i;if(null===(i=navigator.userAgentData)||void 0===i?void 0:i.brands)for(var t=["Chrome","Firefox","Safari","Edge","Opera"],n=0,o=navigator.userAgentData.brands;n<o.length;n++){var e=o[n];if(t.includes(e.brand))return e.brand}return(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},x=function(){var i,t,n,o;return{width:(null===window||void 0===window?void 0:window.innerWidth)||(null===(i=null===document||void 0===document?void 0:document.documentElement)||void 0===i?void 0:i.clientWidth)||(null===(t=null===document||void 0===document?void 0:document.body)||void 0===t?void 0:t.clientWidth),height:(null===window||void 0===window?void 0:window.innerHeight)||(null===(n=null===document||void 0===document?void 0:document.documentElement)||void 0===n?void 0:n.clientHeight)||(null===(o=null===document||void 0===document?void 0:document.body)||void 0===o?void 0:o.clientHeight)}},I=function(){return{platform:"web",os:b(),browser:g(),sdk_version:"1.1.40-staging.1",device:(i=navigator.userAgent.toLowerCase(),/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(i)?"tablet":/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(i)?"mobile":"desktop"),screen_size:x()};var i};!function(i){i.ERROR="ERROR",i.INFO="INFO"}(f||(f={}));var y,E=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],_=function(i){var t=i.filename,n=i.stack,o=i.message;return!!(t||n||o)&&E.some((function(i){return(null==t?void 0:t.includes(i))||(null==n?void 0:n.includes(i))||(null==o?void 0:o.includes(i))}))},T=function(){function i(){var i=this;this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.handleWindowError=function(t){var n,o={filename:t.filename,stack:null===(n=t.error)||void 0===n?void 0:n.stack,message:t.message};_(o)&&i.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})},this.handleUnhandledRejection=function(t){var n,o,e={stack:null===(n=t.reason)||void 0===n?void 0:n.stack,message:(null===(o=t.reason)||void 0===o?void 0:o.message)||t.reason+""};_(e)&&i.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return i.prototype.setupGlobalHandlers=function(){h()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},i.prototype.cleanup=function(){h()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},i.getInstance=function(){return i.instance||(i.instance=new i),i.instance},i.prototype.initialize=function(i,t){void 0===t&&(t=null);try{if(this.preInitQueue.length>0){var n={org_id:"UNINITALIZED",event_data:{message:"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i)),componentName:"ErrorTrackingService",additionalInfo:{preInitError:!0,apiKey:i,userId:t,timestamp:Date.now()},timestamp:Date.now()},metadata:I(),event_type:f.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=i,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){d.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:Error(n+""),componentName:"ErrorTrackingService",additionalInfo:{apiKey:i,userId:t}})}},i.prototype.processPreInitQueue=function(){return r(this,void 0,void 0,(function(){var i,t,n;return s(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];d.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),i=0,t=this.preInitQueue,o.label=1;case 1:return i<t.length?(n=t[i],[4,this.trackError(n.error,n.componentName,e(e({},n.additionalInfo),{preInitError:!0}))]):[3,4];case 2:o.sent(),o.label=3;case 3:return i++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},i.prototype.sendLog=function(i){return r(this,void 0,void 0,(function(){var t,n,o,e,r,a;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=v().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 1:return(n=s.sent()).ok?[3,3]:(e=(o=d).error,r=["Failed to send error log:"],[4,n.text()]);case 2:e.apply(o,r.concat([s.sent()])),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),d.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},i.prototype.trackError=function(i,t,n){return r(this,void 0,void 0,(function(){var o,r,a;return s(this,(function(s){switch(s.label){case 0:if(this.isInitialized)return[3,5];o={org_id:"UNINITALIZED",event_data:{message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:e(e({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:I(),event_type:f.ERROR,user_id:this.userId},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return s.sent(),[3,4];case 3:return s.sent(),this.preInitQueue.push({error:i,componentName:t,additionalInfo:n}),d.warn("Error tracked before initialization, queuing:",i),[3,4];case 4:return[2];case 5:return r={message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:e(e({},n),{timestamp:Date.now()}),timestamp:Date.now()},a={org_id:this.apiKey||"UNINITALIZED",event_data:r,metadata:I(),event_type:f.ERROR,user_id:this.userId},[4,this.sendLog(a)];case 6:return s.sent(),[2]}}))}))},i.prototype.trackInfo=function(i,t,n){return r(this,void 0,void 0,(function(){var o,e;return s(this,(function(r){switch(r.label){case 0:return this.apiKey?(o={message:i,componentName:t,additionalInfo:n,timestamp:Date.now()},e={org_id:this.apiKey,event_data:o,metadata:I(),event_type:f.INFO,user_id:this.userId},[4,this.sendLog(e)]):(d.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},i}(),S=T.getInstance(),A="MISSING_API_KEY",O="SDK_INIT_FAILED",R="ERROR_TRACKING_INIT_FAILED",C="API_REQUEST_FAILED",k="NETWORK_ERROR",D="INVALID_RESPONSE",j="IFRAME_LOAD_FAILED",z="INITIALIZATION_ERROR",M=((y={})[A]=function(i){return"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i),". A valid API key string is required to initialize the SDK.")},y.INVALID_API_KEY=function(i){return"SDK Initialization Failed: Provided API key '".concat(i,"' is invalid. API key must be a non-empty string in UUID format.")},y.CONFIG_FETCH_FAILED=function(i){return"Failed to fetch chatbot configuration: ".concat(i.statusCode?"Server responded with status ".concat(i.statusCode):"Could not reach server").concat(i.error?". Error: ".concat(i.error):"")},y[C]=function(i,t,n){return"API Request Failed: Server responded with status ".concat(i," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},y[k]=function(i){return"Network Error: Failed to communicate with server".concat(i.url?" at ".concat(i.url):"").concat(i.error?" - ".concat(i.error):"")},y[j]=function(i){return"Failed to load chatbot interface".concat(i.src?" from ".concat(i.src):"").concat(i.error?". Error: ".concat(i.error):"")},y[D]=function(i){return"Invalid API Response: Missing required fields in response data: ".concat(i.join(", "))},y[R]=function(i){return"Error Tracking Service initialization failed".concat(i.apiKey?" for API key ".concat(i.apiKey):"").concat(i.error?". Error: ".concat(i.error):"")},y[O]=function(i){return"SDK Initialization Failed: ".concat(i.reason||"Could not initialize the chatbot SDK").concat(i.config?". Attempted initialization with config: ".concat(JSON.stringify(i.config,null,2)):"")},y.COOKIE_ACCESS_ERROR=function(i,t){return"Cookie Access Error: Failed to ".concat(i).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},y.COMPONENT_RENDER_ERROR=function(i){return"React Component Error: ".concat(i.component||"Unknown component"," failed to render. Error: ").concat(i.error).concat(i.stack?"\nComponent Stack: ".concat(i.stack):"")},y),N=function(){function i(i){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(i){var n,o,e,r,s,a,d,u,h,f,p,m,w,b,g,x=v().copilotUrl;if(i.origin===x){if("closeChatbot"===i.data)return void t.config.onClose();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=i.data)||void 0===n?void 0:n.type))return void t.config.onInternalEvent(c.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(o=i.data)||void 0===o?void 0:o.type)&&(null===(r=(e=t.config).onEvent)||void 0===r||r.call(e,{type:l.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(s=i.data)||void 0===s?void 0:s.type)&&(null===(d=(a=t.config).onEvent)||void 0===d||d.call(a,{type:l.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(u=i.data)||void 0===u?void 0:u.type)&&(null===(f=(h=t.config).onEvent)||void 0===f||f.call(h,{type:l.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZATION_FAILED,{error:null===(p=i.data)||void 0===p?void 0:p.error})),"SESSION_REFRESHED"===(null===(m=i.data)||void 0===m?void 0:m.type)&&(null===(b=(w=t.config).onEvent)||void 0===b||b.call(w,{type:l.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(l.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=i.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(c.CHAT_MOVED,{from:i.data.from,to:i.data.to,trigger:i.data.trigger})}},this.config=i,this.iframeElement=document.createElement("iframe"),this.iframeElement.id="chat-iframe-rbyln",this.resizeHandler=this.applyResponsiveStyles.bind(this),this.render(),this.initialize(),this.setupEventListeners()}return i.prototype.getElement=function(){return this.iframeElement},i.prototype.render=function(){var i,t=(null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.position)||"Right";Object.assign(this.iframeElement.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(t.toLowerCase()),transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 0.15s ease-out",transform:"scale(0.3) translate3d(0,40px,0)",opacity:"0",display:"none"}),this.applyResponsiveStyles()},i.prototype.applyResponsiveStyles=function(){var i,t,n,o,e;if(this.iframeElement){var r=null!==(o=null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.bottom_spacing)&&void 0!==o?o:20,s=(null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.position)||"Right";560>window.innerWidth?Object.assign(this.iframeElement.style,((i={width:"100vw",minWidth:"300px"})[s.toLowerCase()]="0",i.bottom="0",i.height="100vh",i.flexDirection="column",i.flexGrow="1",i.borderRadius="0",i.top="0",i.maxHeight="100%",i.position="fixed",i)):Object.assign(this.iframeElement.style,((t={width:"26%",minWidth:"400px",height:"calc(100vh - 2rem - 10vh - ".concat(r,"px)"),borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"50rem",position:""})[s.toLowerCase()]=void 0,t))}},i.prototype.initialize=function(){var i=this;if(!this.isInitialized){var t=v().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,o,e=new URL(i.iframeElement.src).origin||t;null===(n=i.iframeElement.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},e)}))}},i.prototype.setupEventListeners=function(){var i=this;window.addEventListener("resize",this.resizeHandler),this.iframeElement.addEventListener("error",(function(){S.trackError(Error(M[j]({src:i.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:j,errorType:"RUNTIME_ERROR",context:{config:i.config.config,iframeUrl:i.iframeElement.src,timestamp:Date.now()}})})),window.addEventListener("message",this.handleMessage)},i.prototype.updateVisibility=function(i){var t,n,o,e,r,s,a,d,u,c=this;this.config.isVisible=i;var h=(null===(t=this.config.config.interface_properties)||void 0===t?void 0:t.position)||"Right";if(i?(this.iframeElement.style.display="block",this.iframeElement.getBoundingClientRect(),this.iframeElement.style.opacity="1",this.iframeElement.style.transform="scale(1) translate3d(0,0,0)"):(this.iframeElement.style.opacity="0",this.iframeElement.style.transform="scale(0.3) translate3d(".concat((h.toLowerCase(),"0"),",40px,0)"),setTimeout((function(){c.config.isVisible||(c.iframeElement.style.display="none")}),200)),this.iframeElement.contentWindow&&i){var f=v().copilotUrl,p=new URL(this.iframeElement.src).origin||f;this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},p),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,action:"registerUserId",data:{userId:null===(e=this.config.config)||void 0===e?void 0:e.userId,token:null===(r=this.config.config)||void 0===r?void 0:r.token,userProfile:null===(s=this.config.config)||void 0===s?void 0:s.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},p),this.hasRegistered=!0),null===(u=(d=this.config).onEvent)||void 0===u||u.call(d,{type:l.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(l.CHATBOT_OPENED)}},i.prototype.update=function(i){var t=this.config.isVisible;if(this.config=e(e({},this.config),i),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=v().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},i.prototype.destroy=function(){window.removeEventListener("resize",this.resizeHandler),window.removeEventListener("message",this.handleMessage),this.iframeElement&&this.iframeElement.parentNode&&this.iframeElement.parentNode.removeChild(this.iframeElement)},i}(),U=function(){function i(i){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config=i,this.render(),this.mount(),this.setupResizeListener()}return i.prototype.render=function(){this.applyStyles(),this.containerElement.className="robylon-chatbot-container"},i.prototype.applyStyles=function(){var i,t,n,o,r,s,a,d=560>(null===window||void 0===window?void 0:window.innerWidth),u=(null===(n=this.config.interface_properties)||void 0===n?void 0:n.position)||"Right",l=null!==(r=null===(o=this.config.interface_properties)||void 0===o?void 0:o.side_spacing)&&void 0!==r?r:20,c=null!==(a=null===(s=this.config.interface_properties)||void 0===s?void 0:s.bottom_spacing)&&void 0!==a?a:20;this.containerElement.style.position="",this.containerElement.style.top="",this.containerElement.style.bottom="",this.containerElement.style.right="",this.containerElement.style.left="",this.containerElement.style.alignItems="";var h={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},v=e(e({},h),((i={bottom:"".concat(c,"px")})[u.toLowerCase()]="".concat(l,"px"),i.alignItems="Right"===u?"flex-end":"flex-start",i)),f=e(e({},h),((t={top:"0"})[u.toLowerCase()]="".concat(l,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,d?f:v)},i.prototype.handleResize=function(){this.applyStyles()},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.mount=function(){document.body.appendChild(this.containerElement)},i.prototype.getElement=function(){return this.containerElement},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.containerElement&&this.containerElement.parentNode&&this.containerElement.parentNode.removeChild(this.containerElement)},i}(),F=function(i){var t=i?"USER_DATA=%7B%22attributes%22%3A%5B%7B%22key%22%3A%22USER_ATTRIBUTE_USER_EMAIL%22%2C%22value%22%3A%22dinesh.goel%40robylon.ai%22%7D%2C%7B%22key%22%3A%22USER_ATTRIBUTE_UNIQUE_ID%22%2C%22value%22%3A%2266011f2c28d1787d13c6c796%22%7D%5D%2C%22subscribedToOldSdk%22%3Afalse%2C%22deviceUuid%22%3A%2226c02feb-2664-451d-8469-9cf1378547c6%22%2C%22deviceAdded%22%3Atrue%7D; _ga_3YS9P6ZDWX=GS1.1.1715252584.3.1.1715258696.39.0.0; _ga_V4J24F7YF9=GS1.1.1715273274.2.0.1715273274.0.0.0; city_name=Bengaluru; lang_code=en-in; cookieConcent=A; _gcl_au=1.1.343275043.1717154298; _clck=43guwd%7C2%7Cfmi%7C0%7C1561; _gid=GA1.2.1423066649.1718210058; moe_uuid=26c02feb-2664-451d-8469-9cf1378547c6; _ga_6RM65PWEZY=GS1.1.1718210058.18.1.1718211647.60.0.0; _ga=GA1.1.689213983.1712737672; AMP_MKTG_fe4beb374f=JTdCJTIycmVmZXJyZXIlMjIlM0ElMjJodHRwcyUzQSUyRiUyRmFjY291bnRzLnRlYWNobWludC5jb20lMkYlMjIlMkMlMjJyZWZlcnJpbmdfZG9tYWluJTIyJTNBJTIyYWNjb3VudHMudGVhY2htaW50LmNvbSUyMiU3RA==; AMP_fe4beb374f=JTdCJTIyZGV2aWNlSWQlMjIlM0ElMjI0MWMxMTljZC03YzVjLTRiYTctYTUzZS1mYTgzMjRlYjc0OWUlMjIlMkMlMjJ1c2VySWQlMjIlM0ElMjIxZjI2ODAwOC01OGYxLTQwYTItYjQ0Ni1mYmQ5N2E0NDQyYTAlMjIlMkMlMjJzZXNzaW9uSWQlMjIlM0ExNzE4MjEzMzEwOTc3JTJDJTIyb3B0T3V0JTIyJTNBZmFsc2UlMkMlMjJsYXN0RXZlbnRUaW1lJTIyJTNBMTcxODIxMzMxMDk4MSUyQyUyMmxhc3RFdmVudElkJTIyJTNBMTQlN0Q=; _ga_3YS9P6ZDWX=GS1.1.1718211637.26.1.1718213441.60.0.0; SESSION=%7B%22sessionKey%22%3A%22e4d76f52-9053-4277-99a4-f1ba667fd5f2%22%2C%22sessionStartTime%22%3A%222024-06-12T16%3A34%3A19.047Z%22%2C%22sessionMaxTime%22%3A1800%2C%22customIdentifiersToTrack%22%3A%5B%5D%2C%22sessionExpiryTime%22%3A1718215247464%2C%22numberOfSessions%22%3A17%7D":document.cookie;return t=t.split(";").map((function(i){var t=i.split("="),n=t[0],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},L=function(i,t,n){return r(void 0,void 0,void 0,(function(){var o,e,r,a,u,l,c;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),o=v().apiUrl,d.log("endpointUrl",e="".concat(o,"/chat/chatbot/get/")),[4,fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_user_id:t||null,org_id:i,token:n||void 0,extra_info:{}})})];case 1:return(r=s.sent()).ok?[3,3]:[4,r.text()];case 2:throw a=s.sent(),Error(M[C](r.status,a));case 3:return[4,r.json()];case 4:if(u=s.sent(),!(null===(c=null==u?void 0:u.user)||void 0===c?void 0:c.org_info))throw Error(M[D](["user","org_info"]));return[2,u];case 5:throw l=s.sent(),S.trackError(l instanceof Error?l:Error(M[k]({error:l+""})),"fetchChatbotConfig",{errorCode:l instanceof Error&&l.message.includes("API Request Failed")?C:k,errorType:"API_ERROR",context:{apiKey:i,userId:t,timestamp:Date.now()}}),l;case 6:return[2]}}))}))},W=function(i){return r(void 0,void 0,void 0,(function(){var r,a,d,u,l,c,h,v,f,p,m,w,b,g,x,y,E,_,T,S,A,O,R,C,k,D,j;return s(this,(function(s){switch(s.label){case 0:return r=function(i){return{api_key:(i.api_key||"")+"",user_id:i.user_id?i.user_id+"":null,user_token:i.user_token?i.user_token+"":void 0,user_profile:i.user_profile||{}}}(i),a=r.user_id||void 0,d=!1,a||(a=function(){var i,t="; ".concat(document.cookie).split("; rblyn_anon=");if(2===t.length)return null===(i=t.pop())||void 0===i?void 0:i.split(";").shift()}()||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var t=16*Math.random()|0;return("x"===i?t:3&t|8).toString(16)})),M=a,(N=new Date).setTime(N.getTime()+31536e6),document.cookie="".concat("rblyn_anon","=").concat(M,";expires=").concat(N.toUTCString(),";path=/"),d=!0),[4,L(r.api_key,a,r.user_token)];case 1:return u=s.sent(),l=I(),z=r.user_profile,c=z?Object.fromEntries(Object.entries(z).map((function(i){var t=i[0],n=i[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,n+""]}))):{},h=e(e({},l),c),[2,{chatbotId:r.api_key,userId:a,token:r.user_token,isAnonymous:d,domain:"",brand_colour:(null===(f=null===(v=u.user.org_info.brand_config)||void 0===v?void 0:v.colors)||void 0===f?void 0:f.brand_color)||"",image_url:(null===(m=null===(p=u.user.org_info)||void 0===p?void 0:p.brand_config)||void 0===m?void 0:m.launcher_logo_url)||"",userProfile:h,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(w=u.user.org_info.brand_config)||void 0===w?void 0:w.display_name)||"",welcome_message:(null===(b=u.user.org_info.brand_config)||void 0===b?void 0:b.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(g=u.user.org_info.brand_config)||void 0===g?void 0:g.redirect_url)||""},launcher_type:(null===(x=u.user.org_info.brand_config)||void 0===x?void 0:x.launcher_type)||o.IMAGE,launcher_properties:{text:(null===(E=null===(y=u.user.org_info.brand_config)||void 0===y?void 0:y.launcher_properties)||void 0===E?void 0:E.text)||""},images:{launcher_image_url:{url:(null===(S=null===(T=null===(_=u.user.org_info.brand_config)||void 0===_?void 0:_.images)||void 0===T?void 0:T.launcher_image_url)||void 0===S?void 0:S.url)||""}},interface_properties:{position:(null===(O=null===(A=u.user.org_info.brand_config)||void 0===A?void 0:A.interface_properties)||void 0===O?void 0:O.position)||n.RIGHT,side_spacing:(null===(C=null===(R=u.user.org_info.brand_config)||void 0===R?void 0:R.interface_properties)||void 0===C?void 0:C.side_spacing)||20,bottom_spacing:(null===(D=null===(k=u.user.org_info.brand_config)||void 0===k?void 0:k.interface_properties)||void 0===D?void 0:D.bottom_spacing)||20},interface_type:(null===(j=u.user.org_info.brand_config)||void 0===j?void 0:j.interface_type)||t.WIDGET}]}var z,M,N}))}))},P=function(){function i(i){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=i,this.validateDomain()&&this.init(),null===window||void 0===window||window.addEventListener("message",this.onCloseListener.bind(this),!1)}return i.prototype.onCloseListener=function(i){i.origin===this.config.domain&&"closeChatbot"===i.data&&this.closeIframe()},i.prototype.validateDomain=function(){var i,t=this.config.domain,n=null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.origin;return d.log("expectedDomain, to current domain",t,n,t===n),t===n},i.prototype.createChatBubblContainer=function(){var i,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var o=document.createElement("div");o.classList.add("close-btn"),o.textContent="✕",Object.assign(o.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(i=this.config.chat_interface_config)||void 0===i?void 0:i.chat_bubble_prompts)||[]).forEach((function(i){var o=t.createMessageBubble(i);n.appendChild(o)})),n.appendChild(o),document.body.appendChild(n)},i.prototype.createMessageBubble=function(i){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=i,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var o=document.createElement("button");return o.innerHTML="×",Object.assign(o.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),o.addEventListener("click",(function(){t.remove()})),t.appendChild(o),t.appendChild(n),t},i.prototype.createFloatingButton=function(){var i=document.createElement("div");i.classList.add("message-bubble-container"),Object.assign(i.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:a(this.config.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),document.body.appendChild(i),this.logoContainer=i,this.loadImage(this.logoContainer),this.createChatBubblContainer(),this.logoContainer.addEventListener("click",this.toggleIframe.bind(this))},i.prototype.loadImage=function(i){var t,n,o=document.createElement("img");o.src=this.config.launcher_type?(null===(n=null===(t=this.config.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(this.config.domain,"/chatbubble.png"):this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),o.alt="Chat",Object.assign(o.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=o,i.innerHTML="",i.appendChild(o)},i.prototype.createIframe=function(){var i=this;d.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),d.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){560>(null===window||void 0===window?void 0:window.innerWidth)?Object.assign(t.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(t.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"})};n(),null===window||void 0===window||window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o,e,r;if(i.iframe){var s=new URL(i.iframe.src).origin||i.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},s),null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hostname,action:"registerUserId",data:{userId:i.config.userId,token:i.config.token,userProfile:i.config.userProfile}},s)}})),null===window||void 0===window||window.addEventListener("message",(function(n){var o,e;if(n.origin===i.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===i.config.chatbotId,s={cookies:F(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname};null===(e=t.contentWindow)||void 0===e||e.postMessage(s,i.config.domain||"*")}"expand"===n.data&&(i.adjustIframeWidth(),t.style.height="calc(100vh - 120px)",t.style.bottom="86px"),"collapse"===n.data&&Object.assign(t.style,{width:"26%",height:"calc(100vh - 32px - 10vh)",bottom:"86px",top:"calc(32px + 10vh)"})}}))},i.prototype.adjustIframeWidth=function(){if(this.iframe){var i=null===window||void 0===window?void 0:window.innerWidth;d.log("screenWidth",i),this.iframe.style.width=832>i?"".concat(i-64,"px"):"800px"}},i.prototype.loadSvgInline=function(i){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");i.innerHTML="",n&&i.appendChild(n)},i.prototype.toggleIcon=function(i,t){"block"===t.style.display?this.loadSvgInline(i):this.loadImage(i)},i.prototype.toggleIframe=function(){var i;if(d.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;d.log("toggleIframe"),null===(i=this.iframe.contentWindow)||void 0===i||i.postMessage({domain:null===window||void 0===window?void 0:window.location.hostname,name:"none"===this.iframe.style.display?"openFrame":"closeFrame"},t),this.iframe.style.display="none"===this.iframe.style.display?"block":"none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="block"===this.iframe.style.display?"none":"cover",this.bubblePromptContainer&&(this.bubblePromptContainer.style.display="none"),d.log("this.bubblePromptContainer",this.bubblePromptContainer)}},i.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},i.prototype.init=function(){this.createIframe(),this.createFloatingButton()},i}(),H=function(i){var t={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},n=[],o=function(i){t=e(e({},t),i),n.forEach((function(i){return i(t)}))};return{getState:function(){return t},initialize:function(){return r(void 0,void 0,void 0,(function(){var t,n,e;return s(this,(function(r){switch(r.label){case 0:if(!i.api_key)return S.trackError(Error(M[A](i.api_key)),"ChatbotStateManager",{errorCode:A,errorType:z,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,W(i)];case 2:return t=r.sent(),[4,new Promise((function(i,n){!function(n,e,r){if(n.chatbotId&&n.userId)try{new P(n),o({isInitialized:!0,chatbotConfig:t}),i(),d.log("Robylon SDK initialized successfully.")}catch(i){r(i instanceof Error?i.message:"Failed to initialize SDK")}else r("Incomplete configuration for SDK initialization.")}(t,0,(function(i){n(i)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),e=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:e}),S.trackError(n instanceof Error?n:Error(e),"ChatbotStateManager",{errorCode:O,errorType:z,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!t.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o,subscribe:function(i){return n.push(i),function(){var t=n.indexOf(i);t>-1&&n.splice(t,1)}},unsubscribe:function(i){var t=n.indexOf(i);t>-1&&n.splice(t,1)}}},B=function(i){i.api_key,i.user_profile;var t=i.onEvent;return i.chatbotConfig,{emit:function(i,n){var o={type:i,timestamp:Date.now(),data:n};null==t||t(o)},onInternalEvent:function(i,t){}}},J=function(){function i(i){var t=this;if(this.container=null,this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(i){if(!t.isDestroyed){var n=i.isInitialized,o=i.error,e=i.chatbotConfig,r=i.isIframeVisible;if(!o&&e&&n){if(t.eventEmitter=B({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:e.isAnonymous,userId:e.userId}}),t.container||(t.container=new U(e)),t.iframe)t.iframe.update({config:e,isVisible:r});else if(t.iframe=new N({config:e,isVisible:r,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var s=t.iframe.getElement();s&&t.container&&t.container.getElement().prepend(s)}if(t.floatingButton)t.floatingButton.update({config:e,isIframeVisible:r});else if(t.floatingButton=new w({config:e,toggleIframe:t.toggleIframe,isIframeVisible:r,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var a=t.floatingButton.getElement();a&&t.container&&t.container.getElement().appendChild(a)}}}},this.toggleIframe=function(){var i=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(i.isIframeVisible?l.CHATBOT_CLOSED:l.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(l.CHATBOT_CLOSED)},this.config=i,!i.api_key)throw S.trackError(Error(M[A](i.api_key)),"RobylonChatbot",{errorCode:A,errorType:z,context:{timestamp:Date.now()}}),Error("API key is required");try{S.initialize(i.api_key,i.user_id)}catch(i){S.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot",{errorCode:R,errorType:z,context:{timestamp:Date.now()}})}this.stateManager=H({api_key:i.api_key,user_id:i.user_id,user_token:i.user_token,user_profile:i.user_profile}),this.eventEmitter=B({api_key:i.api_key,user_profile:i.user_profile,onEvent:i.onEvent,chatbotConfig:null}),this.initialize()}return i.prototype.initialize=function(){return r(this,void 0,void 0,(function(){var i;return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.stateManager.initialize()];case 1:return t.sent(),this.stateManager.subscribe(this.handleStateChange),this.handleStateChange(this.stateManager.getState()),[3,3];case 2:return i=t.sent(),S.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot.initialize",{errorCode:O,errorType:z,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},i.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(l.CHATBOT_BUTTON_CLICKED))},i.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(l.CHATBOT_CLOSED))},i.prototype.toggle=function(){this.toggleIframe()},i.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null),this.container&&(this.container.destroy(),this.container=null),this.stateManager.unsubscribe(this.handleStateChange)},i.prototype.getState=function(){return this.stateManager.getState().isInitialized?"initialized":"uninitialized"},i}();function Z(i){return new J(i)}"undefined"!=typeof window&&function(){if("undefined"!=typeof window){var i=window.RobylonChatbot;if(i&&Array.isArray(i.q)){var t=null;i.q.forEach((function(i){var n=i[0];if("init"===n){var o=i[1]||{};t=Z(o)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(i){for(var n,o=[],e=1;arguments.length>e;e++)o[e-1]=arguments[e];return"init"===i?t=Z(o[0]||{}):t&&"function"==typeof t[i]?(n=t)[i].apply(n,o):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var Y={create:Z,getState:function(){return"initialized"}};i.create=Z,i.default=Y,Object.defineProperty(i,"i",{value:!0})}));
|
|
1
|
+
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((i="undefined"!=typeof globalThis?globalThis:i||self).RobylonChatbot={})}(this,(function(i){"use strict";var t,n,o,e=function(){return e=Object.assign||function(i){for(var t,n=1,o=arguments.length;o>n;n++)for(var e in t=arguments[n])({}).hasOwnProperty.call(t,e)&&(i[e]=t[e]);return i},e.apply(this,arguments)};function r(i,t,n,o){return new(n||(n=Promise))((function(e,r){function s(i){try{d(o.next(i))}catch(i){r(i)}}function a(i){try{d(o.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?e(i.value):(t=i.value,t instanceof n?t:new n((function(i){i(t)}))).then(s,a)}d((o=o.apply(i,t||[])).next())}))}function s(i,t){var n,o,e,r={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(d){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(r=0)),r;)try{if(n=1,o&&(e=2&a[0]?o.return:a[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,a[1])).done)return e;switch(o=0,e&&(a=[2&a[0],e.value]),a[0]){case 0:case 1:e=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,o=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!((e=(e=r.trys).length>0&&e[e.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!e||a[1]>e[0]&&a[1]<e[3])){r.label=a[1];break}if(6===a[0]&&r.label<e[1]){r.label=e[1],e=a;break}if(e&&r.label<e[2]){r.label=e[2],r.ops.push(a);break}e[2]&&r.ops.pop(),r.trys.pop();continue}a=t.call(i,r)}catch(i){a=[6,i],o=0}finally{n=e=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,d])}}}"function"==typeof SuppressedError&&SuppressedError,function(i){i.WIDGET="WIDGET",i.POPOVER="POPOVER",i.EMBED="EMBED"}(t||(t={})),function(i){i.RIGHT="Right",i.LEFT="Left"}(n||(n={})),function(i){i.TEXT="TEXT",i.IMAGE="IMAGE",i.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(o||(o={}));var a=function(i,t){void 0===t&&(t=.5);var n,o,e,r,s=function(i){i=i.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(i,t,n,o){return t+t+n+n+o+o}));var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}}(i);return(n=s.r,o=s.g,e=s.b,.2126*(r=[n,o,e].map((function(i){return(i/=255)>.03928?Math.pow((i+.055)/1.055,2.4):i/12.92})))[0]+.7152*r[1]+.0722*r[2])>t?"#0E0E0F":"#FFFFFF"},d={log:function(){},error:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.error.apply(console,i)},warn:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.warn.apply(console,i)},info:function(){}};d.log("Raw API_URL:","https://stage-api.robylon.ai");var u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};d.log("CONFIG",u);var l,c,h=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},v=function(){return{copilotUrl:u.copilotUrl||"https://app.robylon.ai",environment:u.environment||"production",apiUrl:u.apiUrl||"https://app.robylon.ai"}};!function(i){i.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",i.CHATBOT_BUTTON_CLICKED="CHATBOT_BUTTON_CLICKED",i.CHATBOT_OPENED="CHATBOT_OPENED",i.CHATBOT_CLOSED="CHATBOT_CLOSED",i.CHATBOT_APP_READY="CHATBOT_APP_READY",i.CHATBOT_LOADED="CHATBOT_LOADED",i.CHAT_INITIALIZED="CHAT_INITIALIZED",i.SESSION_REFRESHED="SESSION_REFRESHED",i.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED"}(l||(l={})),function(i){i.CHAT_MOVED="CHAT_MOVED",i.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(c||(c={}));var f,p="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",m="21px",w=function(){function i(i){this.resizeObserver=null,this.config=i,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount(),this.setupResizeListener()}return i.prototype.render=function(){var i=this;v().copilotUrl;var t=this.config,n=t.config,e={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97)",transform:t.isIframeVisible?"scale(0.85)":"scale(1)",fontFamily:p};n.launcher_type===o.IMAGE&&Object.assign(e,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:n.brand_colour}),this.applyResponsiveStyles(e),this.buttonElement.className="message-bubble-container",this.buttonElement.innerHTML="",this.buttonElement.appendChild(this.createLauncherElement()),this.buttonElement.onclick=function(){i.config.toggleIframe()}},i.prototype.createLauncherElement=function(){var i,t,n=this.config,e=n.config,r=n.isIframeVisible,s=v().copilotUrl;switch(console.log("config in floating button",e),e.launcher_type){case o.TEXT:return this.createTextLauncher();case o.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case o.IMAGE:default:if(r){var a=document.createElement("div");return a.innerHTML='\n <svg\n width="24"\n height="24"\n viewBox="0 0 24 24"\n fill="none"\n xmlns="http://www.w3.org/2000/svg"\n >\n <path\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </svg>\n ',a}var d=document.createElement("img");return d.src=e.launcher_type?(null===(t=null===(i=e.images)||void 0===i?void 0:i.launcher_image_url)||void 0===t?void 0:t.url)||"".concat(s,"/chatbubble.png"):e.image_url||"".concat(s,"/chatbubble.png"),d.alt="Chat",Object.assign(d.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),d}},i.prototype.createTextLauncher=function(){var i=this.config.config,t=i.brand_colour,n=i.launcher_properties,o=document.createElement("div");Object.assign(o.style,{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:t,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box"});var e=document.createElement("div");Object.assign(e.style,{flex:"1",minWidth:"0"});var r=document.createElement("p");return Object.assign(r.style,{margin:"0",color:a(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:m,fontFamily:p,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),r.textContent=(null==n?void 0:n.text)||"",e.appendChild(r),o.appendChild(e),o},i.prototype.createTextualImageLauncher=function(){var i,t,n,o,e,r,s=v().copilotUrl,d=this.config.config,u=d.brand_colour,l=d.launcher_properties,c=d.image_url,h=document.createElement("div");Object.assign(h.style,{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:u,display:"flex",alignItems:"center",paddingLeft:"20px",paddingRight:"0",paddingTop:"9px",paddingBottom:"9px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",gap:"8px",boxSizing:"border-box"});var f=document.createElement("div");Object.assign(f.style,{flex:"1",minWidth:"0"});var w=document.createElement("p");Object.assign(w.style,{margin:"0",color:a(u),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:m,fontFamily:p,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),w.textContent=(null==l?void 0:l.text)||"";var b=document.createElement("div");Object.assign(b.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var g=document.createElement("img");return g.src=(null===(t=null===(i=null==this?void 0:this.config)||void 0===i?void 0:i.config)||void 0===t?void 0:t.launcher_type)?(null===(r=null===(e=null===(o=null===(n=null==this?void 0:this.config)||void 0===n?void 0:n.config)||void 0===o?void 0:o.images)||void 0===e?void 0:e.launcher_image_url)||void 0===r?void 0:r.url)||"".concat(s,"/chatbubble.png"):c||"".concat(s,"/chatbubble.png"),g.alt="Chat",Object.assign(g.style,{width:"100%",height:"100%",objectFit:"cover"}),f.appendChild(w),b.appendChild(g),h.appendChild(f),h.appendChild(b),h},i.prototype.applyResponsiveStyles=function(i){var t,n,o,r,s,a,d,u=560>(null===window||void 0===window?void 0:window.innerWidth),l=this.config.config,c="string"==typeof this.config.sideSpacing?""===this.config.sideSpacing||isNaN(+this.config.sideSpacing)?void 0:+this.config.sideSpacing:this.config.sideSpacing,h="string"==typeof this.config.bottomSpacing?""===this.config.bottomSpacing||isNaN(+this.config.bottomSpacing)?void 0:+this.config.bottomSpacing:this.config.bottomSpacing,v=("string"==typeof this.config.position?"left"===this.config.position.toLowerCase()?"Left":"right"===this.config.position.toLowerCase()?"Right":void 0:this.config.position)||(null===(o=l.interface_properties)||void 0===o?void 0:o.position)||"Right",f=null!==(s=null!=c?c:null===(r=l.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,p=null!==(d=null!=h?h:null===(a=l.interface_properties)||void 0===a?void 0:a.bottom_spacing)&&void 0!==d?d:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var m=e(e({},i),u?((t={position:"fixed",bottom:"".concat(p,"px")})[v.toLowerCase()]="".concat(f,"px"),t):((n={bottom:"0"})[v.toLowerCase()]="0",n));Object.assign(this.buttonElement.style,m)},i.prototype.handleResize=function(){var i={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",borderRadius:this.config.config.launcher_type&&this.config.config.launcher_type!==o.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===o.IMAGE&&Object.assign(i,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:this.config.config.brand_colour}),this.applyResponsiveStyles(i)},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.getElement=function(){return this.buttonElement},i.prototype.mount=function(){var i=this;requestAnimationFrame((function(){var t,n;null===(n=(t=i.config).onEvent)||void 0===n||n.call(t,{type:l.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),i.config.onInternalEvent(l.CHATBOT_BUTTON_LOADED)}))},i.prototype.update=function(i){this.config.isIframeVisible,this.config=e(e({},this.config),i),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render()},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},i}(),b=function(){var i;return(null===(i=navigator.userAgentData)||void 0===i?void 0:i.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},g=function(){var i;if(null===(i=navigator.userAgentData)||void 0===i?void 0:i.brands)for(var t=["Chrome","Firefox","Safari","Edge","Opera"],n=0,o=navigator.userAgentData.brands;n<o.length;n++){var e=o[n];if(t.includes(e.brand))return e.brand}return(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},x=function(){var i,t,n,o;return{width:(null===window||void 0===window?void 0:window.innerWidth)||(null===(i=null===document||void 0===document?void 0:document.documentElement)||void 0===i?void 0:i.clientWidth)||(null===(t=null===document||void 0===document?void 0:document.body)||void 0===t?void 0:t.clientWidth),height:(null===window||void 0===window?void 0:window.innerHeight)||(null===(n=null===document||void 0===document?void 0:document.documentElement)||void 0===n?void 0:n.clientHeight)||(null===(o=null===document||void 0===document?void 0:document.body)||void 0===o?void 0:o.clientHeight)}},I=function(){return{platform:"web",os:b(),browser:g(),sdk_version:"1.1.40",device:(i=navigator.userAgent.toLowerCase(),/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(i)?"tablet":/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(i)?"mobile":"desktop"),screen_size:x()};var i};!function(i){i.ERROR="ERROR",i.INFO="INFO"}(f||(f={}));var y,E=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],_=function(i){var t=i.filename,n=i.stack,o=i.message;return!!(t||n||o)&&E.some((function(i){return(null==t?void 0:t.includes(i))||(null==n?void 0:n.includes(i))||(null==o?void 0:o.includes(i))}))},T=function(){function i(){var i=this;this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.handleWindowError=function(t){var n,o={filename:t.filename,stack:null===(n=t.error)||void 0===n?void 0:n.stack,message:t.message};_(o)&&i.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})},this.handleUnhandledRejection=function(t){var n,o,e={stack:null===(n=t.reason)||void 0===n?void 0:n.stack,message:(null===(o=t.reason)||void 0===o?void 0:o.message)||t.reason+""};_(e)&&i.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return i.prototype.setupGlobalHandlers=function(){h()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},i.prototype.cleanup=function(){h()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},i.getInstance=function(){return i.instance||(i.instance=new i),i.instance},i.prototype.initialize=function(i,t){void 0===t&&(t=null);try{if(this.preInitQueue.length>0){var n={org_id:"UNINITALIZED",event_data:{message:"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i)),componentName:"ErrorTrackingService",additionalInfo:{preInitError:!0,apiKey:i,userId:t,timestamp:Date.now()},timestamp:Date.now()},metadata:I(),event_type:f.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=i,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){d.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:Error(n+""),componentName:"ErrorTrackingService",additionalInfo:{apiKey:i,userId:t}})}},i.prototype.processPreInitQueue=function(){return r(this,void 0,void 0,(function(){var i,t,n;return s(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];d.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),i=0,t=this.preInitQueue,o.label=1;case 1:return i<t.length?(n=t[i],[4,this.trackError(n.error,n.componentName,e(e({},n.additionalInfo),{preInitError:!0}))]):[3,4];case 2:o.sent(),o.label=3;case 3:return i++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},i.prototype.sendLog=function(i){return r(this,void 0,void 0,(function(){var t,n,o,e,r,a;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=v().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 1:return(n=s.sent()).ok?[3,3]:(e=(o=d).error,r=["Failed to send error log:"],[4,n.text()]);case 2:e.apply(o,r.concat([s.sent()])),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),d.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},i.prototype.trackError=function(i,t,n){return r(this,void 0,void 0,(function(){var o,r,a;return s(this,(function(s){switch(s.label){case 0:if(this.isInitialized)return[3,5];o={org_id:"UNINITALIZED",event_data:{message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:e(e({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:I(),event_type:f.ERROR,user_id:this.userId},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return s.sent(),[3,4];case 3:return s.sent(),this.preInitQueue.push({error:i,componentName:t,additionalInfo:n}),d.warn("Error tracked before initialization, queuing:",i),[3,4];case 4:return[2];case 5:return r={message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:e(e({},n),{timestamp:Date.now()}),timestamp:Date.now()},a={org_id:this.apiKey||"UNINITALIZED",event_data:r,metadata:I(),event_type:f.ERROR,user_id:this.userId},[4,this.sendLog(a)];case 6:return s.sent(),[2]}}))}))},i.prototype.trackInfo=function(i,t,n){return r(this,void 0,void 0,(function(){var o,e;return s(this,(function(r){switch(r.label){case 0:return this.apiKey?(o={message:i,componentName:t,additionalInfo:n,timestamp:Date.now()},e={org_id:this.apiKey,event_data:o,metadata:I(),event_type:f.INFO,user_id:this.userId},[4,this.sendLog(e)]):(d.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},i}(),S=T.getInstance(),A="MISSING_API_KEY",O="SDK_INIT_FAILED",R="ERROR_TRACKING_INIT_FAILED",C="API_REQUEST_FAILED",k="NETWORK_ERROR",D="INVALID_RESPONSE",j="IFRAME_LOAD_FAILED",z="INITIALIZATION_ERROR",M=((y={})[A]=function(i){return"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i),". A valid API key string is required to initialize the SDK.")},y.INVALID_API_KEY=function(i){return"SDK Initialization Failed: Provided API key '".concat(i,"' is invalid. API key must be a non-empty string in UUID format.")},y.CONFIG_FETCH_FAILED=function(i){return"Failed to fetch chatbot configuration: ".concat(i.statusCode?"Server responded with status ".concat(i.statusCode):"Could not reach server").concat(i.error?". Error: ".concat(i.error):"")},y[C]=function(i,t,n){return"API Request Failed: Server responded with status ".concat(i," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},y[k]=function(i){return"Network Error: Failed to communicate with server".concat(i.url?" at ".concat(i.url):"").concat(i.error?" - ".concat(i.error):"")},y[j]=function(i){return"Failed to load chatbot interface".concat(i.src?" from ".concat(i.src):"").concat(i.error?". Error: ".concat(i.error):"")},y[D]=function(i){return"Invalid API Response: Missing required fields in response data: ".concat(i.join(", "))},y[R]=function(i){return"Error Tracking Service initialization failed".concat(i.apiKey?" for API key ".concat(i.apiKey):"").concat(i.error?". Error: ".concat(i.error):"")},y[O]=function(i){return"SDK Initialization Failed: ".concat(i.reason||"Could not initialize the chatbot SDK").concat(i.config?". Attempted initialization with config: ".concat(JSON.stringify(i.config,null,2)):"")},y.COOKIE_ACCESS_ERROR=function(i,t){return"Cookie Access Error: Failed to ".concat(i).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},y.COMPONENT_RENDER_ERROR=function(i){return"React Component Error: ".concat(i.component||"Unknown component"," failed to render. Error: ").concat(i.error).concat(i.stack?"\nComponent Stack: ".concat(i.stack):"")},y),N=function(){function i(i){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(i){var n,o,e,r,s,a,d,u,h,f,p,m,w,b,g,x=v().copilotUrl;if(i.origin===x){if("closeChatbot"===i.data)return void t.config.onClose();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=i.data)||void 0===n?void 0:n.type))return void t.config.onInternalEvent(c.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(o=i.data)||void 0===o?void 0:o.type)&&(null===(r=(e=t.config).onEvent)||void 0===r||r.call(e,{type:l.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(s=i.data)||void 0===s?void 0:s.type)&&(null===(d=(a=t.config).onEvent)||void 0===d||d.call(a,{type:l.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(u=i.data)||void 0===u?void 0:u.type)&&(null===(f=(h=t.config).onEvent)||void 0===f||f.call(h,{type:l.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZATION_FAILED,{error:null===(p=i.data)||void 0===p?void 0:p.error})),"SESSION_REFRESHED"===(null===(m=i.data)||void 0===m?void 0:m.type)&&(null===(b=(w=t.config).onEvent)||void 0===b||b.call(w,{type:l.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(l.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=i.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(c.CHAT_MOVED,{from:i.data.from,to:i.data.to,trigger:i.data.trigger})}},this.config=i,this.iframeElement=document.createElement("iframe"),this.iframeElement.id="chat-iframe-rbyln",this.resizeHandler=this.applyResponsiveStyles.bind(this),this.render(),this.initialize(),this.setupEventListeners()}return i.prototype.getElement=function(){return this.iframeElement},i.prototype.render=function(){var i,t=(null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.position)||"Right";Object.assign(this.iframeElement.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(t.toLowerCase()),transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 0.15s ease-out",transform:"scale(0.3) translate3d(0,40px,0)",opacity:"0",display:"none"}),this.applyResponsiveStyles()},i.prototype.applyResponsiveStyles=function(){var i,t,n,o,e;if(this.iframeElement){var r=null!==(o=null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.bottom_spacing)&&void 0!==o?o:20,s=(null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.position)||"Right";560>window.innerWidth?Object.assign(this.iframeElement.style,((i={width:"100vw",minWidth:"300px"})[s.toLowerCase()]="0",i.bottom="0",i.height="100vh",i.flexDirection="column",i.flexGrow="1",i.borderRadius="0",i.top="0",i.maxHeight="100%",i.position="fixed",i)):Object.assign(this.iframeElement.style,((t={width:"26%",minWidth:"400px",height:"calc(100vh - 2rem - 10vh - ".concat(r,"px)"),borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"50rem",position:""})[s.toLowerCase()]=void 0,t))}},i.prototype.initialize=function(){var i=this;if(!this.isInitialized){var t=v().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,o,e=new URL(i.iframeElement.src).origin||t;null===(n=i.iframeElement.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},e)}))}},i.prototype.setupEventListeners=function(){var i=this;window.addEventListener("resize",this.resizeHandler),this.iframeElement.addEventListener("error",(function(){S.trackError(Error(M[j]({src:i.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:j,errorType:"RUNTIME_ERROR",context:{config:i.config.config,iframeUrl:i.iframeElement.src,timestamp:Date.now()}})})),window.addEventListener("message",this.handleMessage)},i.prototype.updateVisibility=function(i){var t,n,o,e,r,s,a,d,u,c=this;this.config.isVisible=i;var h=(null===(t=this.config.config.interface_properties)||void 0===t?void 0:t.position)||"Right";if(i?(this.iframeElement.style.display="block",this.iframeElement.getBoundingClientRect(),this.iframeElement.style.opacity="1",this.iframeElement.style.transform="scale(1) translate3d(0,0,0)"):(this.iframeElement.style.opacity="0",this.iframeElement.style.transform="scale(0.3) translate3d(".concat((h.toLowerCase(),"0"),",40px,0)"),setTimeout((function(){c.config.isVisible||(c.iframeElement.style.display="none")}),200)),this.iframeElement.contentWindow&&i){var f=v().copilotUrl,p=new URL(this.iframeElement.src).origin||f;this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},p),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,action:"registerUserId",data:{userId:null===(e=this.config.config)||void 0===e?void 0:e.userId,token:null===(r=this.config.config)||void 0===r?void 0:r.token,userProfile:null===(s=this.config.config)||void 0===s?void 0:s.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},p),this.hasRegistered=!0),null===(u=(d=this.config).onEvent)||void 0===u||u.call(d,{type:l.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(l.CHATBOT_OPENED)}},i.prototype.update=function(i){var t=this.config.isVisible;if(this.config=e(e({},this.config),i),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=v().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},i.prototype.destroy=function(){window.removeEventListener("resize",this.resizeHandler),window.removeEventListener("message",this.handleMessage),this.iframeElement&&this.iframeElement.parentNode&&this.iframeElement.parentNode.removeChild(this.iframeElement)},i}(),U=function(){function i(i){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config=i,this.render(),this.mount(),this.setupResizeListener()}return i.prototype.render=function(){this.applyStyles(),this.containerElement.className="robylon-chatbot-container"},i.prototype.applyStyles=function(){var i,t,n,o,r,s,a,d=560>(null===window||void 0===window?void 0:window.innerWidth),u=(null===(n=this.config.interface_properties)||void 0===n?void 0:n.position)||"Right",l=null!==(r=null===(o=this.config.interface_properties)||void 0===o?void 0:o.side_spacing)&&void 0!==r?r:20,c=null!==(a=null===(s=this.config.interface_properties)||void 0===s?void 0:s.bottom_spacing)&&void 0!==a?a:20;this.containerElement.style.position="",this.containerElement.style.top="",this.containerElement.style.bottom="",this.containerElement.style.right="",this.containerElement.style.left="",this.containerElement.style.alignItems="";var h={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},v=e(e({},h),((i={bottom:"".concat(c,"px")})[u.toLowerCase()]="".concat(l,"px"),i.alignItems="Right"===u?"flex-end":"flex-start",i)),f=e(e({},h),((t={top:"0"})[u.toLowerCase()]="".concat(l,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,d?f:v)},i.prototype.handleResize=function(){this.applyStyles()},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.mount=function(){document.body.appendChild(this.containerElement)},i.prototype.getElement=function(){return this.containerElement},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.containerElement&&this.containerElement.parentNode&&this.containerElement.parentNode.removeChild(this.containerElement)},i}(),F=function(i){var t=i?"USER_DATA=%7B%22attributes%22%3A%5B%7B%22key%22%3A%22USER_ATTRIBUTE_USER_EMAIL%22%2C%22value%22%3A%22dinesh.goel%40robylon.ai%22%7D%2C%7B%22key%22%3A%22USER_ATTRIBUTE_UNIQUE_ID%22%2C%22value%22%3A%2266011f2c28d1787d13c6c796%22%7D%5D%2C%22subscribedToOldSdk%22%3Afalse%2C%22deviceUuid%22%3A%2226c02feb-2664-451d-8469-9cf1378547c6%22%2C%22deviceAdded%22%3Atrue%7D; _ga_3YS9P6ZDWX=GS1.1.1715252584.3.1.1715258696.39.0.0; _ga_V4J24F7YF9=GS1.1.1715273274.2.0.1715273274.0.0.0; city_name=Bengaluru; lang_code=en-in; cookieConcent=A; _gcl_au=1.1.343275043.1717154298; _clck=43guwd%7C2%7Cfmi%7C0%7C1561; _gid=GA1.2.1423066649.1718210058; moe_uuid=26c02feb-2664-451d-8469-9cf1378547c6; _ga_6RM65PWEZY=GS1.1.1718210058.18.1.1718211647.60.0.0; _ga=GA1.1.689213983.1712737672; AMP_MKTG_fe4beb374f=JTdCJTIycmVmZXJyZXIlMjIlM0ElMjJodHRwcyUzQSUyRiUyRmFjY291bnRzLnRlYWNobWludC5jb20lMkYlMjIlMkMlMjJyZWZlcnJpbmdfZG9tYWluJTIyJTNBJTIyYWNjb3VudHMudGVhY2htaW50LmNvbSUyMiU3RA==; AMP_fe4beb374f=JTdCJTIyZGV2aWNlSWQlMjIlM0ElMjI0MWMxMTljZC03YzVjLTRiYTctYTUzZS1mYTgzMjRlYjc0OWUlMjIlMkMlMjJ1c2VySWQlMjIlM0ElMjIxZjI2ODAwOC01OGYxLTQwYTItYjQ0Ni1mYmQ5N2E0NDQyYTAlMjIlMkMlMjJzZXNzaW9uSWQlMjIlM0ExNzE4MjEzMzEwOTc3JTJDJTIyb3B0T3V0JTIyJTNBZmFsc2UlMkMlMjJsYXN0RXZlbnRUaW1lJTIyJTNBMTcxODIxMzMxMDk4MSUyQyUyMmxhc3RFdmVudElkJTIyJTNBMTQlN0Q=; _ga_3YS9P6ZDWX=GS1.1.1718211637.26.1.1718213441.60.0.0; SESSION=%7B%22sessionKey%22%3A%22e4d76f52-9053-4277-99a4-f1ba667fd5f2%22%2C%22sessionStartTime%22%3A%222024-06-12T16%3A34%3A19.047Z%22%2C%22sessionMaxTime%22%3A1800%2C%22customIdentifiersToTrack%22%3A%5B%5D%2C%22sessionExpiryTime%22%3A1718215247464%2C%22numberOfSessions%22%3A17%7D":document.cookie;return t=t.split(";").map((function(i){var t=i.split("="),n=t[0],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},L=function(i,t,n){return r(void 0,void 0,void 0,(function(){var o,e,r,a,u,l,c;return s(this,(function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),o=v().apiUrl,d.log("endpointUrl",e="".concat(o,"/chat/chatbot/get/")),[4,fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_user_id:t||null,org_id:i,token:n||void 0,extra_info:{}})})];case 1:return(r=s.sent()).ok?[3,3]:[4,r.text()];case 2:throw a=s.sent(),Error(M[C](r.status,a));case 3:return[4,r.json()];case 4:if(u=s.sent(),!(null===(c=null==u?void 0:u.user)||void 0===c?void 0:c.org_info))throw Error(M[D](["user","org_info"]));return[2,u];case 5:throw l=s.sent(),S.trackError(l instanceof Error?l:Error(M[k]({error:l+""})),"fetchChatbotConfig",{errorCode:l instanceof Error&&l.message.includes("API Request Failed")?C:k,errorType:"API_ERROR",context:{apiKey:i,userId:t,timestamp:Date.now()}}),l;case 6:return[2]}}))}))},W=function(i){return r(void 0,void 0,void 0,(function(){var r,a,d,u,l,c,h,v,f,p,m,w,b,g,x,y,E,_,T,S,A,O,R,C,k,D,j;return s(this,(function(s){switch(s.label){case 0:return r=function(i){return{api_key:(i.api_key||"")+"",user_id:i.user_id?i.user_id+"":null,user_token:i.user_token?i.user_token+"":void 0,user_profile:i.user_profile||{}}}(i),a=r.user_id||void 0,d=!1,a||(a=function(){var i,t="; ".concat(document.cookie).split("; rblyn_anon=");if(2===t.length)return null===(i=t.pop())||void 0===i?void 0:i.split(";").shift()}()||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var t=16*Math.random()|0;return("x"===i?t:3&t|8).toString(16)})),M=a,(N=new Date).setTime(N.getTime()+31536e6),document.cookie="".concat("rblyn_anon","=").concat(M,";expires=").concat(N.toUTCString(),";path=/"),d=!0),[4,L(r.api_key,a,r.user_token)];case 1:return u=s.sent(),l=I(),z=r.user_profile,c=z?Object.fromEntries(Object.entries(z).map((function(i){var t=i[0],n=i[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,n+""]}))):{},h=e(e({},l),c),[2,{chatbotId:r.api_key,userId:a,token:r.user_token,isAnonymous:d,domain:"",brand_colour:(null===(f=null===(v=u.user.org_info.brand_config)||void 0===v?void 0:v.colors)||void 0===f?void 0:f.brand_color)||"",image_url:(null===(m=null===(p=u.user.org_info)||void 0===p?void 0:p.brand_config)||void 0===m?void 0:m.launcher_logo_url)||"",userProfile:h,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(w=u.user.org_info.brand_config)||void 0===w?void 0:w.display_name)||"",welcome_message:(null===(b=u.user.org_info.brand_config)||void 0===b?void 0:b.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(g=u.user.org_info.brand_config)||void 0===g?void 0:g.redirect_url)||""},launcher_type:(null===(x=u.user.org_info.brand_config)||void 0===x?void 0:x.launcher_type)||o.IMAGE,launcher_properties:{text:(null===(E=null===(y=u.user.org_info.brand_config)||void 0===y?void 0:y.launcher_properties)||void 0===E?void 0:E.text)||""},images:{launcher_image_url:{url:(null===(S=null===(T=null===(_=u.user.org_info.brand_config)||void 0===_?void 0:_.images)||void 0===T?void 0:T.launcher_image_url)||void 0===S?void 0:S.url)||""}},interface_properties:{position:(null===(O=null===(A=u.user.org_info.brand_config)||void 0===A?void 0:A.interface_properties)||void 0===O?void 0:O.position)||n.RIGHT,side_spacing:(null===(C=null===(R=u.user.org_info.brand_config)||void 0===R?void 0:R.interface_properties)||void 0===C?void 0:C.side_spacing)||20,bottom_spacing:(null===(D=null===(k=u.user.org_info.brand_config)||void 0===k?void 0:k.interface_properties)||void 0===D?void 0:D.bottom_spacing)||20},interface_type:(null===(j=u.user.org_info.brand_config)||void 0===j?void 0:j.interface_type)||t.WIDGET}]}var z,M,N}))}))},P=function(){function i(i){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=i,this.validateDomain()&&this.init(),null===window||void 0===window||window.addEventListener("message",this.onCloseListener.bind(this),!1)}return i.prototype.onCloseListener=function(i){i.origin===this.config.domain&&"closeChatbot"===i.data&&this.closeIframe()},i.prototype.validateDomain=function(){var i,t=this.config.domain,n=null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.origin;return d.log("expectedDomain, to current domain",t,n,t===n),t===n},i.prototype.createChatBubblContainer=function(){var i,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var o=document.createElement("div");o.classList.add("close-btn"),o.textContent="✕",Object.assign(o.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(i=this.config.chat_interface_config)||void 0===i?void 0:i.chat_bubble_prompts)||[]).forEach((function(i){var o=t.createMessageBubble(i);n.appendChild(o)})),n.appendChild(o),document.body.appendChild(n)},i.prototype.createMessageBubble=function(i){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=i,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var o=document.createElement("button");return o.innerHTML="×",Object.assign(o.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),o.addEventListener("click",(function(){t.remove()})),t.appendChild(o),t.appendChild(n),t},i.prototype.createFloatingButton=function(){var i=document.createElement("div");i.classList.add("message-bubble-container"),Object.assign(i.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:a(this.config.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),document.body.appendChild(i),this.logoContainer=i,this.loadImage(this.logoContainer),this.createChatBubblContainer(),this.logoContainer.addEventListener("click",this.toggleIframe.bind(this))},i.prototype.loadImage=function(i){var t,n,o=document.createElement("img");o.src=this.config.launcher_type?(null===(n=null===(t=this.config.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(this.config.domain,"/chatbubble.png"):this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),o.alt="Chat",Object.assign(o.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=o,i.innerHTML="",i.appendChild(o)},i.prototype.createIframe=function(){var i=this;d.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),d.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){560>(null===window||void 0===window?void 0:window.innerWidth)?Object.assign(t.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(t.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"})};n(),null===window||void 0===window||window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o,e,r;if(i.iframe){var s=new URL(i.iframe.src).origin||i.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},s),null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hostname,action:"registerUserId",data:{userId:i.config.userId,token:i.config.token,userProfile:i.config.userProfile}},s)}})),null===window||void 0===window||window.addEventListener("message",(function(n){var o,e;if(n.origin===i.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===i.config.chatbotId,s={cookies:F(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname};null===(e=t.contentWindow)||void 0===e||e.postMessage(s,i.config.domain||"*")}"expand"===n.data&&(i.adjustIframeWidth(),t.style.height="calc(100vh - 120px)",t.style.bottom="86px"),"collapse"===n.data&&Object.assign(t.style,{width:"26%",height:"calc(100vh - 32px - 10vh)",bottom:"86px",top:"calc(32px + 10vh)"})}}))},i.prototype.adjustIframeWidth=function(){if(this.iframe){var i=null===window||void 0===window?void 0:window.innerWidth;d.log("screenWidth",i),this.iframe.style.width=832>i?"".concat(i-64,"px"):"800px"}},i.prototype.loadSvgInline=function(i){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");i.innerHTML="",n&&i.appendChild(n)},i.prototype.toggleIcon=function(i,t){"block"===t.style.display?this.loadSvgInline(i):this.loadImage(i)},i.prototype.toggleIframe=function(){var i;if(d.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;d.log("toggleIframe"),null===(i=this.iframe.contentWindow)||void 0===i||i.postMessage({domain:null===window||void 0===window?void 0:window.location.hostname,name:"none"===this.iframe.style.display?"openFrame":"closeFrame"},t),this.iframe.style.display="none"===this.iframe.style.display?"block":"none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="block"===this.iframe.style.display?"none":"cover",this.bubblePromptContainer&&(this.bubblePromptContainer.style.display="none"),d.log("this.bubblePromptContainer",this.bubblePromptContainer)}},i.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},i.prototype.init=function(){this.createIframe(),this.createFloatingButton()},i}(),H=function(i){var t={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},n=[],o=function(i){t=e(e({},t),i),n.forEach((function(i){return i(t)}))};return{getState:function(){return t},initialize:function(){return r(void 0,void 0,void 0,(function(){var t,n,e;return s(this,(function(r){switch(r.label){case 0:if(!i.api_key)return S.trackError(Error(M[A](i.api_key)),"ChatbotStateManager",{errorCode:A,errorType:z,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,W(i)];case 2:return t=r.sent(),[4,new Promise((function(i,n){!function(n,e,r){if(n.chatbotId&&n.userId)try{new P(n),o({isInitialized:!0,chatbotConfig:t}),i(),d.log("Robylon SDK initialized successfully.")}catch(i){r(i instanceof Error?i.message:"Failed to initialize SDK")}else r("Incomplete configuration for SDK initialization.")}(t,0,(function(i){n(i)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),e=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:e}),S.trackError(n instanceof Error?n:Error(e),"ChatbotStateManager",{errorCode:O,errorType:z,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!t.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o,subscribe:function(i){return n.push(i),function(){var t=n.indexOf(i);t>-1&&n.splice(t,1)}},unsubscribe:function(i){var t=n.indexOf(i);t>-1&&n.splice(t,1)}}},B=function(i){i.api_key,i.user_profile;var t=i.onEvent;return i.chatbotConfig,{emit:function(i,n){var o={type:i,timestamp:Date.now(),data:n};null==t||t(o)},onInternalEvent:function(i,t){}}},J=function(){function i(i){var t=this;if(this.container=null,this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(i){if(!t.isDestroyed){var n=i.isInitialized,o=i.error,e=i.chatbotConfig,r=i.isIframeVisible;if(!o&&e&&n){if(t.eventEmitter=B({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:e.isAnonymous,userId:e.userId}}),t.container||(t.container=new U(e)),t.iframe)t.iframe.update({config:e,isVisible:r});else if(t.iframe=new N({config:e,isVisible:r,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var s=t.iframe.getElement();s&&t.container&&t.container.getElement().prepend(s)}if(t.floatingButton)t.floatingButton.update({config:e,isIframeVisible:r});else if(t.floatingButton=new w({config:e,toggleIframe:t.toggleIframe,isIframeVisible:r,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var a=t.floatingButton.getElement();a&&t.container&&t.container.getElement().appendChild(a)}}}},this.toggleIframe=function(){var i=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(i.isIframeVisible?l.CHATBOT_CLOSED:l.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(l.CHATBOT_CLOSED)},this.config=i,!i.api_key)throw S.trackError(Error(M[A](i.api_key)),"RobylonChatbot",{errorCode:A,errorType:z,context:{timestamp:Date.now()}}),Error("API key is required");try{S.initialize(i.api_key,i.user_id)}catch(i){S.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot",{errorCode:R,errorType:z,context:{timestamp:Date.now()}})}this.stateManager=H({api_key:i.api_key,user_id:i.user_id,user_token:i.user_token,user_profile:i.user_profile}),this.eventEmitter=B({api_key:i.api_key,user_profile:i.user_profile,onEvent:i.onEvent,chatbotConfig:null}),this.initialize()}return i.prototype.initialize=function(){return r(this,void 0,void 0,(function(){var i;return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.stateManager.initialize()];case 1:return t.sent(),this.stateManager.subscribe(this.handleStateChange),this.handleStateChange(this.stateManager.getState()),[3,3];case 2:return i=t.sent(),S.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot.initialize",{errorCode:O,errorType:z,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},i.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(l.CHATBOT_BUTTON_CLICKED))},i.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(l.CHATBOT_CLOSED))},i.prototype.toggle=function(){this.toggleIframe()},i.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null),this.container&&(this.container.destroy(),this.container=null),this.stateManager.unsubscribe(this.handleStateChange)},i.prototype.getState=function(){return this.stateManager.getState().isInitialized?"initialized":"uninitialized"},i}();function Z(i){return new J(i)}"undefined"!=typeof window&&function(){if("undefined"!=typeof window){var i=window.RobylonChatbot;if(i&&Array.isArray(i.q)){var t=null;i.q.forEach((function(i){var n=i[0];if("init"===n){var o=i[1]||{};t=Z(o)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(i){for(var n,o=[],e=1;arguments.length>e;e++)o[e-1]=arguments[e];return"init"===i?t=Z(o[0]||{}):t&&"function"==typeof t[i]?(n=t)[i].apply(n,o):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var Y={create:Z,getState:function(){return"initialized"}};i.create=Z,i.default=Y,Object.defineProperty(i,"i",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=robylon-chatbot.js.map
|