@robylon/web-react-sdk 1.1.38-staging.39 → 1.1.38-staging.41

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.
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import e,{memo as t,useRef as n,useState as i,useEffect as o,useCallback as r,Component as a,useMemo as s}from"react";var l=function(e,t){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},l(e,t)};var c,d,u,p=function(){return p=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},p.apply(this,arguments)};function f(e,t,n,i){return new(n||(n=Promise))((function(o,r){function a(e){try{l(i.next(e))}catch(e){r(e)}}function s(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((i=i.apply(e,t||[])).next())}))}function h(e,t){var n,i,o,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(r=0)),r;)try{if(n=1,i&&(o=2&s[0]?i.return:s[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;switch(i=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,i=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){r.label=s[1];break}if(6===s[0]&&r.label<o[1]){r.label=o[1],o=s;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(s);break}o[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e],i=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError,function(e){e.WIDGET="WIDGET",e.POPOVER="POPOVER",e.EMBED="EMBED"}(c||(c={})),function(e){e.RIGHT="Right",e.LEFT="Left"}(d||(d={})),function(e){e.TEXT="TEXT",e.IMAGE="IMAGE",e.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(u||(u={}));var v=function(e,t){void 0===t&&(t=.5);var n=function(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(e,t,n,i){return t+t+n+n+i+i}));var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}}(e),i=function(e,t,n){var i=[e,t,n].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*i[0]+.7152*i[1]+.0722*i[2]}(n.r,n.g,n.b);return i>t?"#0E0E0F":"#FFFFFF"},m={log:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.log.apply(console,e)},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.error.apply(console,e)},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.warn.apply(console,e)},info:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.info.apply(console,e)}};m.log("Raw API_URL:","https://stage-api.robylon.ai");var g={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};m.log("CONFIG",g);var b,w,y=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},_=function(){return{copilotUrl:g.copilotUrl||"https://app.robylon.ai",environment:g.environment||"production",apiUrl:g.apiUrl||"https://app.robylon.ai"}};!function(e){e.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",e.CHATBOT_BUTTON_CLICKED="CHATBOT_BUTTON_CLICKED",e.CHATBOT_OPENED="CHATBOT_OPENED",e.CHATBOT_CLOSED="CHATBOT_CLOSED",e.CHATBOT_APP_READY="CHATBOT_APP_READY",e.CHATBOT_LOADED="CHATBOT_LOADED",e.CHAT_INITIALIZED="CHAT_INITIALIZED",e.SESSION_REFRESHED="SESSION_REFRESHED",e.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED"}(b||(b={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(w||(w={}));var E,I=t((function(t){var r,a,s,l,c,d=t.config,f=t.toggleIframe,h=t.isIframeVisible,g=t.onEvent,w=t.onInternalEvent,y=n(null),E=_().copilotUrl,I=i(!1),x=I[0],T=I[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;T(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),o((function(){y.current&&requestAnimationFrame((function(){null==g||g({type:b.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),w(b.CHATBOT_BUTTON_LOADED)}))}),[g,w]);var C={zIndex:1e3,display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",boxSizing:"border-box"};d.launcher_type===u.IMAGE&&(C.width="48px",C.height="48px",C.borderRadius="50%",C.backgroundColor=d.brand_colour);var O=(null===(s=d.interface_properties)||void 0===s?void 0:s.position)||"Right",A=(null===(l=d.interface_properties)||void 0===l?void 0:l.side_spacing)||20,S=(null===(c=d.interface_properties)||void 0===c?void 0:c.bottom_spacing)||20,D=p(p({},C),((r={position:void 0,bottom:"0",borderRadius:(null==d?void 0:d.launcher_type)&&(null==d?void 0:d.launcher_type)!==u.IMAGE?"9999px":"50%"})[O.toLowerCase()]="0",r)),R=p(p({},C),((a={position:"fixed",bottom:"".concat(S,"px"),borderRadius:(null==d?void 0:d.launcher_type)&&(null==d?void 0:d.launcher_type)!==u.IMAGE?"9999px":"50%"})[O.toLowerCase()]="".concat(A,"px"),a)),k=x?R:D;o((function(){m.log("Screen width changed, isMobile:",x,"Style:",k)}),[x,k]),m.log("config in floating button",d);return e.createElement("div",{ref:y,className:"message-bubble-container",style:p(p({},k),{transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97)",transform:h?"scale(0.85)":"scale(1)"}),onClick:f},function(){switch(d.launcher_type){case u.TEXT:return function(){var t;return e.createElement("div",{style:{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:d.brand_colour,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box"}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:v(d.brand_colour),fontSize:"14px",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}},null===(t=d.launcher_properties)||void 0===t?void 0:t.text)))}();case u.TEXTUAL_IMAGE:return function(){var t,n,i;return e.createElement("div",{style:{maxWidth:"174px",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:d.brand_colour,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"}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:v(d.brand_colour),fontSize:"14px",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}},null===(t=d.launcher_properties)||void 0===t?void 0:t.text)),e.createElement("div",{style:{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:0}},e.createElement("img",{src:(null==d?void 0:d.launcher_type)?(null===(i=null===(n=null==d?void 0:d.images)||void 0===n?void 0:n.launcher_image_url)||void 0===i?void 0:i.url)||"".concat(E,"/chatbubble.png"):(null==d?void 0:d.image_url)||"".concat(E,"/chatbubble.png"),alt:"Chat",style:{width:"100%",height:"100%",objectFit:"cover"}})))}();case u.IMAGE:default:return function(){var t,n;return h?e.createElement("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("g",{id:"Chevron_Down"},e.createElement("path",{id:"Vector",d:"M19 9L12 16L5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}))):e.createElement("img",{src:(null==d?void 0:d.launcher_type)?(null===(n=null===(t=null==d?void 0:d.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(E,"/chatbubble.png"):(null==d?void 0:d.image_url)||"".concat(E,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}})}()}}())})),x=function(){var e;return(null===(e=navigator.userAgentData)||void 0===e?void 0:e.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},T=function(){var e;if(null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands)for(var t=["Chrome","Firefox","Safari","Edge","Opera"],n=0,i=navigator.userAgentData.brands;n<i.length;n++){var o=i[n];if(t.includes(o.brand))return o.brand}return(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},C=function(){var e,t,n,i;return{width:(null===window||void 0===window?void 0:window.innerWidth)||(null===(e=null===document||void 0===document?void 0:document.documentElement)||void 0===e?void 0:e.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===(i=null===document||void 0===document?void 0:document.body)||void 0===i?void 0:i.clientHeight)}},O=function(){return{platform:"web",os:x(),browser:T(),sdk_version:"1.1.38-staging.39",device:(e=navigator.userAgent.toLowerCase(),/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(e)?"tablet":/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(e)?"mobile":"desktop"),screen_size:C()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(E||(E={}));var A,S=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],D=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&S.some((function(e){return(null==t?void 0:t.includes(e))||(null==n?void 0:n.includes(e))||(null==i?void 0:i.includes(e))}))},R=function(){function e(){var e=this;this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.handleWindowError=function(t){var n,i={filename:t.filename,stack:null===(n=t.error)||void 0===n?void 0:n.stack,message:t.message};D(i)&&e.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})},this.handleUnhandledRejection=function(t){var n,i,o={stack:null===(n=t.reason)||void 0===n?void 0:n.stack,message:(null===(i=t.reason)||void 0===i?void 0:i.message)||String(t.reason)};D(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){y()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},e.prototype.cleanup=function(){y()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.prototype.initialize=function(e,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===e?"undefined":null===e?"null":""===e?"empty string":"invalid: ".concat(e)),componentName:"ErrorTrackingService",additionalInfo:{preInitError:!0,apiKey:e,userId:t,timestamp:Date.now()},timestamp:Date.now()},metadata:O(),event_type:E.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){m.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:new Error(String(n)),componentName:"ErrorTrackingService",additionalInfo:{apiKey:e,userId:t}})}},e.prototype.processPreInitQueue=function(){return f(this,void 0,void 0,(function(){var e,t,n;return h(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];m.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,i.label=1;case 1:return e<t.length?(n=t[e],[4,this.trackError(n.error,n.componentName,p(p({},n.additionalInfo),{preInitError:!0}))]):[3,4];case 2:i.sent(),i.label=3;case 3:return e++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},e.prototype.sendLog=function(e){return f(this,void 0,void 0,(function(){var t,n,i,o,r,a;return h(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=_().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=s.sent()).ok?[3,3]:(o=(i=m).error,r=["Failed to send error log:"],[4,n.text()]);case 2:o.apply(i,r.concat([s.sent()])),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),m.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return f(this,void 0,void 0,(function(){var i,o,r;return h(this,(function(a){switch(a.label){case 0:if(this.isInitialized)return[3,5];i={org_id:"UNINITALIZED",event_data:{message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:p(p({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:O(),event_type:E.ERROR,user_id:this.userId},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return a.sent(),[3,4];case 3:return a.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),m.warn("Error tracked before initialization, queuing:",e),[3,4];case 4:return[2];case 5:return o={message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:p(p({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:O(),event_type:E.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return f(this,void 0,void 0,(function(){var i,o;return h(this,(function(r){switch(r.label){case 0:return this.apiKey?(i={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},o={org_id:this.apiKey,event_data:i,metadata:O(),event_type:E.INFO,user_id:this.userId},[4,this.sendLog(o)]):(m.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),k=R.getInstance(),L="MISSING_API_KEY",z="INVALID_API_KEY",N="CONFIG_FETCH_FAILED",M="SDK_INIT_FAILED",H="ERROR_TRACKING_INIT_FAILED",B="API_REQUEST_FAILED",j="NETWORK_ERROR",U="INVALID_RESPONSE",F="IFRAME_LOAD_FAILED",W="COOKIE_ACCESS_ERROR",P="COMPONENT_RENDER_ERROR",V="INITIALIZATION_ERROR",G="API_ERROR",K="RUNTIME_ERROR",J="COMPONENT_ERROR",Z=((A={})[L]=function(e){return"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===e?"undefined":null===e?"null":""===e?"empty string":"invalid: ".concat(e),". A valid API key string is required to initialize the SDK.")},A[z]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},A[N]=function(e){return"Failed to fetch chatbot configuration: ".concat(e.statusCode?"Server responded with status ".concat(e.statusCode):"Could not reach server").concat(e.error?". Error: ".concat(e.error):"")},A[B]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},A[j]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},A[F]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},A[U]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},A[H]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},A[M]=function(e){return"SDK Initialization Failed: ".concat(e.reason||"Could not initialize the chatbot SDK").concat(e.config?". Attempted initialization with config: ".concat(JSON.stringify(e.config,null,2)):"")},A[W]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},A[P]=function(e){return"React Component Error: ".concat(e.component||"Unknown component"," failed to render. Error: ").concat(e.error).concat(e.stack?"\nComponent Stack: ".concat(e.stack):"")},A),Y=t((function(t){var i,a,s,l,c=t.config,d=t.isVisible,u=t.onClose,p=t.onEvent,f=t.onInternalEvent,h=n(null),v=n(!1),m=n(!1),g=null!==(a=null===(i=c.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==a?a:20,y=r((function(){var e,t,n=h.current;if(n){var i=(null===(t=c.interface_properties)||void 0===t?void 0:t.position)||"Right",o=((e={width:(null===window||void 0===window?void 0:window.innerWidth)<560?"100vw":"26%",minWidth:(null===window||void 0===window?void 0:window.innerWidth)<560?"300px":"400px",height:(null===window||void 0===window?void 0:window.innerWidth)<560?"100vh":"calc(100vh - 2rem - 10vh - ".concat(g,"px)"),borderRadius:(null===window||void 0===window?void 0:window.innerWidth)<560?"0":"1rem",position:(null===window||void 0===window?void 0:window.innerWidth)<560?"fixed":"",maxHeight:(null===window||void 0===window?void 0:window.innerWidth)<560?"100%":"50rem",top:(null===window||void 0===window?void 0:window.innerWidth)<560?"0":"calc(10vh - 32px)"})[i.toLowerCase()]=(null===window||void 0===window?void 0:window.innerWidth)<560?"0":void 0,e.flexDirection=(null===window||void 0===window?void 0:window.innerWidth)<560?"column":void 0,e.flexGrow=(null===window||void 0===window?void 0:window.innerWidth)<560?"1":void 0,e);Object.assign(n.style,o)}}),[g,null===(s=c.interface_properties)||void 0===s?void 0:s.position]);return o((function(){var e,t=h.current;if(t&&!v.current){var n=_().copilotUrl,i=(null===(e=c.interface_properties)||void 0===e?void 0:e.position)||"Right";Object.assign(t.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(i.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"}),t.src="".concat(n,"/chatbot-plugin?id=").concat(c.chatbotId),v.current=!0,y();var o=function(){var e,i,o=new URL(t.src).origin||n;null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,name:"checkDomain"},o)};return t.addEventListener("load",o),function(){return t.removeEventListener("load",o)}}}),[c.chatbotId,null===(l=c.interface_properties)||void 0===l?void 0:l.position,y]),o((function(){var e,t,n,i,o,r=h.current;if(r&&v.current){var a=(null===(e=c.interface_properties)||void 0===e?void 0:e.position)||"Right";if(d?(r.style.display="block",r.getBoundingClientRect(),requestAnimationFrame((function(){r.style.opacity="1",r.style.transform="scale(1) translate3d(0,0,0)"}))):(r.style.opacity="0",r.style.transform="scale(0.3) translate3d(".concat((a.toLowerCase(),"0"),",40px,0)"),setTimeout((function(){!d&&r&&(r.style.display="none")}),200)),r.contentWindow&&d){var s=_().copilotUrl;null===(t=null==r?void 0:r.contentWindow)||void 0===t||t.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},s),(null==m?void 0:m.current)||(null===(i=r.contentWindow)||void 0===i||i.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==c?void 0:c.userId,token:null==c?void 0:c.token,userProfile:null==c?void 0:c.userProfile,isAnonymous:null==c?void 0:c.isAnonymous}},s),m.current=!0)}}}),[d,c.userId,c.token,c.userProfile]),o((function(){if(h.current&&v.current){var e=_().copilotUrl;d&&(null==p||p({type:b.CHATBOT_OPENED,timestamp:Date.now()}),f(b.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,s,l;if(t.origin===e){if("closeChatbot"===t.data)return void u();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void f(w.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==p||p({type:b.CHATBOT_LOADED,timestamp:Date.now()}),f(b.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==p||p({type:b.CHAT_INITIALIZED,timestamp:Date.now()}),f(b.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==p||p({type:b.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),f(b.CHAT_INITIALIZATION_FAILED,{error:null===(a=t.data)||void 0===a?void 0:a.error})),"SESSION_REFRESHED"===(null===(s=t.data)||void 0===s?void 0:s.type)&&(null==p||p({type:b.SESSION_REFRESHED,timestamp:Date.now()}),f(b.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(l=t.data)||void 0===l?void 0:l.type)&&f(w.CHAT_MOVED,{from:t.data.from,to:t.data.to,trigger:t.data.trigger})}};return null===window||void 0===window||window.addEventListener("message",t),function(){return null===window||void 0===window?void 0:window.removeEventListener("message",t)}}}),[u,p,f,c.chatbotId,d]),o((function(){var e=h.current;if(e&&v.current){var t=function(){k.trackError(new Error(Z[F]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:F,errorType:K,context:{config:c,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[c]),o((function(){var e;if(h.current&&c&&d){var t=h.current,n=_().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:c.userProfile},n)}}),[c.userProfile,d]),e.createElement("iframe",{ref:h,id:"chat-iframe-rbyln",style:{display:"none"}})})),Q=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={hasError:!1},t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.getDerivedStateFromError=function(e){return{hasError:!0}},t.prototype.componentDidCatch=function(e,t){k.trackError(new Error(Z[P]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:P,errorType:J,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(a),X=function(e,t,n){return f(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return h(this,(function(u){switch(u.label){case 0:i=_().apiUrl,o="".concat(i,"/chat/chatbot/get/"),m.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{}},u.label=1;case 1:return u.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 2:return(a=u.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=u.sent(),new Error(Z[B](a.status,s));case 4:return[4,a.json()];case 5:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(Z[U](["user","org_info"]));return[2,l];case 6:throw c=u.sent(),k.trackError(c instanceof Error?c:new Error(Z[j]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?B:j,errorType:G,context:{chatbotId:e,userId:t,apiUrl:i,statusCode:c instanceof Response?c.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),c;case 7:return[2]}}))}))},q=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},$=function(e){var t,n="; ".concat(document.cookie).split("; ".concat(e,"="));if(2===n.length)return null===(t=n.pop())||void 0===t?void 0:t.split(";").shift()},ee=function(e,t,n){var i=new Date;i.setTime(i.getTime()+24*n*60*60*1e3),document.cookie="".concat(e,"=").concat(t,";expires=").concat(i.toUTCString(),";path=/")},te=function(e){var t=e?"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(e){var t=e.split("="),n=t[0],i=t.slice(1).join("=").trim();return{name:n=n.trim(),value:i?decodeURIComponent(i):""}})),t},ne=function(){function e(e){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=e,this.validateDomain()&&this.init(),null===window||void 0===window||window.addEventListener("message",this.onCloseListener.bind(this),!1)}return e.prototype.onCloseListener=function(e){e.origin===this.config.domain&&"closeChatbot"===e.data&&this.closeIframe()},e.prototype.validateDomain=function(){var e,t=this.config.domain,n=null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.origin;return m.log("expectedDomain, to current domain",t,n,t===n),t===n},e.prototype.createChatBubblContainer=function(){var e,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 i=document.createElement("div");i.classList.add("close-btn"),i.textContent="✕",Object.assign(i.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===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var i=t.createMessageBubble(e);n.appendChild(i)})),n.appendChild(i),document.body.appendChild(n)},e.prototype.createMessageBubble=function(e){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=e,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 i=document.createElement("button");return i.innerHTML="&times;",Object.assign(i.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"}),i.addEventListener("click",(function(){t.remove()})),t.appendChild(i),t.appendChild(n),t},e.prototype.createFloatingButton=function(){var e=document.createElement("div");e.classList.add("message-bubble-container"),Object.assign(e.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:v(this.config.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),document.body.appendChild(e),this.logoContainer=e,this.loadImage(this.logoContainer),this.createChatBubblContainer(),this.logoContainer.addEventListener("click",this.toggleIframe.bind(this))},e.prototype.loadImage=function(e){var t,n,i=document.createElement("img");i.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"),i.alt="Chat",Object.assign(i.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=i,e.innerHTML="",e.appendChild(i)},e.prototype.createIframe=function(){var e=this;m.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),m.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){(null===window||void 0===window?void 0:window.innerWidth)<560?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,i,o,r;if(e.iframe){var a=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,name:"checkDomain"},a),null===(o=t.contentWindow)||void 0===o||o.postMessage({domain:null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hostname,action:"registerUserId",data:{userId:e.config.userId,token:e.config.token,userProfile:e.config.userProfile}},a)}})),null===window||void 0===window||window.addEventListener("message",(function(n){var i,o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,a={cookies:te(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(a,e.config.domain||"*")}"expand"===n.data&&(e.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)"})}}))},e.prototype.adjustIframeWidth=function(){if(this.iframe){var e=null===window||void 0===window?void 0:window.innerWidth;m.log("screenWidth",e),this.iframe.style.width=e<832?"".concat(e-64,"px"):"800px"}},e.prototype.loadSvgInline=function(e){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");e.innerHTML="",n&&e.appendChild(n)},e.prototype.toggleIcon=function(e,t){"block"===t.style.display?this.loadSvgInline(e):this.loadImage(e)},e.prototype.toggleIframe=function(){var e;if(m.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;m.log("toggleIframe"),null===(e=this.iframe.contentWindow)||void 0===e||e.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"),m.log("this.bubblePromptContainer",this.bubblePromptContainer)}},e.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")},e.prototype.init=function(){this.createIframe(),this.createFloatingButton()},e}(),ie=function(e,t,n){if(e.chatbotId&&e.userId)try{new ne(e);t(!0),m.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},oe=function(e){var t=s((function(){return function(e){return{api_key:String(e.api_key||""),user_id:e.user_id?String(e.user_id):null,user_token:e.user_token?String(e.user_token):void 0,user_profile:e.user_profile||{}}}(e)}),[e.api_key,e.user_id,e.user_token,JSON.stringify(e.user_profile)]),n=i({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),a=n[0],l=n[1],v=s((function(){var e=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"];return t.user_profile?Object.fromEntries(Object.entries(t.user_profile).filter((function(t){var n=t[0];return e.includes(n)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(t.user_profile)]),m=r((function(e){l((function(t){return p(p({},t),e)}))}),[]),g=r((function(){return f(void 0,void 0,void 0,(function(){var e,n,i,o,r,a,s,l,f,g,b,w,y,_,E,I,x,T,C,A,S,D,R,z,N,H,B,j,U,F;return h(this,(function(h){switch(h.label){case 0:if(!t.api_key)return k.trackError(new Error(Z[L](t.api_key)),"useChatbotState",{errorCode:L,errorType:V,context:{timestamp:Date.now()}}),[2];m({isInitializing:!0}),h.label=1;case 1:return h.trys.push([1,4,5,6]),e=t.user_id||void 0,n=!1,e||(e=$("rblyn_anon")||q(),ee("rblyn_anon",e,365),n=!0),[4,X(t.api_key,e,t.user_token)];case 2:return i=h.sent(),o=O(),r=p(p({},o),v),a={chatbotId:t.api_key,userId:e,token:t.user_token,isAnonymous:n,domain:"",brand_colour:(null===(g=null===(f=i.user.org_info.brand_config)||void 0===f?void 0:f.colors)||void 0===g?void 0:g.brand_color)||"",image_url:(null===(w=null===(b=i.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===w?void 0:w.launcher_logo_url)||"",userProfile:r,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(y=i.user.org_info.brand_config)||void 0===y?void 0:y.display_name)||"",welcome_message:(null===(_=i.user.org_info.brand_config)||void 0===_?void 0:_.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(E=i.user.org_info.brand_config)||void 0===E?void 0:E.redirect_url)||""},interface_properties:{position:(null===(x=null===(I=i.user.org_info.brand_config)||void 0===I?void 0:I.interface_properties)||void 0===x?void 0:x.position)||d.RIGHT,side_spacing:null!==(A=null===(C=null===(T=i.user.org_info.brand_config)||void 0===T?void 0:T.interface_properties)||void 0===C?void 0:C.side_spacing)&&void 0!==A?A:20,bottom_spacing:null!==(R=null===(D=null===(S=i.user.org_info.brand_config)||void 0===S?void 0:S.interface_properties)||void 0===D?void 0:D.bottom_spacing)&&void 0!==R?R:20},interface_type:(null===(z=i.user.org_info.brand_config)||void 0===z?void 0:z.interface_type)||c.WIDGET,launcher_type:(null===(N=i.user.org_info.brand_config)||void 0===N?void 0:N.launcher_type)||u.IMAGE,launcher_properties:{text:(null===(B=null===(H=i.user.org_info.brand_config)||void 0===H?void 0:H.launcher_properties)||void 0===B?void 0:B.text)||""},images:{launcher_image_url:{url:(null===(F=null===(U=null===(j=i.user.org_info.brand_config)||void 0===j?void 0:j.images)||void 0===U?void 0:U.launcher_image_url)||void 0===F?void 0:F.url)||""}}},[4,new Promise((function(e,t){ie(a,(function(){m({isInitialized:!0,chatbotConfig:a}),e()}),(function(e){t(e)}))}))];case 3:return h.sent(),[3,6];case 4:return s=h.sent(),l=s instanceof Error?s.message:"Failed to initialize chatbot",m({error:l}),k.trackError(s instanceof Error?s:new Error(l),"useChatbotState",{errorCode:M,errorType:V,context:{timestamp:Date.now()}}),[3,6];case 5:return m({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[t.api_key,t.user_id,t.user_token]);o((function(){t.api_key&&g()}),[g]),o((function(){a.chatbotConfig&&l((function(e){return p(p({},e),{chatbotConfig:p(p({},e.chatbotConfig),{userProfile:p(p({},O()),v)})})}))}),[v]);var b=r((function(){l((function(e){return p(p({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),w=r((function(){m({isIframeVisible:!1})}),[]);return p(p({},a),{toggleIframeVisibility:b,closeIframe:w})},re=function(e){var t=e.api_key,n=e.chatbotConfig,i=e.user_profile,o=e.onEvent,a=s((function(){return{isAnonymous:(null==n?void 0:n.isAnonymous)||!1,userId:(null==n?void 0:n.userId)||""}}),[null==n?void 0:n.isAnonymous,null==n?void 0:n.userId]),l=s((function(){return i||{}}),[JSON.stringify(i)]),c=r((function(e){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return f(void 0,function(e,t,n){if(n||2===arguments.length)for(var i,o=0,r=t.length;o<r;o++)!i&&o in t||(i||(i=Array.prototype.slice.call(t,0,o)),i[o]=t[o]);return e.concat(i||Array.prototype.slice.call(t))}([e],n,!0),void 0,(function(e,n){var i,o,r,s,c,d,u;return void 0===n&&(n={}),h(this,(function(f){switch(f.label){case 0:if(!t)return[2];f.label=1;case 1:return f.trys.push([1,3,,4]),i=_().apiUrl,o=O(),r=p({trigger_time:Date.now(),channel:"CHATBOT",launch_url:(null===(u=null===window||void 0===window?void 0:window.location)||void 0===u?void 0:u.href)||"",org_id:t,client_user_id:a.isAnonymous?"Anonymous":String(a.userId),event_type:e,user_profile:l},n),s={org_id:t,event_data:r,metadata:p({timestamp:Date.now()},o),event_type:"INFO",user_id:a.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 2:if(!(c=f.sent()).ok)throw new Error("Failed to send internal event: ".concat(c.statusText));return[3,4];case 3:return d=f.sent(),m.error("Failed to send internal event:",d),[3,4];case 4:return[2]}}))}))}),[t,a]);return{emitEvent:r((function(e,t){var n=Date.now();e!==b.CHATBOT_BUTTON_CLICKED&&e!==b.CHATBOT_CLOSED&&e!==b.CHATBOT_OPENED||(o&&o({type:e,timestamp:n,data:t}),c(e,{timestamp:n}))}),[o,c]),onInternalEvent:c}},ae=function(t){var n,r,a,s,l,c,d,u=t.children,f=t.config,h=i(!1),v=h[0],g=h[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;g(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]);var b=(null===(a=f.interface_properties)||void 0===a?void 0:a.position)||"Right",w=null!==(l=null===(s=f.interface_properties)||void 0===s?void 0:s.side_spacing)&&void 0!==l?l:20,y=null!==(d=null===(c=f.interface_properties)||void 0===c?void 0:c.bottom_spacing)&&void 0!==d?d:20;m.log("config",f,b,w);var _={position:"fixed",zIndex:1e3,display:"flex",flexDirection:"column"},E=p(p({},_),((n={bottom:"".concat(y,"px")})[b.toLowerCase()]="".concat(null!=w?w:20,"px"),n.alignItems="Right"===b?"flex-end":"flex-start",n.top=void 0,n["Right"===b?"left":"right"]=void 0,n)),I=p(p({},_),((r={top:0})[b.toLowerCase()]="".concat(null!=w?w:20,"px"),r.alignItems="center",r.bottom=void 0,r["Right"===b?"left":"right"]=void 0,r)),x=v?I:E;return o((function(){console.log("Container screen width changed, isMobile:",v,"Style:",x)}),[v,x]),e.createElement("div",{className:"robylon-chatbot-container",style:x},u)},se=t((function(t){var n=t.api_key,i=t.user_id,a=t.user_token,l=t.user_profile,c=t.onEvent;o((function(){}));var d=s((function(){return{api_key:n,user_id:i,user_token:a,user_profile:l}}),[n,i,a,l]),u=r((function(e){null==c||c(e)}),[c]),f=oe(d),h=f.isInitialized,v=f.error,g=f.chatbotConfig,w=f.isIframeVisible,y=f.toggleIframeVisibility,_=f.closeIframe,E=s((function(){return{api_key:n,user_profile:d.user_profile,onEvent:u,chatbotConfig:g?{isAnonymous:g.isAnonymous,userId:g.userId}:null}}),[n,d.user_profile,u,null==g?void 0:g.isAnonymous,null==g?void 0:g.userId]),x=re(p({},E)),T=x.emitEvent,C=x.onInternalEvent;o((function(){if(n)try{k.initialize(n,i)}catch(e){k.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:H,errorType:V,context:{timestamp:Date.now()}})}else k.trackError(new Error(Z[L](n)),"RobylonChatbot",{errorCode:L,errorType:V,context:{timestamp:Date.now()}})}),[n,i]);var O=r((function(){_(),T(b.CHATBOT_CLOSED)}),[_,T]),A=r((function(){y(),T(w?b.CHATBOT_CLOSED:b.CHATBOT_BUTTON_CLICKED)}),[y,T,w]),S=s((function(){return{config:g,toggleIframe:A,isIframeVisible:w,onEvent:u,onInternalEvent:C}}),[g,A,w,u,C]);m.log("floatingButtonProps",S);var D=s((function(){return{config:g,isVisible:w,onClose:O,onEvent:u,onInternalEvent:C}}),[g,w,O,u,C]);return n&&!v&&g?e.createElement(Q,{componentName:"RobylonChatbot"},h?e.createElement(ae,{config:g},e.createElement(Q,{componentName:"ChatbotIframe"},e.createElement(Y,p({},D))),e.createElement(Q,{componentName:"ChatbotFloatingButton"},e.createElement(I,p({},S)))):null):null}),(function(e,t){return e.api_key===t.api_key&&e.user_id===t.user_id&&e.user_token===t.user_token&&JSON.stringify(e.user_profile)===JSON.stringify(t.user_profile)&&!0})),le=function(e){var t=i({isLoading:!0,isInitialized:!1,error:null}),n=t[0],r=t[1],a=function(e){r((function(t){return p(p({},t),{isInitialized:e})}))},s=function(e){r((function(t){return p(p({},t),{error:e})}))};return o((function(){!function(){try{ie(e,a,s)}catch(e){r((function(t){return p(p({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),n},ce=function(){function e(e){this.resizeObserver=null,this.config=e,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount(),this.setupResizeListener()}return e.prototype.render=function(){var e=this;_().copilotUrl;var t=this.config,n=t.config,i={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)"};n.launcher_type===u.IMAGE&&Object.assign(i,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:n.brand_colour}),this.applyResponsiveStyles(i),this.buttonElement.className="message-bubble-container",this.buttonElement.innerHTML="",this.buttonElement.appendChild(this.createLauncherElement()),this.buttonElement.onclick=function(){e.config.toggleIframe()}},e.prototype.createLauncherElement=function(){var e,t,n=this.config,i=n.config,o=n.isIframeVisible,r=_().copilotUrl;switch(console.log("config in floating button",i),i.launcher_type){case u.TEXT:return this.createTextLauncher();case u.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case u.IMAGE:default:if(o){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 s=document.createElement("img");return s.src=i.launcher_type?(null===(t=null===(e=i.images)||void 0===e?void 0:e.launcher_image_url)||void 0===t?void 0:t.url)||"".concat(r,"/chatbubble.png"):i.image_url||"".concat(r,"/chatbubble.png"),s.alt="Chat",Object.assign(s.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),s}},e.prototype.createTextLauncher=function(){var e=this.config.config,t=e.brand_colour,n=e.launcher_properties,i=document.createElement("div");Object.assign(i.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 o=document.createElement("div");Object.assign(o.style,{flex:"1",minWidth:"0"});var r=document.createElement("p");return Object.assign(r.style,{margin:"0",color:v(t),fontSize:"14px",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),r.textContent=(null==n?void 0:n.text)||"",o.appendChild(r),i.appendChild(o),i},e.prototype.createTextualImageLauncher=function(){var e,t,n,i,o,r,a=_().copilotUrl,s=this.config.config,l=s.brand_colour,c=s.launcher_properties,d=s.image_url,u=document.createElement("div");Object.assign(u.style,{maxWidth:"174px",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:l,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 p=document.createElement("div");Object.assign(p.style,{flex:"1",minWidth:"0"});var f=document.createElement("p");Object.assign(f.style,{margin:"0",color:v(l),fontSize:"14px",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),f.textContent=(null==c?void 0:c.text)||"";var h=document.createElement("div");Object.assign(h.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var m=document.createElement("img");return m.src=(null===(t=null===(e=null==this?void 0:this.config)||void 0===e?void 0:e.config)||void 0===t?void 0:t.launcher_type)?(null===(r=null===(o=null===(i=null===(n=null==this?void 0:this.config)||void 0===n?void 0:n.config)||void 0===i?void 0:i.images)||void 0===o?void 0:o.launcher_image_url)||void 0===r?void 0:r.url)||"".concat(a,"/chatbubble.png"):d||"".concat(a,"/chatbubble.png"),m.alt="Chat",Object.assign(m.style,{width:"100%",height:"100%",objectFit:"cover"}),p.appendChild(f),h.appendChild(m),u.appendChild(p),u.appendChild(h),u},e.prototype.applyResponsiveStyles=function(e){var t,n,i,o,r,a=(null===window||void 0===window?void 0:window.innerWidth)<560,s=this.config.config,l=(null===(i=s.interface_properties)||void 0===i?void 0:i.position)||"Right",c=(null===(o=s.interface_properties)||void 0===o?void 0:o.side_spacing)||20,d=(null===(r=s.interface_properties)||void 0===r?void 0:r.bottom_spacing)||20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var u=p(p({},e),a?((t={position:"fixed",bottom:"".concat(d,"px")})[l.toLowerCase()]="".concat(c,"px"),t):((n={bottom:"0"})[l.toLowerCase()]="0",n));Object.assign(this.buttonElement.style,u)},e.prototype.handleResize=function(){var e={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!==u.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===u.IMAGE&&Object.assign(e,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:this.config.config.brand_colour}),this.applyResponsiveStyles(e)},e.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},e.prototype.getElement=function(){return this.buttonElement},e.prototype.mount=function(){var e=this;requestAnimationFrame((function(){var t,n;null===(n=(t=e.config).onEvent)||void 0===n||n.call(t,{type:b.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(b.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config.isIframeVisible,this.config=p(p({},this.config),e),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render()},e.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)},e}(),de=function(){function e(e){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(e){var n,i,o,r,a,s,l,c,d,u,p,f,h,v,m,g=_().copilotUrl;if(e.origin===g){if("closeChatbot"===e.data)return void t.config.onClose();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=e.data)||void 0===n?void 0:n.type))return void t.config.onInternalEvent(w.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=e.data)||void 0===i?void 0:i.type)&&(null===(r=(o=t.config).onEvent)||void 0===r||r.call(o,{type:b.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(b.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=e.data)||void 0===a?void 0:a.type)&&(null===(l=(s=t.config).onEvent)||void 0===l||l.call(s,{type:b.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(b.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(c=e.data)||void 0===c?void 0:c.type)&&(null===(u=(d=t.config).onEvent)||void 0===u||u.call(d,{type:b.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(b.CHAT_INITIALIZATION_FAILED,{error:null===(p=e.data)||void 0===p?void 0:p.error})),"SESSION_REFRESHED"===(null===(f=e.data)||void 0===f?void 0:f.type)&&(null===(v=(h=t.config).onEvent)||void 0===v||v.call(h,{type:b.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(b.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(m=e.data)||void 0===m?void 0:m.type)&&t.config.onInternalEvent(w.CHAT_MOVED,{from:e.data.from,to:e.data.to,trigger:e.data.trigger})}},this.config=e,this.iframeElement=document.createElement("iframe"),this.iframeElement.id="chat-iframe-rbyln",this.resizeHandler=this.applyResponsiveStyles.bind(this),this.render(),this.initialize(),this.setupEventListeners()}return e.prototype.getElement=function(){return this.iframeElement},e.prototype.render=function(){var e,t=(null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.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()},e.prototype.applyResponsiveStyles=function(){var e,t,n,i,o;if(this.iframeElement){var r=null!==(i=null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.bottom_spacing)&&void 0!==i?i:20,a=(null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.position)||"Right";window.innerWidth<560?Object.assign(this.iframeElement.style,((e={width:"100vw",minWidth:"300px"})[a.toLowerCase()]="0",e.bottom="0",e.height="100vh",e.flexDirection="column",e.flexGrow="1",e.borderRadius="0",e.top="0",e.maxHeight="100%",e.position="fixed",e)):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:""})[a.toLowerCase()]=void 0,t))}},e.prototype.initialize=function(){var e=this;if(!this.isInitialized){var t=_().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,i,o=new URL(e.iframeElement.src).origin||t;null===(n=e.iframeElement.contentWindow)||void 0===n||n.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,name:"checkDomain"},o)}))}},e.prototype.setupEventListeners=function(){var e=this;window.addEventListener("resize",this.resizeHandler),this.iframeElement.addEventListener("error",(function(){k.trackError(new Error(Z[F]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:F,errorType:K,context:{config:e.config.config,iframeUrl:e.iframeElement.src,timestamp:Date.now()}})})),window.addEventListener("message",this.handleMessage)},e.prototype.updateVisibility=function(e){var t,n,i,o,r,a,s,l,c,d=this;this.config.isVisible=e;var u=(null===(t=this.config.config.interface_properties)||void 0===t?void 0:t.position)||"Right";if(e?(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((u.toLowerCase(),"0"),",40px,0)"),setTimeout((function(){d.config.isVisible||(d.iframeElement.style.display="none")}),200)),this.iframeElement.contentWindow&&e){var p=_().copilotUrl,f=new URL(this.iframeElement.src).origin||p;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"},f),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,action:"registerUserId",data:{userId:null===(o=this.config.config)||void 0===o?void 0:o.userId,token:null===(r=this.config.config)||void 0===r?void 0:r.token,userProfile:null===(a=this.config.config)||void 0===a?void 0:a.userProfile,isAnonymous:null===(s=this.config.config)||void 0===s?void 0:s.isAnonymous}},f),this.hasRegistered=!0),null===(c=(l=this.config).onEvent)||void 0===c||c.call(l,{type:b.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(b.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=p(p({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=_().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},e.prototype.destroy=function(){window.removeEventListener("resize",this.resizeHandler),window.removeEventListener("message",this.handleMessage),this.iframeElement&&this.iframeElement.parentNode&&this.iframeElement.parentNode.removeChild(this.iframeElement)},e}(),ue=function(){function e(e){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config=e,this.render(),this.mount(),this.setupResizeListener()}return e.prototype.render=function(){this.applyStyles(),this.containerElement.className="robylon-chatbot-container"},e.prototype.applyStyles=function(){var e,t,n,i,o,r,a,s=(null===window||void 0===window?void 0:window.innerWidth)<560,l=(null===(n=this.config.interface_properties)||void 0===n?void 0:n.position)||"Right",c=null!==(o=null===(i=this.config.interface_properties)||void 0===i?void 0:i.side_spacing)&&void 0!==o?o:20,d=null!==(a=null===(r=this.config.interface_properties)||void 0===r?void 0:r.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 u={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},f=p(p({},u),((e={bottom:"".concat(d,"px")})[l.toLowerCase()]="".concat(c,"px"),e.alignItems="Right"===l?"flex-end":"flex-start",e)),h=p(p({},u),((t={top:"0"})[l.toLowerCase()]="".concat(c,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,s?h:f)},e.prototype.handleResize=function(){this.applyStyles()},e.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},e.prototype.mount=function(){document.body.appendChild(this.containerElement)},e.prototype.getElement=function(){return this.containerElement},e.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)},e}(),pe=function(e,t,n){return f(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return h(this,(function(u){switch(u.label){case 0:return u.trys.push([0,5,,6]),i=_().apiUrl,o="".concat(i,"/chat/chatbot/get/"),m.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{}},[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(a=u.sent()).ok?[3,3]:[4,a.text()];case 2:throw s=u.sent(),new Error(Z[B](a.status,s));case 3:return[4,a.json()];case 4:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(Z[U](["user","org_info"]));return[2,l];case 5:throw c=u.sent(),k.trackError(c instanceof Error?c:new Error(Z[j]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?B:j,errorType:G,context:{apiKey:e,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},fe=function(e){return f(void 0,void 0,void 0,(function(){var t,n,i,o,r,a,s,l,f,v,m,g,b,w,y,_,E,I,x,T,C,A,S,D,R,k,L;return h(this,(function(h){switch(h.label){case 0:return t=function(e){return{api_key:String(e.api_key||""),user_id:e.user_id?String(e.user_id):null,user_token:e.user_token?String(e.user_token):void 0,user_profile:e.user_profile||{}}}(e),n=t.user_id||void 0,i=!1,n||(n=$("rblyn_anon")||q(),ee("rblyn_anon",n,365),i=!0),[4,pe(t.api_key,n,t.user_token)];case 1:return o=h.sent(),r=O(),z=t.user_profile,N=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],a=z?Object.fromEntries(Object.entries(z).filter((function(e){var t=e[0];return N.includes(t)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},s=p(p({},r),a),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",brand_colour:(null===(f=null===(l=o.user.org_info.brand_config)||void 0===l?void 0:l.colors)||void 0===f?void 0:f.brand_color)||"",image_url:(null===(m=null===(v=o.user.org_info)||void 0===v?void 0:v.brand_config)||void 0===m?void 0:m.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(g=o.user.org_info.brand_config)||void 0===g?void 0:g.display_name)||"",welcome_message:(null===(b=o.user.org_info.brand_config)||void 0===b?void 0:b.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(w=o.user.org_info.brand_config)||void 0===w?void 0:w.redirect_url)||""},launcher_type:(null===(y=o.user.org_info.brand_config)||void 0===y?void 0:y.launcher_type)||u.IMAGE,launcher_properties:{text:(null===(E=null===(_=o.user.org_info.brand_config)||void 0===_?void 0:_.launcher_properties)||void 0===E?void 0:E.text)||""},images:{launcher_image_url:{url:(null===(T=null===(x=null===(I=o.user.org_info.brand_config)||void 0===I?void 0:I.images)||void 0===x?void 0:x.launcher_image_url)||void 0===T?void 0:T.url)||""}},interface_properties:{position:(null===(A=null===(C=o.user.org_info.brand_config)||void 0===C?void 0:C.interface_properties)||void 0===A?void 0:A.position)||d.RIGHT,side_spacing:(null===(D=null===(S=o.user.org_info.brand_config)||void 0===S?void 0:S.interface_properties)||void 0===D?void 0:D.side_spacing)||20,bottom_spacing:(null===(k=null===(R=o.user.org_info.brand_config)||void 0===R?void 0:R.interface_properties)||void 0===k?void 0:k.bottom_spacing)||20},interface_type:(null===(L=o.user.org_info.brand_config)||void 0===L?void 0:L.interface_type)||c.WIDGET}]}var z,N}))}))},he=function(e){e.api_key,e.user_profile;var t=e.onEvent;e.chatbotConfig;return{emit:function(e,n){var i={type:e,timestamp:Date.now(),data:n};null==t||t(i)},onInternalEvent:function(e,t){}}},ve=function(){function e(e){var t,n,i,o,r=this;if(this.container=null,this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){if(!r.isDestroyed){var t=e.isInitialized,n=e.error,i=e.chatbotConfig,o=e.isIframeVisible;if(!n&&i&&t){if(r.eventEmitter=he({api_key:r.config.api_key,user_profile:r.config.user_profile,onEvent:r.config.onEvent,chatbotConfig:{isAnonymous:i.isAnonymous,userId:i.userId}}),r.container||(r.container=new ue(i)),r.iframe)r.iframe.update({config:i,isVisible:o});else if(r.iframe=new de({config:i,isVisible:o,onClose:r.handleClose,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}),r.iframe.getElement&&"function"==typeof r.iframe.getElement){var a=r.iframe.getElement();a&&r.container&&r.container.getElement().prepend(a)}if(r.floatingButton)r.floatingButton.update({config:i,isIframeVisible:o});else if(r.floatingButton=new ce({config:i,toggleIframe:r.toggleIframe,isIframeVisible:o,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}),r.floatingButton.getElement&&"function"==typeof r.floatingButton.getElement){var s=r.floatingButton.getElement();s&&r.container&&r.container.getElement().appendChild(s)}}}},this.toggleIframe=function(){var e=r.stateManager.getState();r.stateManager.toggleIframeVisibility(),r.eventEmitter.emit(e.isIframeVisible?b.CHATBOT_CLOSED:b.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){r.stateManager.closeIframe(),r.eventEmitter.emit(b.CHATBOT_CLOSED)},this.config=e,!e.api_key)throw k.trackError(new Error(Z[L](e.api_key)),"RobylonChatbot",{errorCode:L,errorType:V,context:{timestamp:Date.now()}}),new Error("API key is required");try{k.initialize(e.api_key,e.user_id)}catch(e){k.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:H,errorType:V,context:{timestamp:Date.now()}})}this.stateManager=(t={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},n={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},i=[],{getState:function(){return n},initialize:function(){return f(void 0,void 0,void 0,(function(){var e,n,i;return h(this,(function(r){switch(r.label){case 0:if(!t.api_key)return k.trackError(new Error(Z[L](t.api_key)),"ChatbotStateManager",{errorCode:L,errorType:V,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,fe(t)];case 2:return e=r.sent(),[4,new Promise((function(t,n){ie(e,(function(){o({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),i=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:i}),k.trackError(n instanceof Error?n:new Error(i),"ChatbotStateManager",{errorCode:M,errorType:V,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!n.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o=function(e){n=p(p({},n),e),i.forEach((function(e){return e(n)}))},subscribe:function(e){return i.push(e),function(){var t=i.indexOf(e);t>-1&&i.splice(t,1)}},unsubscribe:function(e){var t=i.indexOf(e);t>-1&&i.splice(t,1)}}),this.eventEmitter=he({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),this.initialize()}return e.prototype.initialize=function(){return f(this,void 0,void 0,(function(){var e;return h(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 e=t.sent(),k.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:M,errorType:V,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(b.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(b.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.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)},e.prototype.getState=function(){return this.stateManager.getState().isInitialized?"initialized":"uninitialized"},e}();function me(e){return new ve(e)}"undefined"!=typeof window&&function(){if("undefined"!=typeof window){var e=window.RobylonChatbot;if(e&&Array.isArray(e.q)){var t=null;e.q.forEach((function(e){var n=e[0];if("init"===n){var i=e[1]||{};t=me(i)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(e){for(var n,i=[],o=1;o<arguments.length;o++)i[o-1]=arguments[o];return"init"===e?t=me(i[0]||{}):t&&"function"==typeof t[e]?(n=t)[e].apply(n,i):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var ge={create:me,getState:function(){return"initialized"}};export{se as Chatbot,c as ChatbotInterfaceType,u as LauncherType,ge as RobylonChatbot,d as WidgetPositionEnums,le as useChatbot};
1
+ import e,{memo as t,useRef as n,useState as i,useEffect as o,useCallback as r,Component as a,useMemo as s}from"react";var l=function(e,t){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},l(e,t)};var c,d,u,p=function(){return p=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},p.apply(this,arguments)};function f(e,t,n,i){return new(n||(n=Promise))((function(o,r){function a(e){try{l(i.next(e))}catch(e){r(e)}}function s(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((i=i.apply(e,t||[])).next())}))}function h(e,t){var n,i,o,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(r=0)),r;)try{if(n=1,i&&(o=2&s[0]?i.return:s[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,s[1])).done)return o;switch(i=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,i=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){r.label=s[1];break}if(6===s[0]&&r.label<o[1]){r.label=o[1],o=s;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(s);break}o[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e],i=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError,function(e){e.WIDGET="WIDGET",e.POPOVER="POPOVER",e.EMBED="EMBED"}(c||(c={})),function(e){e.RIGHT="Right",e.LEFT="Left"}(d||(d={})),function(e){e.TEXT="TEXT",e.IMAGE="IMAGE",e.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(u||(u={}));var v=function(e,t){void 0===t&&(t=.5);var n=function(e){e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(e,t,n,i){return t+t+n+n+i+i}));var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}}(e),i=function(e,t,n){var i=[e,t,n].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*i[0]+.7152*i[1]+.0722*i[2]}(n.r,n.g,n.b);return i>t?"#0E0E0F":"#FFFFFF"},m={log:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.log.apply(console,e)},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.error.apply(console,e)},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.warn.apply(console,e)},info:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.info.apply(console,e)}};m.log("Raw API_URL:","https://stage-api.robylon.ai");var g={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};m.log("CONFIG",g);var b,w,y=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},_=function(){return{copilotUrl:g.copilotUrl||"https://app.robylon.ai",environment:g.environment||"production",apiUrl:g.apiUrl||"https://app.robylon.ai"}};!function(e){e.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",e.CHATBOT_BUTTON_CLICKED="CHATBOT_BUTTON_CLICKED",e.CHATBOT_OPENED="CHATBOT_OPENED",e.CHATBOT_CLOSED="CHATBOT_CLOSED",e.CHATBOT_APP_READY="CHATBOT_APP_READY",e.CHATBOT_LOADED="CHATBOT_LOADED",e.CHAT_INITIALIZED="CHAT_INITIALIZED",e.SESSION_REFRESHED="SESSION_REFRESHED",e.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED"}(b||(b={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(w||(w={}));var E,I="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",x="21px",T=t((function(t){var r,a,s,l,c,d=t.config,f=t.toggleIframe,h=t.isIframeVisible,g=t.onEvent,w=t.onInternalEvent,y=n(null),E=_().copilotUrl,T=i(!1),C=T[0],O=T[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;O(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),o((function(){y.current&&requestAnimationFrame((function(){null==g||g({type:b.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),w(b.CHATBOT_BUTTON_LOADED)}))}),[g,w]);var A={zIndex:1e3,display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",boxSizing:"border-box"};d.launcher_type===u.IMAGE&&(A.width="48px",A.height="48px",A.borderRadius="50%",A.backgroundColor=d.brand_colour);var S=(null===(s=d.interface_properties)||void 0===s?void 0:s.position)||"Right",R=(null===(l=d.interface_properties)||void 0===l?void 0:l.side_spacing)||20,D=(null===(c=d.interface_properties)||void 0===c?void 0:c.bottom_spacing)||20,k=p(p({},A),((r={position:void 0,bottom:"0",borderRadius:(null==d?void 0:d.launcher_type)&&(null==d?void 0:d.launcher_type)!==u.IMAGE?"9999px":"50%"})[S.toLowerCase()]="0",r)),L=p(p({},A),((a={position:"fixed",bottom:"".concat(D,"px"),borderRadius:(null==d?void 0:d.launcher_type)&&(null==d?void 0:d.launcher_type)!==u.IMAGE?"9999px":"50%"})[S.toLowerCase()]="".concat(R,"px"),a)),z=C?L:k;o((function(){m.log("Screen width changed, isMobile:",C,"Style:",z)}),[C,z]),m.log("config in floating button",d);return e.createElement("div",{ref:y,className:"message-bubble-container",style:p(p({},z),{transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97)",transform:h?"scale(0.85)":"scale(1)"}),onClick:f},function(){switch(d.launcher_type){case u.TEXT:return function(){var t;return e.createElement("div",{style:{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:d.brand_colour,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box",fontFamily:I,lineHeight:x}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:v(d.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:I,lineHeight:x,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},null===(t=d.launcher_properties)||void 0===t?void 0:t.text)))}();case u.TEXTUAL_IMAGE:return function(){var t,n,i;return e.createElement("div",{style:{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:d.brand_colour,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",fontFamily:I,lineHeight:x}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:v(d.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:I,lineHeight:x,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},null===(t=d.launcher_properties)||void 0===t?void 0:t.text)),e.createElement("div",{style:{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:0}},e.createElement("img",{src:(null==d?void 0:d.launcher_type)?(null===(i=null===(n=null==d?void 0:d.images)||void 0===n?void 0:n.launcher_image_url)||void 0===i?void 0:i.url)||"".concat(E,"/chatbubble.png"):(null==d?void 0:d.image_url)||"".concat(E,"/chatbubble.png"),alt:"Chat",style:{width:"100%",height:"100%",objectFit:"cover"}})))}();case u.IMAGE:default:return function(){var t,n;return h?e.createElement("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("g",{id:"Chevron_Down"},e.createElement("path",{id:"Vector",d:"M19 9L12 16L5 9",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}))):e.createElement("img",{src:(null==d?void 0:d.launcher_type)?(null===(n=null===(t=null==d?void 0:d.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(E,"/chatbubble.png"):(null==d?void 0:d.image_url)||"".concat(E,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}})}()}}())})),C=function(){var e;return(null===(e=navigator.userAgentData)||void 0===e?void 0:e.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},O=function(){var e;if(null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands)for(var t=["Chrome","Firefox","Safari","Edge","Opera"],n=0,i=navigator.userAgentData.brands;n<i.length;n++){var o=i[n];if(t.includes(o.brand))return o.brand}return(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},A=function(){var e,t,n,i;return{width:(null===window||void 0===window?void 0:window.innerWidth)||(null===(e=null===document||void 0===document?void 0:document.documentElement)||void 0===e?void 0:e.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===(i=null===document||void 0===document?void 0:document.body)||void 0===i?void 0:i.clientHeight)}},S=function(){return{platform:"web",os:C(),browser:O(),sdk_version:"1.1.38-staging.41",device:(e=navigator.userAgent.toLowerCase(),/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(e)?"tablet":/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(e)?"mobile":"desktop"),screen_size:A()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(E||(E={}));var R,D=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],k=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&D.some((function(e){return(null==t?void 0:t.includes(e))||(null==n?void 0:n.includes(e))||(null==i?void 0:i.includes(e))}))},L=function(){function e(){var e=this;this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.handleWindowError=function(t){var n,i={filename:t.filename,stack:null===(n=t.error)||void 0===n?void 0:n.stack,message:t.message};k(i)&&e.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})},this.handleUnhandledRejection=function(t){var n,i,o={stack:null===(n=t.reason)||void 0===n?void 0:n.stack,message:(null===(i=t.reason)||void 0===i?void 0:i.message)||String(t.reason)};k(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){y()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},e.prototype.cleanup=function(){y()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.prototype.initialize=function(e,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===e?"undefined":null===e?"null":""===e?"empty string":"invalid: ".concat(e)),componentName:"ErrorTrackingService",additionalInfo:{preInitError:!0,apiKey:e,userId:t,timestamp:Date.now()},timestamp:Date.now()},metadata:S(),event_type:E.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){m.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:new Error(String(n)),componentName:"ErrorTrackingService",additionalInfo:{apiKey:e,userId:t}})}},e.prototype.processPreInitQueue=function(){return f(this,void 0,void 0,(function(){var e,t,n;return h(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];m.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,i.label=1;case 1:return e<t.length?(n=t[e],[4,this.trackError(n.error,n.componentName,p(p({},n.additionalInfo),{preInitError:!0}))]):[3,4];case 2:i.sent(),i.label=3;case 3:return e++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},e.prototype.sendLog=function(e){return f(this,void 0,void 0,(function(){var t,n,i,o,r,a;return h(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=_().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=s.sent()).ok?[3,3]:(o=(i=m).error,r=["Failed to send error log:"],[4,n.text()]);case 2:o.apply(i,r.concat([s.sent()])),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),m.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return f(this,void 0,void 0,(function(){var i,o,r;return h(this,(function(a){switch(a.label){case 0:if(this.isInitialized)return[3,5];i={org_id:"UNINITALIZED",event_data:{message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:p(p({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:S(),event_type:E.ERROR,user_id:this.userId},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return a.sent(),[3,4];case 3:return a.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),m.warn("Error tracked before initialization, queuing:",e),[3,4];case 4:return[2];case 5:return o={message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:p(p({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:S(),event_type:E.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return f(this,void 0,void 0,(function(){var i,o;return h(this,(function(r){switch(r.label){case 0:return this.apiKey?(i={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},o={org_id:this.apiKey,event_data:i,metadata:S(),event_type:E.INFO,user_id:this.userId},[4,this.sendLog(o)]):(m.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),z=L.getInstance(),N="MISSING_API_KEY",M="INVALID_API_KEY",H="CONFIG_FETCH_FAILED",B="SDK_INIT_FAILED",j="ERROR_TRACKING_INIT_FAILED",F="API_REQUEST_FAILED",U="NETWORK_ERROR",W="INVALID_RESPONSE",P="IFRAME_LOAD_FAILED",V="COOKIE_ACCESS_ERROR",G="COMPONENT_RENDER_ERROR",K="INITIALIZATION_ERROR",J="API_ERROR",Z="RUNTIME_ERROR",Y="COMPONENT_ERROR",Q=((R={})[N]=function(e){return"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===e?"undefined":null===e?"null":""===e?"empty string":"invalid: ".concat(e),". A valid API key string is required to initialize the SDK.")},R[M]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},R[H]=function(e){return"Failed to fetch chatbot configuration: ".concat(e.statusCode?"Server responded with status ".concat(e.statusCode):"Could not reach server").concat(e.error?". Error: ".concat(e.error):"")},R[F]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},R[U]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},R[P]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},R[W]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},R[j]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},R[B]=function(e){return"SDK Initialization Failed: ".concat(e.reason||"Could not initialize the chatbot SDK").concat(e.config?". Attempted initialization with config: ".concat(JSON.stringify(e.config,null,2)):"")},R[V]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},R[G]=function(e){return"React Component Error: ".concat(e.component||"Unknown component"," failed to render. Error: ").concat(e.error).concat(e.stack?"\nComponent Stack: ".concat(e.stack):"")},R),X=t((function(t){var i,a,s,l,c=t.config,d=t.isVisible,u=t.onClose,p=t.onEvent,f=t.onInternalEvent,h=n(null),v=n(!1),m=n(!1),g=null!==(a=null===(i=c.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==a?a:20,y=r((function(){var e,t,n=h.current;if(n){var i=(null===(t=c.interface_properties)||void 0===t?void 0:t.position)||"Right",o=((e={width:(null===window||void 0===window?void 0:window.innerWidth)<560?"100vw":"26%",minWidth:(null===window||void 0===window?void 0:window.innerWidth)<560?"300px":"400px",height:(null===window||void 0===window?void 0:window.innerWidth)<560?"100vh":"calc(100vh - 2rem - 10vh - ".concat(g,"px)"),borderRadius:(null===window||void 0===window?void 0:window.innerWidth)<560?"0":"1rem",position:(null===window||void 0===window?void 0:window.innerWidth)<560?"fixed":"",maxHeight:(null===window||void 0===window?void 0:window.innerWidth)<560?"100%":"50rem",top:(null===window||void 0===window?void 0:window.innerWidth)<560?"0":"calc(10vh - 32px)"})[i.toLowerCase()]=(null===window||void 0===window?void 0:window.innerWidth)<560?"0":void 0,e.flexDirection=(null===window||void 0===window?void 0:window.innerWidth)<560?"column":void 0,e.flexGrow=(null===window||void 0===window?void 0:window.innerWidth)<560?"1":void 0,e);Object.assign(n.style,o)}}),[g,null===(s=c.interface_properties)||void 0===s?void 0:s.position]);return o((function(){var e,t=h.current;if(t&&!v.current){var n=_().copilotUrl,i=(null===(e=c.interface_properties)||void 0===e?void 0:e.position)||"Right";Object.assign(t.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(i.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"}),t.src="".concat(n,"/chatbot-plugin?id=").concat(c.chatbotId),v.current=!0,y();var o=function(){var e,i,o=new URL(t.src).origin||n;null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,name:"checkDomain"},o)};return t.addEventListener("load",o),function(){return t.removeEventListener("load",o)}}}),[c.chatbotId,null===(l=c.interface_properties)||void 0===l?void 0:l.position,y]),o((function(){var e,t,n,i,o,r=h.current;if(r&&v.current){var a=(null===(e=c.interface_properties)||void 0===e?void 0:e.position)||"Right";if(d?(Object.assign(r.style,{transform:"scale(0.3) translate3d(0,40px,0)",opacity:"0",display:"block"}),r.getBoundingClientRect(),setTimeout((function(){Object.assign(r.style,{transform:"scale(1) translate3d(0,0,0)",opacity:"1",transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 0.15s ease-out"})}),20)):(r.style.transition="none",r.getBoundingClientRect(),Object.assign(r.style,{opacity:"0",transform:"scale(0.3) translate3d(".concat((a.toLowerCase(),"0"),",40px,0)"),transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 0.15s ease-out"}),setTimeout((function(){!d&&r&&(r.style.display="none")}),200)),r.contentWindow&&d){var s=_().copilotUrl;null===(t=null==r?void 0:r.contentWindow)||void 0===t||t.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},s),(null==m?void 0:m.current)||(null===(i=r.contentWindow)||void 0===i||i.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==c?void 0:c.userId,token:null==c?void 0:c.token,userProfile:null==c?void 0:c.userProfile,isAnonymous:null==c?void 0:c.isAnonymous}},s),m.current=!0)}}}),[d,c.userId,c.token,c.userProfile]),o((function(){if(h.current&&v.current){var e=_().copilotUrl;d&&(null==p||p({type:b.CHATBOT_OPENED,timestamp:Date.now()}),f(b.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,s,l;if(t.origin===e){if("closeChatbot"===t.data)return void u();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void f(w.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==p||p({type:b.CHATBOT_LOADED,timestamp:Date.now()}),f(b.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==p||p({type:b.CHAT_INITIALIZED,timestamp:Date.now()}),f(b.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==p||p({type:b.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),f(b.CHAT_INITIALIZATION_FAILED,{error:null===(a=t.data)||void 0===a?void 0:a.error})),"SESSION_REFRESHED"===(null===(s=t.data)||void 0===s?void 0:s.type)&&(null==p||p({type:b.SESSION_REFRESHED,timestamp:Date.now()}),f(b.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(l=t.data)||void 0===l?void 0:l.type)&&f(w.CHAT_MOVED,{from:t.data.from,to:t.data.to,trigger:t.data.trigger})}};return null===window||void 0===window||window.addEventListener("message",t),function(){return null===window||void 0===window?void 0:window.removeEventListener("message",t)}}}),[u,p,f,c.chatbotId,d]),o((function(){var e=h.current;if(e&&v.current){var t=function(){z.trackError(new Error(Q[P]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:P,errorType:Z,context:{config:c,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[c]),o((function(){var e;if(h.current&&c&&d){var t=h.current,n=_().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:c.userProfile},n)}}),[c.userProfile,d]),e.createElement("iframe",{ref:h,id:"chat-iframe-rbyln",style:{display:"none"}})})),q=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={hasError:!1},t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.getDerivedStateFromError=function(e){return{hasError:!0}},t.prototype.componentDidCatch=function(e,t){z.trackError(new Error(Q[G]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:G,errorType:Y,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(a),$=function(e,t,n){return f(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return h(this,(function(u){switch(u.label){case 0:i=_().apiUrl,o="".concat(i,"/chat/chatbot/get/"),m.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{}},u.label=1;case 1:return u.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 2:return(a=u.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=u.sent(),new Error(Q[F](a.status,s));case 4:return[4,a.json()];case 5:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(Q[W](["user","org_info"]));return[2,l];case 6:throw c=u.sent(),z.trackError(c instanceof Error?c:new Error(Q[U]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?F:U,errorType:J,context:{chatbotId:e,userId:t,apiUrl:i,statusCode:c instanceof Response?c.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),c;case 7:return[2]}}))}))},ee=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},te=function(e){var t,n="; ".concat(document.cookie).split("; ".concat(e,"="));if(2===n.length)return null===(t=n.pop())||void 0===t?void 0:t.split(";").shift()},ne=function(e,t,n){var i=new Date;i.setTime(i.getTime()+24*n*60*60*1e3),document.cookie="".concat(e,"=").concat(t,";expires=").concat(i.toUTCString(),";path=/")},ie=function(e){var t=e?"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(e){var t=e.split("="),n=t[0],i=t.slice(1).join("=").trim();return{name:n=n.trim(),value:i?decodeURIComponent(i):""}})),t},oe=function(){function e(e){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=e,this.validateDomain()&&this.init(),null===window||void 0===window||window.addEventListener("message",this.onCloseListener.bind(this),!1)}return e.prototype.onCloseListener=function(e){e.origin===this.config.domain&&"closeChatbot"===e.data&&this.closeIframe()},e.prototype.validateDomain=function(){var e,t=this.config.domain,n=null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.origin;return m.log("expectedDomain, to current domain",t,n,t===n),t===n},e.prototype.createChatBubblContainer=function(){var e,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 i=document.createElement("div");i.classList.add("close-btn"),i.textContent="✕",Object.assign(i.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===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var i=t.createMessageBubble(e);n.appendChild(i)})),n.appendChild(i),document.body.appendChild(n)},e.prototype.createMessageBubble=function(e){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=e,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 i=document.createElement("button");return i.innerHTML="&times;",Object.assign(i.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"}),i.addEventListener("click",(function(){t.remove()})),t.appendChild(i),t.appendChild(n),t},e.prototype.createFloatingButton=function(){var e=document.createElement("div");e.classList.add("message-bubble-container"),Object.assign(e.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:v(this.config.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),document.body.appendChild(e),this.logoContainer=e,this.loadImage(this.logoContainer),this.createChatBubblContainer(),this.logoContainer.addEventListener("click",this.toggleIframe.bind(this))},e.prototype.loadImage=function(e){var t,n,i=document.createElement("img");i.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"),i.alt="Chat",Object.assign(i.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=i,e.innerHTML="",e.appendChild(i)},e.prototype.createIframe=function(){var e=this;m.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),m.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){(null===window||void 0===window?void 0:window.innerWidth)<560?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,i,o,r;if(e.iframe){var a=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,name:"checkDomain"},a),null===(o=t.contentWindow)||void 0===o||o.postMessage({domain:null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hostname,action:"registerUserId",data:{userId:e.config.userId,token:e.config.token,userProfile:e.config.userProfile}},a)}})),null===window||void 0===window||window.addEventListener("message",(function(n){var i,o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,a={cookies:ie(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(a,e.config.domain||"*")}"expand"===n.data&&(e.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)"})}}))},e.prototype.adjustIframeWidth=function(){if(this.iframe){var e=null===window||void 0===window?void 0:window.innerWidth;m.log("screenWidth",e),this.iframe.style.width=e<832?"".concat(e-64,"px"):"800px"}},e.prototype.loadSvgInline=function(e){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");e.innerHTML="",n&&e.appendChild(n)},e.prototype.toggleIcon=function(e,t){"block"===t.style.display?this.loadSvgInline(e):this.loadImage(e)},e.prototype.toggleIframe=function(){var e;if(m.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;m.log("toggleIframe"),null===(e=this.iframe.contentWindow)||void 0===e||e.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"),m.log("this.bubblePromptContainer",this.bubblePromptContainer)}},e.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")},e.prototype.init=function(){this.createIframe(),this.createFloatingButton()},e}(),re=function(e,t,n){if(e.chatbotId&&e.userId)try{new oe(e);t(!0),m.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},ae=function(e){var t=s((function(){return function(e){return{api_key:String(e.api_key||""),user_id:e.user_id?String(e.user_id):null,user_token:e.user_token?String(e.user_token):void 0,user_profile:e.user_profile||{}}}(e)}),[e.api_key,e.user_id,e.user_token,JSON.stringify(e.user_profile)]),n=i({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),a=n[0],l=n[1],v=s((function(){var e=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"];return t.user_profile?Object.fromEntries(Object.entries(t.user_profile).filter((function(t){var n=t[0];return e.includes(n)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(t.user_profile)]),m=r((function(e){l((function(t){return p(p({},t),e)}))}),[]),g=r((function(){return f(void 0,void 0,void 0,(function(){var e,n,i,o,r,a,s,l,f,g,b,w,y,_,E,I,x,T,C,O,A,R,D,k,L,M,H,j,F,U;return h(this,(function(h){switch(h.label){case 0:if(!t.api_key)return z.trackError(new Error(Q[N](t.api_key)),"useChatbotState",{errorCode:N,errorType:K,context:{timestamp:Date.now()}}),[2];m({isInitializing:!0}),h.label=1;case 1:return h.trys.push([1,4,5,6]),e=t.user_id||void 0,n=!1,e||(e=te("rblyn_anon")||ee(),ne("rblyn_anon",e,365),n=!0),[4,$(t.api_key,e,t.user_token)];case 2:return i=h.sent(),o=S(),r=p(p({},o),v),a={chatbotId:t.api_key,userId:e,token:t.user_token,isAnonymous:n,domain:"",brand_colour:(null===(g=null===(f=i.user.org_info.brand_config)||void 0===f?void 0:f.colors)||void 0===g?void 0:g.brand_color)||"",image_url:(null===(w=null===(b=i.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===w?void 0:w.launcher_logo_url)||"",userProfile:r,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(y=i.user.org_info.brand_config)||void 0===y?void 0:y.display_name)||"",welcome_message:(null===(_=i.user.org_info.brand_config)||void 0===_?void 0:_.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(E=i.user.org_info.brand_config)||void 0===E?void 0:E.redirect_url)||""},interface_properties:{position:(null===(x=null===(I=i.user.org_info.brand_config)||void 0===I?void 0:I.interface_properties)||void 0===x?void 0:x.position)||d.RIGHT,side_spacing:null!==(O=null===(C=null===(T=i.user.org_info.brand_config)||void 0===T?void 0:T.interface_properties)||void 0===C?void 0:C.side_spacing)&&void 0!==O?O:20,bottom_spacing:null!==(D=null===(R=null===(A=i.user.org_info.brand_config)||void 0===A?void 0:A.interface_properties)||void 0===R?void 0:R.bottom_spacing)&&void 0!==D?D:20},interface_type:(null===(k=i.user.org_info.brand_config)||void 0===k?void 0:k.interface_type)||c.WIDGET,launcher_type:(null===(L=i.user.org_info.brand_config)||void 0===L?void 0:L.launcher_type)||u.IMAGE,launcher_properties:{text:(null===(H=null===(M=i.user.org_info.brand_config)||void 0===M?void 0:M.launcher_properties)||void 0===H?void 0:H.text)||""},images:{launcher_image_url:{url:(null===(U=null===(F=null===(j=i.user.org_info.brand_config)||void 0===j?void 0:j.images)||void 0===F?void 0:F.launcher_image_url)||void 0===U?void 0:U.url)||""}}},[4,new Promise((function(e,t){re(a,(function(){m({isInitialized:!0,chatbotConfig:a}),e()}),(function(e){t(e)}))}))];case 3:return h.sent(),[3,6];case 4:return s=h.sent(),l=s instanceof Error?s.message:"Failed to initialize chatbot",m({error:l}),z.trackError(s instanceof Error?s:new Error(l),"useChatbotState",{errorCode:B,errorType:K,context:{timestamp:Date.now()}}),[3,6];case 5:return m({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[t.api_key,t.user_id,t.user_token]);o((function(){t.api_key&&g()}),[g]),o((function(){a.chatbotConfig&&l((function(e){return p(p({},e),{chatbotConfig:p(p({},e.chatbotConfig),{userProfile:p(p({},S()),v)})})}))}),[v]);var b=r((function(){l((function(e){return p(p({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),w=r((function(){m({isIframeVisible:!1})}),[]);return p(p({},a),{toggleIframeVisibility:b,closeIframe:w})},se=function(e){var t=e.api_key,n=e.chatbotConfig,i=e.user_profile,o=e.onEvent,a=s((function(){return{isAnonymous:(null==n?void 0:n.isAnonymous)||!1,userId:(null==n?void 0:n.userId)||""}}),[null==n?void 0:n.isAnonymous,null==n?void 0:n.userId]),l=s((function(){return i||{}}),[JSON.stringify(i)]),c=r((function(e){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return f(void 0,function(e,t,n){if(n||2===arguments.length)for(var i,o=0,r=t.length;o<r;o++)!i&&o in t||(i||(i=Array.prototype.slice.call(t,0,o)),i[o]=t[o]);return e.concat(i||Array.prototype.slice.call(t))}([e],n,!0),void 0,(function(e,n){var i,o,r,s,c,d,u;return void 0===n&&(n={}),h(this,(function(f){switch(f.label){case 0:if(!t)return[2];f.label=1;case 1:return f.trys.push([1,3,,4]),i=_().apiUrl,o=S(),r=p({trigger_time:Date.now(),channel:"CHATBOT",launch_url:(null===(u=null===window||void 0===window?void 0:window.location)||void 0===u?void 0:u.href)||"",org_id:t,client_user_id:a.isAnonymous?"Anonymous":String(a.userId),event_type:e,user_profile:l},n),s={org_id:t,event_data:r,metadata:p({timestamp:Date.now()},o),event_type:"INFO",user_id:a.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 2:if(!(c=f.sent()).ok)throw new Error("Failed to send internal event: ".concat(c.statusText));return[3,4];case 3:return d=f.sent(),m.error("Failed to send internal event:",d),[3,4];case 4:return[2]}}))}))}),[t,a]);return{emitEvent:r((function(e,t){var n=Date.now();e!==b.CHATBOT_BUTTON_CLICKED&&e!==b.CHATBOT_CLOSED&&e!==b.CHATBOT_OPENED||(o&&o({type:e,timestamp:n,data:t}),c(e,{timestamp:n}))}),[o,c]),onInternalEvent:c}},le=function(t){var n,r,a,s,l,c,d,u=t.children,f=t.config,h=i(!1),v=h[0],g=h[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;g(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]);var b=(null===(a=f.interface_properties)||void 0===a?void 0:a.position)||"Right",w=null!==(l=null===(s=f.interface_properties)||void 0===s?void 0:s.side_spacing)&&void 0!==l?l:20,y=null!==(d=null===(c=f.interface_properties)||void 0===c?void 0:c.bottom_spacing)&&void 0!==d?d:20;m.log("config",f,b,w);var _={position:"fixed",zIndex:1e3,display:"flex",flexDirection:"column"},E=p(p({},_),((n={bottom:"".concat(y,"px")})[b.toLowerCase()]="".concat(null!=w?w:20,"px"),n.alignItems="Right"===b?"flex-end":"flex-start",n.top=void 0,n["Right"===b?"left":"right"]=void 0,n)),I=p(p({},_),((r={top:0})[b.toLowerCase()]="".concat(null!=w?w:20,"px"),r.alignItems="center",r.bottom=void 0,r["Right"===b?"left":"right"]=void 0,r)),x=v?I:E;return o((function(){console.log("Container screen width changed, isMobile:",v,"Style:",x)}),[v,x]),e.createElement("div",{className:"robylon-chatbot-container",style:x},u)},ce=t((function(t){var n=t.api_key,i=t.user_id,a=t.user_token,l=t.user_profile,c=t.onEvent;o((function(){}));var d=s((function(){return{api_key:n,user_id:i,user_token:a,user_profile:l}}),[n,i,a,l]),u=r((function(e){null==c||c(e)}),[c]),f=ae(d),h=f.isInitialized,v=f.error,g=f.chatbotConfig,w=f.isIframeVisible,y=f.toggleIframeVisibility,_=f.closeIframe,E=s((function(){return{api_key:n,user_profile:d.user_profile,onEvent:u,chatbotConfig:g?{isAnonymous:g.isAnonymous,userId:g.userId}:null}}),[n,d.user_profile,u,null==g?void 0:g.isAnonymous,null==g?void 0:g.userId]),I=se(p({},E)),x=I.emitEvent,C=I.onInternalEvent;o((function(){if(n)try{z.initialize(n,i)}catch(e){z.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:j,errorType:K,context:{timestamp:Date.now()}})}else z.trackError(new Error(Q[N](n)),"RobylonChatbot",{errorCode:N,errorType:K,context:{timestamp:Date.now()}})}),[n,i]);var O=r((function(){_(),x(b.CHATBOT_CLOSED)}),[_,x]),A=r((function(){y(),x(w?b.CHATBOT_CLOSED:b.CHATBOT_BUTTON_CLICKED)}),[y,x,w]),S=s((function(){return{config:g,toggleIframe:A,isIframeVisible:w,onEvent:u,onInternalEvent:C}}),[g,A,w,u,C]);m.log("floatingButtonProps",S);var R=s((function(){return{config:g,isVisible:w,onClose:O,onEvent:u,onInternalEvent:C}}),[g,w,O,u,C]);return n&&!v&&g?e.createElement(q,{componentName:"RobylonChatbot"},h?e.createElement(le,{config:g},e.createElement(q,{componentName:"ChatbotIframe"},e.createElement(X,p({},R))),e.createElement(q,{componentName:"ChatbotFloatingButton"},e.createElement(T,p({},S)))):null):null}),(function(e,t){return e.api_key===t.api_key&&e.user_id===t.user_id&&e.user_token===t.user_token&&JSON.stringify(e.user_profile)===JSON.stringify(t.user_profile)&&!0})),de=function(e){var t=i({isLoading:!0,isInitialized:!1,error:null}),n=t[0],r=t[1],a=function(e){r((function(t){return p(p({},t),{isInitialized:e})}))},s=function(e){r((function(t){return p(p({},t),{error:e})}))};return o((function(){!function(){try{re(e,a,s)}catch(e){r((function(t){return p(p({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),n},ue=function(){function e(e){this.resizeObserver=null,this.config=e,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount(),this.setupResizeListener()}return e.prototype.render=function(){var e=this;_().copilotUrl;var t=this.config,n=t.config,i={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:I};n.launcher_type===u.IMAGE&&Object.assign(i,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:n.brand_colour}),this.applyResponsiveStyles(i),this.buttonElement.className="message-bubble-container",this.buttonElement.innerHTML="",this.buttonElement.appendChild(this.createLauncherElement()),this.buttonElement.onclick=function(){e.config.toggleIframe()}},e.prototype.createLauncherElement=function(){var e,t,n=this.config,i=n.config,o=n.isIframeVisible,r=_().copilotUrl;switch(console.log("config in floating button",i),i.launcher_type){case u.TEXT:return this.createTextLauncher();case u.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case u.IMAGE:default:if(o){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 s=document.createElement("img");return s.src=i.launcher_type?(null===(t=null===(e=i.images)||void 0===e?void 0:e.launcher_image_url)||void 0===t?void 0:t.url)||"".concat(r,"/chatbubble.png"):i.image_url||"".concat(r,"/chatbubble.png"),s.alt="Chat",Object.assign(s.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),s}},e.prototype.createTextLauncher=function(){var e=this.config.config,t=e.brand_colour,n=e.launcher_properties,i=document.createElement("div");Object.assign(i.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 o=document.createElement("div");Object.assign(o.style,{flex:"1",minWidth:"0"});var r=document.createElement("p");return Object.assign(r.style,{margin:"0",color:v(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:x,fontFamily:I,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),r.textContent=(null==n?void 0:n.text)||"",o.appendChild(r),i.appendChild(o),i},e.prototype.createTextualImageLauncher=function(){var e,t,n,i,o,r,a=_().copilotUrl,s=this.config.config,l=s.brand_colour,c=s.launcher_properties,d=s.image_url,u=document.createElement("div");Object.assign(u.style,{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:l,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 p=document.createElement("div");Object.assign(p.style,{flex:"1",minWidth:"0"});var f=document.createElement("p");Object.assign(f.style,{margin:"0",color:v(l),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:x,fontFamily:I,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),f.textContent=(null==c?void 0:c.text)||"";var h=document.createElement("div");Object.assign(h.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var m=document.createElement("img");return m.src=(null===(t=null===(e=null==this?void 0:this.config)||void 0===e?void 0:e.config)||void 0===t?void 0:t.launcher_type)?(null===(r=null===(o=null===(i=null===(n=null==this?void 0:this.config)||void 0===n?void 0:n.config)||void 0===i?void 0:i.images)||void 0===o?void 0:o.launcher_image_url)||void 0===r?void 0:r.url)||"".concat(a,"/chatbubble.png"):d||"".concat(a,"/chatbubble.png"),m.alt="Chat",Object.assign(m.style,{width:"100%",height:"100%",objectFit:"cover"}),p.appendChild(f),h.appendChild(m),u.appendChild(p),u.appendChild(h),u},e.prototype.applyResponsiveStyles=function(e){var t,n,i,o,r,a=(null===window||void 0===window?void 0:window.innerWidth)<560,s=this.config.config,l=(null===(i=s.interface_properties)||void 0===i?void 0:i.position)||"Right",c=(null===(o=s.interface_properties)||void 0===o?void 0:o.side_spacing)||20,d=(null===(r=s.interface_properties)||void 0===r?void 0:r.bottom_spacing)||20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var u=p(p({},e),a?((t={position:"fixed",bottom:"".concat(d,"px")})[l.toLowerCase()]="".concat(c,"px"),t):((n={bottom:"0"})[l.toLowerCase()]="0",n));Object.assign(this.buttonElement.style,u)},e.prototype.handleResize=function(){var e={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!==u.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===u.IMAGE&&Object.assign(e,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:this.config.config.brand_colour}),this.applyResponsiveStyles(e)},e.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},e.prototype.getElement=function(){return this.buttonElement},e.prototype.mount=function(){var e=this;requestAnimationFrame((function(){var t,n;null===(n=(t=e.config).onEvent)||void 0===n||n.call(t,{type:b.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(b.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config.isIframeVisible,this.config=p(p({},this.config),e),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render()},e.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)},e}(),pe=function(){function e(e){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(e){var n,i,o,r,a,s,l,c,d,u,p,f,h,v,m,g=_().copilotUrl;if(e.origin===g){if("closeChatbot"===e.data)return void t.config.onClose();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=e.data)||void 0===n?void 0:n.type))return void t.config.onInternalEvent(w.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=e.data)||void 0===i?void 0:i.type)&&(null===(r=(o=t.config).onEvent)||void 0===r||r.call(o,{type:b.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(b.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=e.data)||void 0===a?void 0:a.type)&&(null===(l=(s=t.config).onEvent)||void 0===l||l.call(s,{type:b.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(b.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(c=e.data)||void 0===c?void 0:c.type)&&(null===(u=(d=t.config).onEvent)||void 0===u||u.call(d,{type:b.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(b.CHAT_INITIALIZATION_FAILED,{error:null===(p=e.data)||void 0===p?void 0:p.error})),"SESSION_REFRESHED"===(null===(f=e.data)||void 0===f?void 0:f.type)&&(null===(v=(h=t.config).onEvent)||void 0===v||v.call(h,{type:b.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(b.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(m=e.data)||void 0===m?void 0:m.type)&&t.config.onInternalEvent(w.CHAT_MOVED,{from:e.data.from,to:e.data.to,trigger:e.data.trigger})}},this.config=e,this.iframeElement=document.createElement("iframe"),this.iframeElement.id="chat-iframe-rbyln",this.resizeHandler=this.applyResponsiveStyles.bind(this),this.render(),this.initialize(),this.setupEventListeners()}return e.prototype.getElement=function(){return this.iframeElement},e.prototype.render=function(){var e,t=(null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.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()},e.prototype.applyResponsiveStyles=function(){var e,t,n,i,o;if(this.iframeElement){var r=null!==(i=null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.bottom_spacing)&&void 0!==i?i:20,a=(null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.position)||"Right";window.innerWidth<560?Object.assign(this.iframeElement.style,((e={width:"100vw",minWidth:"300px"})[a.toLowerCase()]="0",e.bottom="0",e.height="100vh",e.flexDirection="column",e.flexGrow="1",e.borderRadius="0",e.top="0",e.maxHeight="100%",e.position="fixed",e)):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:""})[a.toLowerCase()]=void 0,t))}},e.prototype.initialize=function(){var e=this;if(!this.isInitialized){var t=_().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,i,o=new URL(e.iframeElement.src).origin||t;null===(n=e.iframeElement.contentWindow)||void 0===n||n.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,name:"checkDomain"},o)}))}},e.prototype.setupEventListeners=function(){var e=this;window.addEventListener("resize",this.resizeHandler),this.iframeElement.addEventListener("error",(function(){z.trackError(new Error(Q[P]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:P,errorType:Z,context:{config:e.config.config,iframeUrl:e.iframeElement.src,timestamp:Date.now()}})})),window.addEventListener("message",this.handleMessage)},e.prototype.updateVisibility=function(e){var t,n,i,o,r,a,s,l,c,d=this;this.config.isVisible=e;var u=(null===(t=this.config.config.interface_properties)||void 0===t?void 0:t.position)||"Right";if(e?(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((u.toLowerCase(),"0"),",40px,0)"),setTimeout((function(){d.config.isVisible||(d.iframeElement.style.display="none")}),200)),this.iframeElement.contentWindow&&e){var p=_().copilotUrl,f=new URL(this.iframeElement.src).origin||p;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"},f),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.hostname,action:"registerUserId",data:{userId:null===(o=this.config.config)||void 0===o?void 0:o.userId,token:null===(r=this.config.config)||void 0===r?void 0:r.token,userProfile:null===(a=this.config.config)||void 0===a?void 0:a.userProfile,isAnonymous:null===(s=this.config.config)||void 0===s?void 0:s.isAnonymous}},f),this.hasRegistered=!0),null===(c=(l=this.config).onEvent)||void 0===c||c.call(l,{type:b.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(b.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=p(p({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=_().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},e.prototype.destroy=function(){window.removeEventListener("resize",this.resizeHandler),window.removeEventListener("message",this.handleMessage),this.iframeElement&&this.iframeElement.parentNode&&this.iframeElement.parentNode.removeChild(this.iframeElement)},e}(),fe=function(){function e(e){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config=e,this.render(),this.mount(),this.setupResizeListener()}return e.prototype.render=function(){this.applyStyles(),this.containerElement.className="robylon-chatbot-container"},e.prototype.applyStyles=function(){var e,t,n,i,o,r,a,s=(null===window||void 0===window?void 0:window.innerWidth)<560,l=(null===(n=this.config.interface_properties)||void 0===n?void 0:n.position)||"Right",c=null!==(o=null===(i=this.config.interface_properties)||void 0===i?void 0:i.side_spacing)&&void 0!==o?o:20,d=null!==(a=null===(r=this.config.interface_properties)||void 0===r?void 0:r.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 u={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},f=p(p({},u),((e={bottom:"".concat(d,"px")})[l.toLowerCase()]="".concat(c,"px"),e.alignItems="Right"===l?"flex-end":"flex-start",e)),h=p(p({},u),((t={top:"0"})[l.toLowerCase()]="".concat(c,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,s?h:f)},e.prototype.handleResize=function(){this.applyStyles()},e.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},e.prototype.mount=function(){document.body.appendChild(this.containerElement)},e.prototype.getElement=function(){return this.containerElement},e.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)},e}(),he=function(e,t,n){return f(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return h(this,(function(u){switch(u.label){case 0:return u.trys.push([0,5,,6]),i=_().apiUrl,o="".concat(i,"/chat/chatbot/get/"),m.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{}},[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(a=u.sent()).ok?[3,3]:[4,a.text()];case 2:throw s=u.sent(),new Error(Q[F](a.status,s));case 3:return[4,a.json()];case 4:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(Q[W](["user","org_info"]));return[2,l];case 5:throw c=u.sent(),z.trackError(c instanceof Error?c:new Error(Q[U]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?F:U,errorType:J,context:{apiKey:e,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},ve=function(e){return f(void 0,void 0,void 0,(function(){var t,n,i,o,r,a,s,l,f,v,m,g,b,w,y,_,E,I,x,T,C,O,A,R,D,k,L;return h(this,(function(h){switch(h.label){case 0:return t=function(e){return{api_key:String(e.api_key||""),user_id:e.user_id?String(e.user_id):null,user_token:e.user_token?String(e.user_token):void 0,user_profile:e.user_profile||{}}}(e),n=t.user_id||void 0,i=!1,n||(n=te("rblyn_anon")||ee(),ne("rblyn_anon",n,365),i=!0),[4,he(t.api_key,n,t.user_token)];case 1:return o=h.sent(),r=S(),z=t.user_profile,N=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],a=z?Object.fromEntries(Object.entries(z).filter((function(e){var t=e[0];return N.includes(t)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},s=p(p({},r),a),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",brand_colour:(null===(f=null===(l=o.user.org_info.brand_config)||void 0===l?void 0:l.colors)||void 0===f?void 0:f.brand_color)||"",image_url:(null===(m=null===(v=o.user.org_info)||void 0===v?void 0:v.brand_config)||void 0===m?void 0:m.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(g=o.user.org_info.brand_config)||void 0===g?void 0:g.display_name)||"",welcome_message:(null===(b=o.user.org_info.brand_config)||void 0===b?void 0:b.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(w=o.user.org_info.brand_config)||void 0===w?void 0:w.redirect_url)||""},launcher_type:(null===(y=o.user.org_info.brand_config)||void 0===y?void 0:y.launcher_type)||u.IMAGE,launcher_properties:{text:(null===(E=null===(_=o.user.org_info.brand_config)||void 0===_?void 0:_.launcher_properties)||void 0===E?void 0:E.text)||""},images:{launcher_image_url:{url:(null===(T=null===(x=null===(I=o.user.org_info.brand_config)||void 0===I?void 0:I.images)||void 0===x?void 0:x.launcher_image_url)||void 0===T?void 0:T.url)||""}},interface_properties:{position:(null===(O=null===(C=o.user.org_info.brand_config)||void 0===C?void 0:C.interface_properties)||void 0===O?void 0:O.position)||d.RIGHT,side_spacing:(null===(R=null===(A=o.user.org_info.brand_config)||void 0===A?void 0:A.interface_properties)||void 0===R?void 0:R.side_spacing)||20,bottom_spacing:(null===(k=null===(D=o.user.org_info.brand_config)||void 0===D?void 0:D.interface_properties)||void 0===k?void 0:k.bottom_spacing)||20},interface_type:(null===(L=o.user.org_info.brand_config)||void 0===L?void 0:L.interface_type)||c.WIDGET}]}var z,N}))}))},me=function(e){e.api_key,e.user_profile;var t=e.onEvent;e.chatbotConfig;return{emit:function(e,n){var i={type:e,timestamp:Date.now(),data:n};null==t||t(i)},onInternalEvent:function(e,t){}}},ge=function(){function e(e){var t,n,i,o,r=this;if(this.container=null,this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){if(!r.isDestroyed){var t=e.isInitialized,n=e.error,i=e.chatbotConfig,o=e.isIframeVisible;if(!n&&i&&t){if(r.eventEmitter=me({api_key:r.config.api_key,user_profile:r.config.user_profile,onEvent:r.config.onEvent,chatbotConfig:{isAnonymous:i.isAnonymous,userId:i.userId}}),r.container||(r.container=new fe(i)),r.iframe)r.iframe.update({config:i,isVisible:o});else if(r.iframe=new pe({config:i,isVisible:o,onClose:r.handleClose,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}),r.iframe.getElement&&"function"==typeof r.iframe.getElement){var a=r.iframe.getElement();a&&r.container&&r.container.getElement().prepend(a)}if(r.floatingButton)r.floatingButton.update({config:i,isIframeVisible:o});else if(r.floatingButton=new ue({config:i,toggleIframe:r.toggleIframe,isIframeVisible:o,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}),r.floatingButton.getElement&&"function"==typeof r.floatingButton.getElement){var s=r.floatingButton.getElement();s&&r.container&&r.container.getElement().appendChild(s)}}}},this.toggleIframe=function(){var e=r.stateManager.getState();r.stateManager.toggleIframeVisibility(),r.eventEmitter.emit(e.isIframeVisible?b.CHATBOT_CLOSED:b.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){r.stateManager.closeIframe(),r.eventEmitter.emit(b.CHATBOT_CLOSED)},this.config=e,!e.api_key)throw z.trackError(new Error(Q[N](e.api_key)),"RobylonChatbot",{errorCode:N,errorType:K,context:{timestamp:Date.now()}}),new Error("API key is required");try{z.initialize(e.api_key,e.user_id)}catch(e){z.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:j,errorType:K,context:{timestamp:Date.now()}})}this.stateManager=(t={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},n={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},i=[],{getState:function(){return n},initialize:function(){return f(void 0,void 0,void 0,(function(){var e,n,i;return h(this,(function(r){switch(r.label){case 0:if(!t.api_key)return z.trackError(new Error(Q[N](t.api_key)),"ChatbotStateManager",{errorCode:N,errorType:K,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,ve(t)];case 2:return e=r.sent(),[4,new Promise((function(t,n){re(e,(function(){o({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),i=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:i}),z.trackError(n instanceof Error?n:new Error(i),"ChatbotStateManager",{errorCode:B,errorType:K,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!n.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o=function(e){n=p(p({},n),e),i.forEach((function(e){return e(n)}))},subscribe:function(e){return i.push(e),function(){var t=i.indexOf(e);t>-1&&i.splice(t,1)}},unsubscribe:function(e){var t=i.indexOf(e);t>-1&&i.splice(t,1)}}),this.eventEmitter=me({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),this.initialize()}return e.prototype.initialize=function(){return f(this,void 0,void 0,(function(){var e;return h(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 e=t.sent(),z.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:B,errorType:K,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(b.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(b.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.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)},e.prototype.getState=function(){return this.stateManager.getState().isInitialized?"initialized":"uninitialized"},e}();function be(e){return new ge(e)}"undefined"!=typeof window&&function(){if("undefined"!=typeof window){var e=window.RobylonChatbot;if(e&&Array.isArray(e.q)){var t=null;e.q.forEach((function(e){var n=e[0];if("init"===n){var i=e[1]||{};t=be(i)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(e){for(var n,i=[],o=1;o<arguments.length;o++)i[o-1]=arguments[o];return"init"===e?t=be(i[0]||{}):t&&"function"==typeof t[e]?(n=t)[e].apply(n,i):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var we={create:be,getState:function(){return"initialized"}};export{ce as Chatbot,c as ChatbotInterfaceType,u as LauncherType,we as RobylonChatbot,d as WidgetPositionEnums,de as useChatbot};
2
2
  //# sourceMappingURL=index.js.map