@robylon/web-react-sdk 1.1.40-staging.5 → 1.1.40-staging.6
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/cjs/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/umd/robylon-chatbot.js +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=function(e,n){return t=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])},t(e,n)};var n,i,o,r,a=function(){return a=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},a.apply(this,arguments)};function s(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 l(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,exports.ChatbotInterfaceType=void 0,(n=exports.ChatbotInterfaceType||(exports.ChatbotInterfaceType={})).WIDGET="WIDGET",n.POPOVER="POPOVER",n.EMBED="EMBED",exports.WidgetPositionEnums=void 0,(i=exports.WidgetPositionEnums||(exports.WidgetPositionEnums={})).RIGHT="Right",i.LEFT="Left",exports.LauncherType=void 0,(o=exports.LauncherType||(exports.LauncherType={})).TEXT="TEXT",o.IMAGE="IMAGE",o.TEXTUAL_IMAGE="TEXTUAL_IMAGE",exports.ProactiveSendTimeType=void 0,(r=exports.ProactiveSendTimeType||(exports.ProactiveSendTimeType={})).WORKING_HOURS="WORKING_HOURS",r.ALWAYS="ALWAYS";var c=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"},d={log:function(){},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(){}};d.log("Raw API_URL:","https://stage-api.robylon.ai");var u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};d.log("CONFIG",u);var p,f,h=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},v=function(){return{copilotUrl:u.copilotUrl||"https://app.robylon.ai",environment:u.environment||"production",apiUrl:u.apiUrl||"https://app.robylon.ai"}};!function(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",e.CHATBOT_READY="CHATBOT_READY"}(p||(p={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(f||(f={}));var g,m="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",b="21px",y=!1,_=function(){y=!0};console.log("isProactiveHiddenThisPage",(function(){return y}));var w,E=((g={})[exports.ProactiveSendTimeType.WORKING_HOURS]=function(e,t){var n=t.getHours(),i=t.getMinutes();return(n>10||10===n&&i>=0)&&(n<19||19===n&&0===i)},g[exports.ProactiveSendTimeType.ALWAYS]=function(e,t){return!0},g),I=function(e,t){var n;if(void 0===t&&(t=new Date),console.log("proactiveHiddenThisPage shouldShowProactiveMessage",y),!(null===(n=null==e?void 0:e.content)||void 0===n?void 0:n.trim()))return!1;if(y)return!1;var i=(null==e?void 0:e.send_time_type)||"";if(!i)return!0;var o=E[i];return!!o&&o(e,t)},x=e.memo((function(t){var n,i,o,r,s,l,u,f,h,g,y,_,w,E,x,T,C,S,A,O=t.config,R=t.toggleIframe,k=t.isIframeVisible,D=t.onEvent,L=t.onInternalEvent,N=t.position,z=t.sideSpacing,M=t.bottomSpacing,H=t.launcher_type,B=t.launcher_properties_text,j=t.shouldFadeIn,F=e.useRef(null),W=v().copilotUrl,U=e.useState(!1),P=U[0],V=U[1],G=e.useState(!1),K=G[0],J=G[1];e.useEffect((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;V(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),e.useEffect((function(){F.current&&requestAnimationFrame((function(){null==D||D({type:p.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),L(p.CHATBOT_BUTTON_LOADED)}))}),[D,L]),e.useEffect((function(){if(F.current&&j){F.current.style.opacity="0";var e=requestAnimationFrame((function(){F.current&&(F.current.style.opacity="1")}));return function(){return cancelAnimationFrame(e)}}}),[j]);var Z=N||(null===(o=O.interface_properties)||void 0===o?void 0:o.position)||"Right",Y=null!==(s=null!=z?z:null===(r=O.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,Q=null!==(u=null!=M?M:null===(l=O.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==u?u:20,X=H||(null==O?void 0:O.launcher_type)||exports.LauncherType.IMAGE,q=B||(null===(f=null==O?void 0:O.launcher_properties)||void 0===f?void 0:f.text),$={zIndex:1e3,display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",boxSizing:"border-box"};X===exports.LauncherType.IMAGE&&($.width="48px",$.height="48px",$.borderRadius="50%",$.backgroundColor=O.brand_colour);var ee=a(a({},$),((n={position:void 0,bottom:"0",borderRadius:X===exports.LauncherType.IMAGE?"50%":"9999px"})[Z.toLowerCase()]="0",n)),te=a(a({},$),((i={position:"fixed",bottom:"".concat(Q,"px"),borderRadius:X===exports.LauncherType.IMAGE?"50%":"9999px"})[Z.toLowerCase()]="".concat(Y,"px"),i)),ne=P?te:ee;e.useEffect((function(){d.log("Screen width changed, isMobile:",P,"Style:",ne)}),[P,ne]),d.log("config in floating button",O);var ie=I(null==O?void 0:O.proactive_message_obj)&&!k&&!K;return e.createElement(e.Fragment,null,ie?e.createElement("div",{className:"proactive-message-container",style:{position:"fixed",bottom:"".concat((null!==(g=null!=M?M:null===(h=O.interface_properties)||void 0===h?void 0:h.bottom_spacing)&&void 0!==g?g:20)+(X===exports.LauncherType.IMAGE?48:40)+8,"px"),right:"Right"===(N||(null===(y=O.interface_properties)||void 0===y?void 0:y.position)||"Right")?"".concat(null!==(w=null!=z?z:null===(_=O.interface_properties)||void 0===_?void 0:_.side_spacing)&&void 0!==w?w:20,"px"):"auto",left:"Left"===(N||(null===(E=O.interface_properties)||void 0===E?void 0:E.position)||"Right")?"".concat(null!==(T=null!=z?z:null===(x=O.interface_properties)||void 0===x?void 0:x.side_spacing)&&void 0!==T?T:20,"px"):"auto",maxWidth:"22.875rem",zIndex:2147483646}},e.createElement("div",{onClick:function(){R(),J(!0)},style:{background:"#fff",color:"#111",borderRadius:"12px",boxShadow:"0 0 40px 0 rgba(14, 14, 15, 0.24)",padding:"16px",cursor:"pointer",fontFamily:m,lineHeight:b,fontSize:"14px"}},null===(C=null==O?void 0:O.proactive_message_obj)||void 0===C?void 0:C.content),e.createElement("div",{onClick:function(e){e.stopPropagation(),J(!0),console.log("Clicked close")},style:{position:"absolute",top:"-32px",right:"Right"===(N||(null===(S=O.interface_properties)||void 0===S?void 0:S.position)||"Right")?"0px":"auto",left:"Left"===(N||(null===(A=O.interface_properties)||void 0===A?void 0:A.position)||"Right")?"0px":"auto",width:"24px",height:"24px",borderRadius:"50%",background:"#fff",boxShadow:" 0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",userSelect:"none"},"aria-label":"Close proactive message"},e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 14 14",fill:"none"},e.createElement("path",{d:"M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334",stroke:"#444547",strokeWidth:"0.816326",strokeLinecap:"round",strokeLinejoin:"round"})))):null,e.createElement("div",{ref:F,className:"message-bubble-container",style:a(a({},ne),{transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",transform:k?"scale(0.85)":"scale(1)",opacity:j?0:1}),onClick:R},function(){switch(X){case exports.LauncherType.TEXT:return e.createElement("div",{style:{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:O.brand_colour,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box",fontFamily:m,lineHeight:b}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:c(O.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:m,lineHeight:b,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},q)));case exports.LauncherType.TEXTUAL_IMAGE:return function(){var t,n;return e.createElement("div",{style:{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:O.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:m,lineHeight:b}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:c(O.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:m,lineHeight:b,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},q)),e.createElement("div",{style:{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:0}},e.createElement("img",{src:(null==O?void 0:O.launcher_type)?(null===(n=null===(t=null==O?void 0:O.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(W,"/chatbubble.png"):(null==O?void 0:O.image_url)||"".concat(W,"/chatbubble.png"),alt:"Chat",style:{width:"100%",height:"100%",objectFit:"cover"}})))}();case exports.LauncherType.IMAGE:default:return function(){var t,n;return k?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==O?void 0:O.launcher_type)?(null===(n=null===(t=null==O?void 0:O.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(W,"/chatbubble.png"):(null==O?void 0:O.image_url)||"".concat(W,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}})}()}}()))})),T=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]},C=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]},S=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)}},A=function(){return{platform:"web",os:T(),browser:C(),sdk_version:"1.1.40-staging.5",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:S()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(w||(w={}));var O,R=["@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)&&R.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))}))},D=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(){h()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},e.prototype.cleanup=function(){h()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},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:A(),event_type:w.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){d.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:new Error(String(n)),componentName:"ErrorTrackingService",additionalInfo:{apiKey:e,userId:t}})}},e.prototype.processPreInitQueue=function(){return s(this,void 0,void 0,(function(){var e,t,n;return l(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];d.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,a(a({},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 s(this,void 0,void 0,(function(){var t,n,i,o,r,a;return l(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=v().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=s.sent()).ok?[3,3]:(o=(i=d).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(),d.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return s(this,void 0,void 0,(function(){var i,o,r;return l(this,(function(s){switch(s.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:a(a({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:A(),event_type:w.ERROR,user_id:this.userId},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return s.sent(),[3,4];case 3:return s.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),d.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:a(a({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:A(),event_type:w.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return s.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return s(this,void 0,void 0,(function(){var i,o;return l(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:A(),event_type:w.INFO,user_id:this.userId},[4,this.sendLog(o)]):(d.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),L=D.getInstance(),N="MISSING_API_KEY",z="INVALID_API_KEY",M="CONFIG_FETCH_FAILED",H="SDK_INIT_FAILED",B="ERROR_TRACKING_INIT_FAILED",j="API_REQUEST_FAILED",F="NETWORK_ERROR",W="INVALID_RESPONSE",U="IFRAME_LOAD_FAILED",P="COOKIE_ACCESS_ERROR",V="COMPONENT_RENDER_ERROR",G="INITIALIZATION_ERROR",K="API_ERROR",J="RUNTIME_ERROR",Z="COMPONENT_ERROR",Y=((O={})[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.")},O[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.")},O[M]=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):"")},O[j]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},O[F]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},O[U]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},O[W]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},O[B]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},O[H]=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)):"")},O[P]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},O[V]=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):"")},O),Q=e.memo((function(t){var n,i,o,r,a=t.config,s=t.isVisible,l=t.onClose,c=t.onEvent,d=t.onInternalEvent,u=t.position,h=t.bottomSpacing,g=e.useRef(null),m=e.useRef(!1),b=e.useRef(!1),y=u||(null===(n=a.interface_properties)||void 0===n?void 0:n.position)||"Right",_=null!==(o=null!=h?h:null===(i=a.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==o?o:20,w=e.useCallback((function(){var e,t=g.current;if(t){var n=((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(_,"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)"})[y.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(t.style,n)}}),[_,y]);return e.useEffect((function(){var e=g.current;if(e&&!m.current){var t=v().copilotUrl;Object.assign(e.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(y.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"}),e.src="".concat(t,"/chatbot-plugin?id=").concat(a.chatbotId),m.current=!0,w();var n=function(){var n,i,o=new URL(e.src).origin||t;null===(n=e.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)};return e.addEventListener("load",n),function(){return e.removeEventListener("load",n)}}}),[a.chatbotId,null===(r=a.interface_properties)||void 0===r?void 0:r.position,w]),e.useEffect((function(){var e,t,n,i,o,r=g.current;if(r&&m.current){var l=(null===(e=a.interface_properties)||void 0===e?void 0:e.position)||"Right";if(s?(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((l.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(){!s&&r&&(r.style.display="none")}),200)),r.contentWindow&&s){var c=v().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"},c),(null==b?void 0:b.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==a?void 0:a.userId,token:null==a?void 0:a.token,userProfile:null==a?void 0:a.userProfile,isAnonymous:null==a?void 0:a.isAnonymous}},c),b.current=!0)}}}),[s,a.userId,a.token,a.userProfile]),e.useEffect((function(){if(g.current&&m.current){var e=v().copilotUrl;s&&(null==c||c({type:p.CHATBOT_OPENED,timestamp:Date.now()}),d(p.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,s,u;if(t.origin===e){if("closeChatbot"===t.data)return void l();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void d(f.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==c||c({type:p.CHATBOT_LOADED,timestamp:Date.now()}),d(p.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==c||c({type:p.CHAT_INITIALIZED,timestamp:Date.now()}),d(p.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==c||c({type:p.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),d(p.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==c||c({type:p.SESSION_REFRESHED,timestamp:Date.now()}),d(p.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(u=t.data)||void 0===u?void 0:u.type)&&d(f.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)}}}),[l,c,d,a.chatbotId,s]),e.useEffect((function(){var e=g.current;if(e&&m.current){var t=function(){L.trackError(new Error(Y[U]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:J,context:{config:a,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[a]),e.useEffect((function(){var e;if(g.current&&a&&s){var t=g.current,n=v().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:a.userProfile},n)}}),[a.userProfile,s]),e.createElement("iframe",{ref:g,id:"chat-iframe-rbyln",style:{display:"none"}})})),X=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={hasError:!1},t}return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}(n,e),n.getDerivedStateFromError=function(e){return{hasError:!0}},n.prototype.componentDidCatch=function(e,t){L.trackError(new Error(Y[V]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:V,errorType:Z,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},n.prototype.render=function(){return this.state.hasError?null:this.props.children},n}(e.Component),q=function(){var e,t=navigator.userAgent;if(null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands){var n=navigator.userAgentData.brands.find((function(e){return"Google Chrome"===e.brand}));if(null==n?void 0:n.version)return n.version}var i=t.match(/(Chrome|Firefox|Safari|Edge|Opera)\/(\d+\.\d+)/);return i?i[2]:"Unknown"},$=function(){var e,t,n=A();return{current_page_url:(null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.href)||"",browser_language:(null===navigator||void 0===navigator?void 0:navigator.language)||(null===(t=null===navigator||void 0===navigator?void 0:navigator.languages)||void 0===t?void 0:t[0])||"en",browser_version:q(),os:null==n?void 0:n.os,referral_url:(null===document||void 0===document?void 0:document.referrer)||""}},ee=function(e,t,n){return s(void 0,void 0,void 0,(function(){var i,o,r,a,s,c,u,p;return l(this,(function(l){switch(l.label){case 0:i=v().apiUrl,o="".concat(i,"/chat/chatbot/get/"),d.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{},launcher_info:$()},l.label=1;case 1:return l.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 2:return(a=l.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=l.sent(),new Error(Y[j](a.status,s));case 4:return[4,a.json()];case 5:if(c=l.sent(),!(null===(p=null==c?void 0:c.user)||void 0===p?void 0:p.org_info))throw new Error(Y[W](["user","org_info"]));return[2,c];case 6:throw u=l.sent(),L.trackError(u instanceof Error?u:new Error(Y[F]({error:String(u)})),"fetchChatbotConfig",{errorCode:u instanceof Error&&u.message.includes("API Request Failed")?j:F,errorType:K,context:{chatbotId:e,userId:t,apiUrl:i,statusCode:u instanceof Response?u.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),u;case 7:return[2]}}))}))},te=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)}))},ne=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()},ie=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=/")},oe=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},re=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 d.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="×",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:c(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;d.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),d.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){(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:oe(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;d.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(d.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;d.log("toggleIframe"),null===(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"),d.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}(),ae=function(e,t,n){if(e.chatbotId&&e.userId)try{new re(e);t(!0),d.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},se=function(t){var n=e.useMemo((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||{}}}(t)}),[t.api_key,t.user_id,t.user_token,JSON.stringify(t.user_profile)]),i=e.useState({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),o=i[0],r=i[1],c=e.useMemo((function(){return n.user_profile?Object.fromEntries(Object.entries(n.user_profile).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(n.user_profile)]),d=e.useCallback((function(e){r((function(t){return a(a({},t),e)}))}),[]),u=e.useCallback((function(){return s(void 0,void 0,void 0,(function(){var e,t,i,o,r,s,u,p,f,h,v,g,m,b,y,_,w,E,I,x,T,C,S,O,R,k,D,z,M,B,j,F,W,U,P,V;return l(this,(function(l){switch(l.label){case 0:if(!n.api_key)return L.trackError(new Error(Y[N](n.api_key)),"useChatbotState",{errorCode:N,errorType:G,context:{timestamp:Date.now()}}),[2];d({isInitializing:!0}),l.label=1;case 1:return l.trys.push([1,4,5,6]),e=n.user_id||void 0,t=!1,e||(e=ne("rblyn_anon")||te(),ie("rblyn_anon",e,365),t=!0),[4,ee(n.api_key,e,n.user_token)];case 2:return i=l.sent(),o=A(),r=$(),s=a(a(a({},o),{__INT_SYS_INFO__:a(a({},o),r)}),c),u={chatbotId:n.api_key,userId:e,token:n.user_token,isAnonymous:t,domain:"",show_launcher:null===(v=null===(h=i.user.org_info)||void 0===h?void 0:h.show_launcher)||void 0===v||v,brand_colour:(null===(m=null===(g=i.user.org_info.brand_config)||void 0===g?void 0:g.colors)||void 0===m?void 0:m.brand_color)||"",image_url:(null===(y=null===(b=i.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===y?void 0:y.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(_=i.user.org_info.brand_config)||void 0===_?void 0:_.display_name)||"",welcome_message:(null===(w=i.user.org_info.brand_config)||void 0===w?void 0:w.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)||exports.WidgetPositionEnums.RIGHT,side_spacing:null!==(S=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!==S?S:20,bottom_spacing:null!==(k=null===(R=null===(O=i.user.org_info.brand_config)||void 0===O?void 0:O.interface_properties)||void 0===R?void 0:R.bottom_spacing)&&void 0!==k?k:20},interface_type:(null===(D=i.user.org_info.brand_config)||void 0===D?void 0:D.interface_type)||exports.ChatbotInterfaceType.WIDGET,launcher_type:(null===(z=i.user.org_info.brand_config)||void 0===z?void 0:z.launcher_type)||exports.LauncherType.IMAGE,launcher_properties:{text:(null===(B=null===(M=i.user.org_info.brand_config)||void 0===M?void 0:M.launcher_properties)||void 0===B?void 0:B.text)||""},images:{launcher_image_url:{url:(null===(W=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===W?void 0:W.url)||""}},proactive_message_obj:(null===(U=i.user.org_info.brand_config)||void 0===U?void 0:U.proactive_message_obj)||void 0,launcher_delay:(null===(V=null===(P=i.user.org_info)||void 0===P?void 0:P.brand_config)||void 0===V?void 0:V.launcher_delay)||{enabled:!1,delay:0}},[4,new Promise((function(e,t){ae(u,(function(){d({isInitialized:!0,chatbotConfig:u}),e()}),(function(e){t(e)}))}))];case 3:return l.sent(),[3,6];case 4:return p=l.sent(),f=p instanceof Error?p.message:"Failed to initialize chatbot",d({error:f}),L.trackError(p instanceof Error?p:new Error(f),"useChatbotState",{errorCode:H,errorType:G,context:{timestamp:Date.now()}}),[3,6];case 5:return d({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[n.api_key,n.user_id,n.user_token]);e.useEffect((function(){n.api_key&&u()}),[u]),e.useEffect((function(){o.chatbotConfig&&r((function(e){return a(a({},e),{chatbotConfig:a(a({},e.chatbotConfig),{userProfile:a(a({},A()),c)})})}))}),[c]);var p=e.useCallback((function(){r((function(e){return a(a({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),f=e.useCallback((function(){d({isIframeVisible:!1})}),[]);return a(a({},o),{toggleIframeVisibility:p,closeIframe:f})},le=function(t){var n=t.api_key,i=t.chatbotConfig,o=t.user_profile,r=t.onEvent,c=e.useMemo((function(){return{isAnonymous:(null==i?void 0:i.isAnonymous)||!1,userId:(null==i?void 0:i.userId)||""}}),[null==i?void 0:i.isAnonymous,null==i?void 0:i.userId]),u=e.useMemo((function(){return o||{}}),[JSON.stringify(o)]),f=e.useCallback((function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];return s(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],t,!0),void 0,(function(e,t){var i,o,r,s,p,f,h;return void 0===t&&(t={}),l(this,(function(l){switch(l.label){case 0:if(!n)return[2];l.label=1;case 1:return l.trys.push([1,3,,4]),i=v().apiUrl,o=A(),r=a({trigger_time:Date.now(),channel:"CHATBOT",launch_url:(null===(h=null===window||void 0===window?void 0:window.location)||void 0===h?void 0:h.href)||"",org_id:n,client_user_id:c.isAnonymous?"Anonymous":String(c.userId),event_type:e,user_profile:u},t),s={org_id:n,event_data:r,metadata:a({timestamp:Date.now()},o),event_type:"INFO",user_id:c.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 2:if(!(p=l.sent()).ok)throw new Error("Failed to send internal event: ".concat(p.statusText));return[3,4];case 3:return f=l.sent(),d.error("Failed to send internal event:",f),[3,4];case 4:return[2]}}))}))}),[n,c]);return{emitEvent:e.useCallback((function(e,t){var n=Date.now();e!==p.CHATBOT_BUTTON_CLICKED&&e!==p.CHATBOT_CLOSED&&e!==p.CHATBOT_OPENED&&e!==p.CHATBOT_READY||(r&&r({type:e,timestamp:n,data:t}),f(e,{timestamp:n}))}),[r,f]),onInternalEvent:f}},ce=function(t){var n,i,o,r,s,l,c,u=t.children,p=t.config,f=t.position,h=t.sideSpacing,v=t.bottomSpacing,g=e.useState(!1),m=g[0],b=g[1];e.useEffect((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;b(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]);var y=f||(null===(o=p.interface_properties)||void 0===o?void 0:o.position)||"Right",_=null!==(s=null!=h?h:null===(r=p.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,w=null!==(c=null!=v?v:null===(l=p.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==c?c:20;d.log("config",p,y,_);var E={position:"fixed",zIndex:1e3,display:"flex",flexDirection:"column"},I=a(a({},E),((n={bottom:"".concat(w,"px")})[y.toLowerCase()]="".concat(null!=_?_:20,"px"),n.alignItems="Right"===y?"flex-end":"flex-start",n.top=void 0,n["Right"===y?"left":"right"]=void 0,n)),x=a(a({},E),((i={top:0})[y.toLowerCase()]="".concat(null!=_?_:20,"px"),i.alignItems="center",i.bottom=void 0,i["Right"===y?"left":"right"]=void 0,i)),T=m?x:I;return e.useEffect((function(){console.log("Container screen width changed, isMobile:",m,"Style:",T)}),[m,T]),e.createElement("div",{className:"robylon-chatbot-container",style:T},u)},de=e.forwardRef((function(t,n){var i,o,r,s=t.api_key,l=t.user_id,c=t.user_token,u=t.user_profile,f=t.onEvent,h=t.position,v=t.sideSpacing,g=t.bottomSpacing;t.show_launcher;var m=t.launcher_type,b=t.launcher_properties_text,y="string"==typeof v?""===v||isNaN(Number(v))?void 0:Number(v):v,_="string"==typeof g?""===g||isNaN(Number(g))?void 0:Number(g):g,w="string"==typeof h?"left"===h.toLowerCase()?"Left":"right"===h.toLowerCase()?"Right":void 0:h;e.useEffect((function(){}));var E=e.useMemo((function(){return{api_key:s,user_id:l,user_token:c,user_profile:u}}),[s,l,c,u]),I=e.useCallback((function(e){null==f||f(e)}),[f]),T=se(E),C=T.isInitialized,S=T.error,A=T.chatbotConfig,O=T.isIframeVisible,R=T.toggleIframeVisibility,k=T.closeIframe,D=e.useMemo((function(){return{api_key:s,user_profile:E.user_profile,onEvent:I,chatbotConfig:A?{isAnonymous:A.isAnonymous,userId:A.userId}:null}}),[s,E.user_profile,I,null==A?void 0:A.isAnonymous,null==A?void 0:A.userId]),z=le(a({},D)),M=z.emitEvent,H=z.onInternalEvent;e.useImperativeHandle(n,(function(){return{show:function(){C&&A?O||(R(),M(p.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot show - chatbot not ready yet")},hide:function(){C&&A?O&&(k(),M(p.CHATBOT_CLOSED)):console.warn("Robylon Chatbot: Cannot hide - chatbot not ready yet")},toggle:function(){C&&A?(R(),M(O?p.CHATBOT_CLOSED:p.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot toggle - chatbot not ready yet")},isReady:C&&!!A}}),[C,A,O,R,k,M]),e.useEffect((function(){C&&A&&M(p.CHATBOT_READY)}),[C,A,M]);var j=e.useState(!1),F=j[0],W=j[1];e.useEffect((function(){var e,t,n,i,o,r;if(!(!0===(null==A?void 0:A.show_launcher)))return W(!1),function(){r&&clearTimeout(r)};var a=!0===(null===(e=null==A?void 0:A.launcher_delay)||void 0===e?void 0:e.enabled),s=null!==(o=null!==(n=null===(t=null==A?void 0:A.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==A?void 0:A.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0;return a&&Number(s)>0?(W(!1),r=window.setTimeout((function(){W(!0)}),1e3*Number(s))):W(!0),function(){r&&clearTimeout(r)}}),[null==A?void 0:A.show_launcher,null===(i=null==A?void 0:A.launcher_delay)||void 0===i?void 0:i.enabled,null===(o=null==A?void 0:A.launcher_delay)||void 0===o?void 0:o.seconds,null===(r=null==A?void 0:A.launcher_delay)||void 0===r?void 0:r.delay]),e.useEffect((function(){if(s)try{L.initialize(s,l)}catch(e){L.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:B,errorType:G,context:{timestamp:Date.now()}})}else L.trackError(new Error(Y[N](s)),"RobylonChatbot",{errorCode:N,errorType:G,context:{timestamp:Date.now()}})}),[s,l]);var U=e.useCallback((function(){k(),M(p.CHATBOT_CLOSED)}),[k,M]),P=e.useCallback((function(){R(),M(O?p.CHATBOT_CLOSED:p.CHATBOT_BUTTON_CLICKED)}),[R,M,O]),V=e.useMemo((function(){var e,t,n,i,o;return{config:A,toggleIframe:P,isIframeVisible:O,onEvent:I,onInternalEvent:H,position:w,sideSpacing:y,bottomSpacing:_,launcher_type:m,launcher_properties_text:b,shouldFadeIn:!0===(null===(e=null==A?void 0:A.launcher_delay)||void 0===e?void 0:e.enabled)&&(null!==(o=null!==(n=null===(t=null==A?void 0:A.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==A?void 0:A.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0)>0||!1}}),[A,P,O,I,H,w,y,_,m,b]);d.log("floatingButtonProps",V);var K=e.useMemo((function(){return{config:A,isVisible:O,onClose:U,onEvent:I,onInternalEvent:H,position:w,bottomSpacing:_}}),[A,O,U,I,H,w,_]);return s&&!S&&A?e.createElement(X,{componentName:"RobylonChatbot"},C?e.createElement(ce,{config:A,position:w,sideSpacing:y,bottomSpacing:_},e.createElement(X,{componentName:"ChatbotIframe"},e.createElement(Q,a({},K))),e.createElement(X,{componentName:"ChatbotFloatingButton"},F?e.createElement(x,a({},V)):null)):null):null})),ue=e.memo(de,(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)&&e.position===t.position&&e.sideSpacing===t.sideSpacing&&e.bottomSpacing===t.bottomSpacing&&e.show_launcher===t.show_launcher&&e.launcher_type===t.launcher_type&&e.launcher_properties_text===t.launcher_properties_text&&!0})),pe=function(){function e(e){var t=this;this.resizeObserver=null,this.proactiveElement=null,this.config=e,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount();try{this.buttonElement.style.opacity="0",this.buttonElement.style.transition="transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",requestAnimationFrame((function(){t.buttonElement.style.opacity="1"}))}catch(e){}this.setupResizeListener(),this.renderProactiveIfNeeded()}return e.prototype.render=function(){var e=this;v().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:m};n.launcher_type===exports.LauncherType.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()},this.renderProactiveIfNeeded()},e.prototype.createLauncherElement=function(){var e,t,n=this.config,i=n.config,o=n.isIframeVisible,r=v().copilotUrl;switch(console.log("config in floating button",i),i.launcher_type){case exports.LauncherType.TEXT:return this.createTextLauncher();case exports.LauncherType.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case exports.LauncherType.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:c(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:b,fontFamily:m,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=v().copilotUrl,s=this.config.config,l=s.brand_colour,d=s.launcher_properties,u=s.image_url,p=document.createElement("div");Object.assign(p.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 f=document.createElement("div");Object.assign(f.style,{flex:"1",minWidth:"0"});var h=document.createElement("p");Object.assign(h.style,{margin:"0",color:c(l),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:b,fontFamily:m,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),h.textContent=(null==d?void 0:d.text)||"";var g=document.createElement("div");Object.assign(g.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var y=document.createElement("img");return y.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"):u||"".concat(a,"/chatbubble.png"),y.alt="Chat",Object.assign(y.style,{width:"100%",height:"100%",objectFit:"cover"}),f.appendChild(h),g.appendChild(y),p.appendChild(f),p.appendChild(g),p},e.prototype.applyResponsiveStyles=function(e){var t,n,i,o,r,s,l,c,d,u=(null===window||void 0===window?void 0:window.innerWidth)<560,p=this.config.config,f=this.config.position||(null===(i=p.interface_properties)||void 0===i?void 0:i.position)||"Right",h=null!==(s=null!==(o=this.config.sideSpacing)&&void 0!==o?o:null===(r=p.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,v=null!==(d=null!==(l=this.config.bottomSpacing)&&void 0!==l?l:null===(c=p.interface_properties)||void 0===c?void 0:c.bottom_spacing)&&void 0!==d?d:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var g=a(a({},e),u?((t={position:"fixed",bottom:"".concat(v,"px")})[f.toLowerCase()]="".concat(h,"px"),t):((n={bottom:"".concat(v,"px")})[f.toLowerCase()]="".concat(h,"px"),n));Object.assign(this.buttonElement.style,g)},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!==exports.LauncherType.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===exports.LauncherType.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:p.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(p.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config.isIframeVisible,this.config=a(a({},this.config),e),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render(),this.renderProactiveIfNeeded()},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),this.proactiveElement&&this.proactiveElement.parentElement&&(this.proactiveElement.parentElement.removeChild(this.proactiveElement),this.proactiveElement=null)},e.prototype.renderProactiveIfNeeded=function(){var e,t,n,i,o,r,a,s,l,c=this,d=null===(t=null===(e=this.config)||void 0===e?void 0:e.config)||void 0===t?void 0:t.proactive_message_obj;if(!(I(d)&&!this.config.isIframeVisible))return this.proactiveElement&&this.proactiveElement.parentElement&&this.proactiveElement.parentElement.removeChild(this.proactiveElement),void(this.proactiveElement=null);if(!this.proactiveElement){var u=document.createElement("div");u.style.position="fixed";var p=null!==(o=null!==(n=this.config.bottomSpacing)&&void 0!==n?n:null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==o?o:20,f=null!==(s=null!==(r=this.config.sideSpacing)&&void 0!==r?r:null===(a=this.config.config.interface_properties)||void 0===a?void 0:a.side_spacing)&&void 0!==s?s:20,h=this.config.position||(null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.position)||"Right";u.style.bottom="".concat(p+(this.config.config.launcher_type===exports.LauncherType.IMAGE?48:40)+8,"px"),"Right"===h?u.style.right="".concat(f,"px"):u.style.left="".concat(f,"px"),u.style.maxWidth="22.875rem",u.style.zIndex="2147483646";var v=document.createElement("div");v.style.background="#fff",v.style.color="#111",v.style.borderRadius="16px",v.style.boxShadow="0 0 40px 0 rgba(14, 14, 15, 0.24)",v.style.padding="16px",v.style.cursor="pointer",v.style.fontFamily=m,v.style.fontSize="14px",v.style.lineHeight=String(b),v.textContent=(null==d?void 0:d.content)||"",v.onclick=function(){c.config.toggleIframe(),_()};var g=document.createElement("div");g.style.position="absolute",g.style.top="-32px",g.style.width="24px",g.style.height="24px",g.style.borderRadius="50%",g.style.background="#fff",g.style.boxShadow="0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",g.style.display="flex",g.style.alignItems="center",g.style.justifyContent="center",g.style.cursor="pointer","Right"===h?(g.style.right="0px",g.style.left="auto"):(g.style.left="0px",g.style.right="auto"),g.onclick=function(e){e.stopPropagation(),_(),c.proactiveElement&&c.proactiveElement.parentElement&&c.proactiveElement.parentElement.removeChild(c.proactiveElement),c.proactiveElement=null},g.innerHTML='\n <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none">\n <path d="M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334" stroke="#444547" stroke-width="0.816326" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n ',u.appendChild(v),u.appendChild(g),document.body.appendChild(u),this.proactiveElement=u}},e}(),fe=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,h,g,m,b,y,_=v().copilotUrl;if(e.origin===_){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(f.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:p.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(p.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:p.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(p.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:p.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(p.CHAT_INITIALIZATION_FAILED,{error:null===(h=e.data)||void 0===h?void 0:h.error})),"SESSION_REFRESHED"===(null===(g=e.data)||void 0===g?void 0:g.type)&&(null===(b=(m=t.config).onEvent)||void 0===b||b.call(m,{type:p.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(p.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(y=e.data)||void 0===y?void 0:y.type)&&t.config.onInternalEvent(f.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=this.config.position||(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,r;if(this.iframeElement){var a=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",s=null!==(r=null!==(i=this.config.bottomSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.bottom_spacing)&&void 0!==r?r:20;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(s,"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=v().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,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(){L.trackError(new Error(Y[U]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:J,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=this.config.position||(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 f=v().copilotUrl,h=new URL(this.iframeElement.src).origin||f;this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},h),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}},h),this.hasRegistered=!0),null===(c=(l=this.config).onEvent)||void 0===c||c.call(l,{type:p.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(p.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=a(a({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=v().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},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}(),he=function(){function e(e,t,n,i){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config={config:e,position:t,sideSpacing:n,bottomSpacing:i},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,s,l,c,d=(null===window||void 0===window?void 0:window.innerWidth)<560,u=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",p=null!==(r=null!==(i=this.config.sideSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.side_spacing)&&void 0!==r?r:20,f=null!==(c=null!==(s=this.config.bottomSpacing)&&void 0!==s?s:null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==c?c:20;this.containerElement.style.position="",this.containerElement.style.top="",this.containerElement.style.bottom="",this.containerElement.style.right="",this.containerElement.style.left="",this.containerElement.style.alignItems="";var h={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},v=a(a({},h),((e={bottom:"".concat(f,"px")})[u.toLowerCase()]="".concat(p,"px"),e.alignItems="Right"===u?"flex-end":"flex-start",e)),g=a(a({},h),((t={top:"0"})[u.toLowerCase()]="".concat(p,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,d?g:v)},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}(),ve=function(e,t,n){return s(void 0,void 0,void 0,(function(){var i,o,r,a,s,c,u,p;return l(this,(function(l){switch(l.label){case 0:return l.trys.push([0,5,,6]),i=v().apiUrl,o="".concat(i,"/chat/chatbot/get/"),d.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{},launcher_info:$()},[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(a=l.sent()).ok?[3,3]:[4,a.text()];case 2:throw s=l.sent(),new Error(Y[j](a.status,s));case 3:return[4,a.json()];case 4:if(c=l.sent(),!(null===(p=null==c?void 0:c.user)||void 0===p?void 0:p.org_info))throw new Error(Y[W](["user","org_info"]));return[2,c];case 5:throw u=l.sent(),L.trackError(u instanceof Error?u:new Error(Y[F]({error:String(u)})),"fetchChatbotConfig",{errorCode:u instanceof Error&&u.message.includes("API Request Failed")?j:F,errorType:K,context:{apiKey:e,userId:t,timestamp:Date.now()}}),u;case 6:return[2]}}))}))},ge=function(e){return s(void 0,void 0,void 0,(function(){var t,n,i,o,r,s,c,d,u,p,f,h,v,g,m,b,y,_,w,E,I,x,T,C,S,O,R,k,D,L,N,z,M,H;return l(this,(function(l){switch(l.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=ne("rblyn_anon")||te(),ie("rblyn_anon",n,365),i=!0),[4,ve(t.api_key,n,t.user_token)];case 1:return o=l.sent(),r=A(),s=$(),B=t.user_profile,c=B?Object.fromEntries(Object.entries(B).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},d=a(a(a({},r),{__INT_SYS_INFO__:a(a({},r),s)}),c),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",show_launcher:null===(p=null===(u=o.user.org_info)||void 0===u?void 0:u.show_launcher)||void 0===p||p,brand_colour:(null===(h=null===(f=o.user.org_info.brand_config)||void 0===f?void 0:f.colors)||void 0===h?void 0:h.brand_color)||"",image_url:(null===(g=null===(v=o.user.org_info)||void 0===v?void 0:v.brand_config)||void 0===g?void 0:g.launcher_logo_url)||"",userProfile:d,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(m=o.user.org_info.brand_config)||void 0===m?void 0:m.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===(y=o.user.org_info.brand_config)||void 0===y?void 0:y.redirect_url)||""},launcher_type:(null===(_=o.user.org_info.brand_config)||void 0===_?void 0:_.launcher_type)||exports.LauncherType.IMAGE,launcher_properties:{text:(null===(E=null===(w=o.user.org_info.brand_config)||void 0===w?void 0:w.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)||""}},proactive_message_obj:(null===(O=null===(S=null===(C=null==o?void 0:o.user)||void 0===C?void 0:C.org_info)||void 0===S?void 0:S.brand_config)||void 0===O?void 0:O.proactive_message_obj)||void 0,interface_properties:{position:(null===(k=null===(R=o.user.org_info.brand_config)||void 0===R?void 0:R.interface_properties)||void 0===k?void 0:k.position)||exports.WidgetPositionEnums.RIGHT,side_spacing:(null===(L=null===(D=o.user.org_info.brand_config)||void 0===D?void 0:D.interface_properties)||void 0===L?void 0:L.side_spacing)||20,bottom_spacing:(null===(z=null===(N=o.user.org_info.brand_config)||void 0===N?void 0:N.interface_properties)||void 0===z?void 0:z.bottom_spacing)||20},interface_type:(null===(M=o.user.org_info.brand_config)||void 0===M?void 0:M.interface_type)||exports.ChatbotInterfaceType.WIDGET,launcher_delay:(null===(H=o.user.org_info.brand_config)||void 0===H?void 0:H.launcher_delay)||{enabled:!1,delay:0}}]}var B}))}))},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){}}},be=function(){function e(e){var t=this;this.container=null,this.floatingButton=null,this.launcherDelayTimeout=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){var n,i,o,r,a;if(!t.isDestroyed){var s=e.isInitialized,l=e.error,c=e.chatbotConfig,d=e.isIframeVisible;if(!l&&c&&s){if(t.eventEmitter=me({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:c.isAnonymous,userId:c.userId}}),t.container||(t.container=new he(c,t.config.position,t.config.sideSpacing,t.config.bottomSpacing)),t.iframe)t.iframe.update({config:c,isVisible:d,position:t.config.position,bottomSpacing:t.config.bottomSpacing});else if(t.iframe=new fe({config:c,isVisible:d,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,bottomSpacing:t.config.bottomSpacing}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var u=t.iframe.getElement();u&&t.container&&t.container.getElement().prepend(u)}var p=!0===(null==c?void 0:c.show_launcher),f=!0===(null===(n=null==c?void 0:c.launcher_delay)||void 0===n?void 0:n.enabled),h=null!==(a=null!==(o=null===(i=null==c?void 0:c.launcher_delay)||void 0===i?void 0:i.seconds)&&void 0!==o?o:null===(r=null==c?void 0:c.launcher_delay)||void 0===r?void 0:r.delay)&&void 0!==a?a:0,v=function(){if(t.floatingButton)t.floatingButton.update({config:c,isIframeVisible:d,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing});else if(t.floatingButton=new pe({config:c,toggleIframe:t.toggleIframe,isIframeVisible:d,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var e=t.floatingButton.getElement();e&&t.container&&t.container.getElement().appendChild(e)}};t.launcherDelayTimeout&&(clearTimeout(t.launcherDelayTimeout),t.launcherDelayTimeout=null),p?f&&Number(h)>0&&!t.floatingButton?t.launcherDelayTimeout=window.setTimeout((function(){v(),t.launcherDelayTimeout=null}),1e3*Number(h)):v():t.floatingButton&&(t.floatingButton.destroy(),t.floatingButton=null)}}},this.toggleIframe=function(){var e=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(e.isIframeVisible?p.CHATBOT_CLOSED:p.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(p.CHATBOT_CLOSED)};var n,i,o,r,c=a(a({},e),{position:"string"==typeof e.position?"left"===e.position.toLowerCase()?"Left":"right"===e.position.toLowerCase()?"Right":void 0:void 0,sideSpacing:"string"==typeof e.sideSpacing?""===e.sideSpacing||isNaN(Number(e.sideSpacing))?void 0:Number(e.sideSpacing):e.sideSpacing,bottomSpacing:"string"==typeof e.bottomSpacing?""===e.bottomSpacing||isNaN(Number(e.bottomSpacing))?void 0:Number(e.bottomSpacing):e.bottomSpacing});if(this.config=c,!e.api_key)throw L.trackError(new Error(Y[N](e.api_key)),"RobylonChatbot",{errorCode:N,errorType:G,context:{timestamp:Date.now()}}),new Error("API key is required");try{L.initialize(e.api_key,e.user_id)}catch(e){L.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:B,errorType:G,context:{timestamp:Date.now()}})}this.stateManager=(n={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},i={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},o=[],{getState:function(){return i},initialize:function(){return s(void 0,void 0,void 0,(function(){var e,t,i;return l(this,(function(o){switch(o.label){case 0:if(!n.api_key)return L.trackError(new Error(Y[N](n.api_key)),"ChatbotStateManager",{errorCode:N,errorType:G,context:{timestamp:Date.now()}}),[2];r({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,ge(n)];case 2:return e=o.sent(),[4,new Promise((function(t,n){ae(e,(function(){r({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return o.sent(),[3,6];case 4:return t=o.sent(),i=t instanceof Error?t.message:"Failed to initialize chatbot",r({error:i}),L.trackError(t instanceof Error?t:new Error(i),"ChatbotStateManager",{errorCode:H,errorType:G,context:{timestamp:Date.now()}}),[3,6];case 5:return r({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){r({isIframeVisible:!i.isIframeVisible})},closeIframe:function(){r({isIframeVisible:!1})},updateState:r=function(e){i=a(a({},i),e),o.forEach((function(e){return e(i)}))},subscribe:function(e){return o.push(e),function(){var t=o.indexOf(e);t>-1&&o.splice(t,1)}},unsubscribe:function(e){var t=o.indexOf(e);t>-1&&o.splice(t,1)}}),this.eventEmitter=me({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),window.RobylonShouldShowProactive=I,window.RobylonHideProactive=_,this.initialize()}return e.prototype.initialize=function(){return s(this,void 0,void 0,(function(){var e;return l(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(),L.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:H,errorType:G,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(p.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(p.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.launcherDelayTimeout&&(clearTimeout(this.launcherDelayTimeout),this.launcherDelayTimeout=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 ye(e){return new be(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=ye(i)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(e){var n=Array.prototype.slice.call(arguments,1);return"init"===e?t=ye(n[0]||{}):t&&"function"==typeof t[e]?t[e].apply(t,n):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var _e={create:ye,getState:function(){return"initialized"}};exports.Chatbot=ue,exports.RobylonChatbot=_e,exports.useChatbot=function(t){var n=e.useState({isLoading:!0,isInitialized:!1,error:null}),i=n[0],o=n[1],r=function(e){o((function(t){return a(a({},t),{isInitialized:e})}))},s=function(e){o((function(t){return a(a({},t),{error:e})}))};return e.useEffect((function(){!function(){try{ae(t,r,s)}catch(e){o((function(t){return a(a({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[t.chatbotId,t.userId]),i};
|
|
1
|
+
"use strict";var e=require("react"),t=function(e,n){return t=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])},t(e,n)};var n,i,o,r,a=function(){return a=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},a.apply(this,arguments)};function s(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 l(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,exports.ChatbotInterfaceType=void 0,(n=exports.ChatbotInterfaceType||(exports.ChatbotInterfaceType={})).WIDGET="WIDGET",n.POPOVER="POPOVER",n.EMBED="EMBED",exports.WidgetPositionEnums=void 0,(i=exports.WidgetPositionEnums||(exports.WidgetPositionEnums={})).RIGHT="Right",i.LEFT="Left",exports.LauncherType=void 0,(o=exports.LauncherType||(exports.LauncherType={})).TEXT="TEXT",o.IMAGE="IMAGE",o.TEXTUAL_IMAGE="TEXTUAL_IMAGE",exports.ProactiveSendTimeType=void 0,(r=exports.ProactiveSendTimeType||(exports.ProactiveSendTimeType={})).WORKING_HOURS="WORKING_HOURS",r.ALWAYS="ALWAYS";var c=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"},d={log:function(){},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(){}};d.log("Raw API_URL:","https://stage-api.robylon.ai");var u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};d.log("CONFIG",u);var p,f,h=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},v=function(){return{copilotUrl:u.copilotUrl||"https://app.robylon.ai",environment:u.environment||"production",apiUrl:u.apiUrl||"https://app.robylon.ai"}};!function(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",e.CHATBOT_READY="CHATBOT_READY"}(p||(p={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(f||(f={}));var g,m="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",b="21px",y=!1,_=function(){y=!0};console.log("isProactiveHiddenThisPage",(function(){return y}));var w,E=((g={})[exports.ProactiveSendTimeType.WORKING_HOURS]=function(e,t){var n=t.getHours(),i=t.getMinutes();return(n>10||10===n&&i>=0)&&(n<19||19===n&&0===i)},g[exports.ProactiveSendTimeType.ALWAYS]=function(e,t){return!0},g),I=function(e,t){var n;if(void 0===t&&(t=new Date),console.log("proactiveHiddenThisPage shouldShowProactiveMessage",y),!(null===(n=null==e?void 0:e.content)||void 0===n?void 0:n.trim()))return!1;if(y)return!1;var i=(null==e?void 0:e.send_time_type)||"";if(!i)return!0;var o=E[i];return!!o&&o(e,t)},x=e.memo((function(t){var n,i,o,r,s,l,u,f,h,g,y,_,w,E,x,T,C,S,A,O=t.config,R=t.toggleIframe,k=t.isIframeVisible,D=t.onEvent,L=t.onInternalEvent,N=t.position,z=t.sideSpacing,M=t.bottomSpacing,H=t.launcher_type,B=t.launcher_properties_text,j=t.shouldFadeIn,F=e.useRef(null),W=v().copilotUrl,U=e.useState(!1),P=U[0],V=U[1],G=e.useState(!1),K=G[0],J=G[1];e.useEffect((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;V(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),e.useEffect((function(){F.current&&requestAnimationFrame((function(){null==D||D({type:p.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),L(p.CHATBOT_BUTTON_LOADED)}))}),[D,L]),e.useEffect((function(){if(F.current&&j){F.current.style.opacity="0";var e=requestAnimationFrame((function(){F.current&&(F.current.style.opacity="1")}));return function(){return cancelAnimationFrame(e)}}}),[j]);var Z=N||(null===(o=O.interface_properties)||void 0===o?void 0:o.position)||"Right",Y=null!==(s=null!=z?z:null===(r=O.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,Q=null!==(u=null!=M?M:null===(l=O.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==u?u:20,X=H||(null==O?void 0:O.launcher_type)||exports.LauncherType.IMAGE,q=B||(null===(f=null==O?void 0:O.launcher_properties)||void 0===f?void 0:f.text),$={zIndex:1e3,display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",boxSizing:"border-box"};X===exports.LauncherType.IMAGE&&($.width="48px",$.height="48px",$.borderRadius="50%",$.backgroundColor=O.brand_colour);var ee=a(a({},$),((n={position:void 0,bottom:"0",borderRadius:X===exports.LauncherType.IMAGE?"50%":"9999px"})[Z.toLowerCase()]="0",n)),te=a(a({},$),((i={position:"fixed",bottom:"".concat(Q,"px"),borderRadius:X===exports.LauncherType.IMAGE?"50%":"9999px"})[Z.toLowerCase()]="".concat(Y,"px"),i)),ne=P?te:ee;e.useEffect((function(){d.log("Screen width changed, isMobile:",P,"Style:",ne)}),[P,ne]),d.log("config in floating button",O);var ie=I(null==O?void 0:O.proactive_message_obj)&&!k&&!K;return e.createElement(e.Fragment,null,ie?e.createElement("div",{className:"proactive-message-container",style:{position:"fixed",bottom:"".concat((null!==(g=null!=M?M:null===(h=O.interface_properties)||void 0===h?void 0:h.bottom_spacing)&&void 0!==g?g:20)+(X===exports.LauncherType.IMAGE?48:40)+8,"px"),right:"Right"===(N||(null===(y=O.interface_properties)||void 0===y?void 0:y.position)||"Right")?"".concat(null!==(w=null!=z?z:null===(_=O.interface_properties)||void 0===_?void 0:_.side_spacing)&&void 0!==w?w:20,"px"):"auto",left:"Left"===(N||(null===(E=O.interface_properties)||void 0===E?void 0:E.position)||"Right")?"".concat(null!==(T=null!=z?z:null===(x=O.interface_properties)||void 0===x?void 0:x.side_spacing)&&void 0!==T?T:20,"px"):"auto",maxWidth:"22.875rem",zIndex:2147483646}},e.createElement("div",{onClick:function(){R(),J(!0)},style:{background:"#fff",color:"#111",borderRadius:"12px",boxShadow:"0 0 40px 0 rgba(14, 14, 15, 0.24)",padding:"16px",cursor:"pointer",fontFamily:m,lineHeight:b,fontSize:"14px"}},null===(C=null==O?void 0:O.proactive_message_obj)||void 0===C?void 0:C.content),e.createElement("div",{onClick:function(e){e.stopPropagation(),J(!0),console.log("Clicked close")},style:{position:"absolute",top:"-32px",right:"Right"===(N||(null===(S=O.interface_properties)||void 0===S?void 0:S.position)||"Right")?"0px":"auto",left:"Left"===(N||(null===(A=O.interface_properties)||void 0===A?void 0:A.position)||"Right")?"0px":"auto",width:"24px",height:"24px",borderRadius:"50%",background:"#fff",boxShadow:" 0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",userSelect:"none"},"aria-label":"Close proactive message"},e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 14 14",fill:"none"},e.createElement("path",{d:"M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334",stroke:"#444547",strokeWidth:"0.816326",strokeLinecap:"round",strokeLinejoin:"round"})))):null,e.createElement("div",{ref:F,className:"message-bubble-container",style:a(a({},ne),{transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",transform:k?"scale(0.85)":"scale(1)",opacity:j?0:1}),onClick:R},function(){switch(X){case exports.LauncherType.TEXT:return e.createElement("div",{style:{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:O.brand_colour,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box",fontFamily:m,lineHeight:b}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:c(O.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:m,lineHeight:b,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},q)));case exports.LauncherType.TEXTUAL_IMAGE:return function(){var t,n;return e.createElement("div",{style:{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:O.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:m,lineHeight:b}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:c(O.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:m,lineHeight:b,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},q)),e.createElement("div",{style:{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:0}},e.createElement("img",{src:(null==O?void 0:O.launcher_type)?(null===(n=null===(t=null==O?void 0:O.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(W,"/chatbubble.png"):(null==O?void 0:O.image_url)||"".concat(W,"/chatbubble.png"),alt:"Chat",style:{width:"100%",height:"100%",objectFit:"cover"}})))}();case exports.LauncherType.IMAGE:default:return function(){var t,n;return k?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==O?void 0:O.launcher_type)?(null===(n=null===(t=null==O?void 0:O.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(W,"/chatbubble.png"):(null==O?void 0:O.image_url)||"".concat(W,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}})}()}}()))})),T=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]},C=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]},S=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)}},A=function(){return{platform:"web",os:T(),browser:C(),sdk_version:"1.1.40-staging.6",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:S()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(w||(w={}));var O,R=["@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)&&R.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))}))},D=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(){h()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},e.prototype.cleanup=function(){h()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},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:A(),event_type:w.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){d.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:new Error(String(n)),componentName:"ErrorTrackingService",additionalInfo:{apiKey:e,userId:t}})}},e.prototype.processPreInitQueue=function(){return s(this,void 0,void 0,(function(){var e,t,n;return l(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];d.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,a(a({},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 s(this,void 0,void 0,(function(){var t,n,i,o,r,a;return l(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=v().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=s.sent()).ok?[3,3]:(o=(i=d).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(),d.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return s(this,void 0,void 0,(function(){var i,o,r;return l(this,(function(s){switch(s.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:a(a({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:A(),event_type:w.ERROR,user_id:this.userId},s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return s.sent(),[3,4];case 3:return s.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),d.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:a(a({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:A(),event_type:w.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return s.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return s(this,void 0,void 0,(function(){var i,o;return l(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:A(),event_type:w.INFO,user_id:this.userId},[4,this.sendLog(o)]):(d.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),L=D.getInstance(),N="MISSING_API_KEY",z="INVALID_API_KEY",M="CONFIG_FETCH_FAILED",H="SDK_INIT_FAILED",B="ERROR_TRACKING_INIT_FAILED",j="API_REQUEST_FAILED",F="NETWORK_ERROR",W="INVALID_RESPONSE",U="IFRAME_LOAD_FAILED",P="COOKIE_ACCESS_ERROR",V="COMPONENT_RENDER_ERROR",G="INITIALIZATION_ERROR",K="API_ERROR",J="RUNTIME_ERROR",Z="COMPONENT_ERROR",Y=((O={})[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.")},O[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.")},O[M]=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):"")},O[j]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},O[F]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},O[U]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},O[W]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},O[B]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},O[H]=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)):"")},O[P]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},O[V]=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):"")},O),Q=e.memo((function(t){var n,i,o,r,a=t.config,s=t.isVisible,l=t.onClose,c=t.onEvent,d=t.onInternalEvent,u=t.position,h=t.bottomSpacing,g=e.useRef(null),m=e.useRef(!1),b=e.useRef(!1),y=u||(null===(n=a.interface_properties)||void 0===n?void 0:n.position)||"Right",_=null!==(o=null!=h?h:null===(i=a.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==o?o:20,w=e.useCallback((function(){var e,t=g.current;if(t){var n=((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(_,"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)"})[y.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(t.style,n)}}),[_,y]);return e.useEffect((function(){var e=g.current;if(e&&!m.current){var t=v().copilotUrl;Object.assign(e.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(y.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"}),e.src="".concat(t,"/chatbot-plugin?id=").concat(a.chatbotId),m.current=!0,w();var n=function(){var n,i,o=new URL(e.src).origin||t;null===(n=e.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)};return e.addEventListener("load",n),function(){return e.removeEventListener("load",n)}}}),[a.chatbotId,null===(r=a.interface_properties)||void 0===r?void 0:r.position,w]),e.useEffect((function(){var e,t,n,i,o,r=g.current;if(r&&m.current){var l=(null===(e=a.interface_properties)||void 0===e?void 0:e.position)||"Right";if(s?(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((l.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(){!s&&r&&(r.style.display="none")}),200)),r.contentWindow&&s){var c=v().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"},c),(null==b?void 0:b.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==a?void 0:a.userId,token:null==a?void 0:a.token,userProfile:null==a?void 0:a.userProfile,isAnonymous:null==a?void 0:a.isAnonymous}},c),b.current=!0)}}}),[s,a.userId,a.token,a.userProfile]),e.useEffect((function(){if(g.current&&m.current){var e=v().copilotUrl;s&&(null==c||c({type:p.CHATBOT_OPENED,timestamp:Date.now()}),d(p.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,s,u;if(t.origin===e){if("closeChatbot"===t.data)return void l();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void d(f.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==c||c({type:p.CHATBOT_LOADED,timestamp:Date.now()}),d(p.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==c||c({type:p.CHAT_INITIALIZED,timestamp:Date.now()}),d(p.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==c||c({type:p.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),d(p.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==c||c({type:p.SESSION_REFRESHED,timestamp:Date.now()}),d(p.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(u=t.data)||void 0===u?void 0:u.type)&&d(f.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)}}}),[l,c,d,a.chatbotId,s]),e.useEffect((function(){var e=g.current;if(e&&m.current){var t=function(){L.trackError(new Error(Y[U]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:J,context:{config:a,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[a]),e.useEffect((function(){var e;if(g.current&&a&&s){var t=g.current,n=v().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:a.userProfile},n)}}),[a.userProfile,s]),e.createElement("iframe",{ref:g,id:"chat-iframe-rbyln",style:{display:"none"}})})),X=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={hasError:!1},t}return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}(n,e),n.getDerivedStateFromError=function(e){return{hasError:!0}},n.prototype.componentDidCatch=function(e,t){L.trackError(new Error(Y[V]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:V,errorType:Z,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},n.prototype.render=function(){return this.state.hasError?null:this.props.children},n}(e.Component),q=function(){var e,t=navigator.userAgent;if(null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands){var n=navigator.userAgentData.brands.find((function(e){return"Google Chrome"===e.brand}));if(null==n?void 0:n.version)return n.version}var i=t.match(/(Chrome|Firefox|Safari|Edge|Opera)\/(\d+\.\d+)/);return i?i[2]:"Unknown"},$=function(){var e,t,n=A();return{current_page_url:(null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.href)||"",browser_language:(null===navigator||void 0===navigator?void 0:navigator.language)||(null===(t=null===navigator||void 0===navigator?void 0:navigator.languages)||void 0===t?void 0:t[0])||"en",browser_version:q(),os:null==n?void 0:n.os,referral_url:(null===document||void 0===document?void 0:document.referrer)||""}},ee=function(e,t,n){return s(void 0,void 0,void 0,(function(){var i,o,r,a,s,c,u,p;return l(this,(function(l){switch(l.label){case 0:i=v().apiUrl,o="".concat(i,"/chat/chatbot/get/"),d.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{},launcher_info:$()},l.label=1;case 1:return l.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 2:return(a=l.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=l.sent(),new Error(Y[j](a.status,s));case 4:return[4,a.json()];case 5:if(c=l.sent(),!(null===(p=null==c?void 0:c.user)||void 0===p?void 0:p.org_info))throw new Error(Y[W](["user","org_info"]));return[2,c];case 6:throw u=l.sent(),L.trackError(u instanceof Error?u:new Error(Y[F]({error:String(u)})),"fetchChatbotConfig",{errorCode:u instanceof Error&&u.message.includes("API Request Failed")?j:F,errorType:K,context:{chatbotId:e,userId:t,apiUrl:i,statusCode:u instanceof Response?u.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),u;case 7:return[2]}}))}))},te=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)}))},ne=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()},ie=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=/")},oe=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},re=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 d.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="×",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:c(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;d.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),d.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){(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:oe(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;d.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(d.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;d.log("toggleIframe"),null===(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"),d.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}(),ae=function(e,t,n){if(e.chatbotId&&e.userId)try{new re(e);t(!0),d.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},se=function(t){var n=e.useMemo((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||{}}}(t)}),[t.api_key,t.user_id,t.user_token,JSON.stringify(t.user_profile)]),i=e.useState({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),o=i[0],r=i[1],c=e.useMemo((function(){return n.user_profile?Object.fromEntries(Object.entries(n.user_profile).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(n.user_profile)]),d=e.useCallback((function(e){r((function(t){return a(a({},t),e)}))}),[]),u=e.useCallback((function(){return s(void 0,void 0,void 0,(function(){var e,t,i,o,r,s,u,p,f,h,v,g,m,b,y,_,w,E,I,x,T,C,S,O,R,k,D,z,M,B,j,F,W,U,P,V;return l(this,(function(l){switch(l.label){case 0:if(!n.api_key)return L.trackError(new Error(Y[N](n.api_key)),"useChatbotState",{errorCode:N,errorType:G,context:{timestamp:Date.now()}}),[2];d({isInitializing:!0}),l.label=1;case 1:return l.trys.push([1,4,5,6]),e=n.user_id||void 0,t=!1,e||(e=ne("rblyn_anon")||te(),ie("rblyn_anon",e,365),t=!0),[4,ee(n.api_key,e,n.user_token)];case 2:return i=l.sent(),o=A(),r=$(),s=a(a(a({},o),{__INT_SYS_INFO__:a(a({},o),r)}),c),u={chatbotId:n.api_key,userId:e,token:n.user_token,isAnonymous:t,domain:"",show_launcher:null===(v=null===(h=i.user.org_info)||void 0===h?void 0:h.show_launcher)||void 0===v||v,brand_colour:(null===(m=null===(g=i.user.org_info.brand_config)||void 0===g?void 0:g.colors)||void 0===m?void 0:m.brand_color)||"",image_url:(null===(y=null===(b=i.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===y?void 0:y.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(_=i.user.org_info.brand_config)||void 0===_?void 0:_.display_name)||"",welcome_message:(null===(w=i.user.org_info.brand_config)||void 0===w?void 0:w.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)||exports.WidgetPositionEnums.RIGHT,side_spacing:null!==(S=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!==S?S:20,bottom_spacing:null!==(k=null===(R=null===(O=i.user.org_info.brand_config)||void 0===O?void 0:O.interface_properties)||void 0===R?void 0:R.bottom_spacing)&&void 0!==k?k:20},interface_type:(null===(D=i.user.org_info.brand_config)||void 0===D?void 0:D.interface_type)||exports.ChatbotInterfaceType.WIDGET,launcher_type:(null===(z=i.user.org_info.brand_config)||void 0===z?void 0:z.launcher_type)||exports.LauncherType.IMAGE,launcher_properties:{text:(null===(B=null===(M=i.user.org_info.brand_config)||void 0===M?void 0:M.launcher_properties)||void 0===B?void 0:B.text)||""},images:{launcher_image_url:{url:(null===(W=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===W?void 0:W.url)||""}},proactive_message_obj:(null===(U=i.user.org_info.brand_config)||void 0===U?void 0:U.proactive_message_obj)||void 0,launcher_delay:(null===(V=null===(P=i.user.org_info)||void 0===P?void 0:P.brand_config)||void 0===V?void 0:V.launcher_delay)||{enabled:!1,delay:0}},[4,new Promise((function(e,t){ae(u,(function(){d({isInitialized:!0,chatbotConfig:u}),e()}),(function(e){t(e)}))}))];case 3:return l.sent(),[3,6];case 4:return p=l.sent(),f=p instanceof Error?p.message:"Failed to initialize chatbot",d({error:f}),L.trackError(p instanceof Error?p:new Error(f),"useChatbotState",{errorCode:H,errorType:G,context:{timestamp:Date.now()}}),[3,6];case 5:return d({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[n.api_key,n.user_id,n.user_token]);e.useEffect((function(){n.api_key&&u()}),[u]),e.useEffect((function(){o.chatbotConfig&&r((function(e){return a(a({},e),{chatbotConfig:a(a({},e.chatbotConfig),{userProfile:a(a({},A()),c)})})}))}),[c]);var p=e.useCallback((function(){r((function(e){return a(a({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),f=e.useCallback((function(){d({isIframeVisible:!1})}),[]);return a(a({},o),{toggleIframeVisibility:p,closeIframe:f})},le=function(t){var n=t.api_key,i=t.chatbotConfig,o=t.user_profile,r=t.onEvent,c=e.useMemo((function(){return{isAnonymous:(null==i?void 0:i.isAnonymous)||!1,userId:(null==i?void 0:i.userId)||""}}),[null==i?void 0:i.isAnonymous,null==i?void 0:i.userId]),u=e.useMemo((function(){return o||{}}),[JSON.stringify(o)]),f=e.useCallback((function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];return s(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],t,!0),void 0,(function(e,t){var i,o,r,s,p,f,h;return void 0===t&&(t={}),l(this,(function(l){switch(l.label){case 0:if(!n)return[2];l.label=1;case 1:return l.trys.push([1,3,,4]),i=v().apiUrl,o=A(),r=a({trigger_time:Date.now(),channel:"CHATBOT",launch_url:(null===(h=null===window||void 0===window?void 0:window.location)||void 0===h?void 0:h.href)||"",org_id:n,client_user_id:c.isAnonymous?"Anonymous":String(c.userId),event_type:e,user_profile:u},t),s={org_id:n,event_data:r,metadata:a({timestamp:Date.now()},o),event_type:"INFO",user_id:c.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 2:if(!(p=l.sent()).ok)throw new Error("Failed to send internal event: ".concat(p.statusText));return[3,4];case 3:return f=l.sent(),d.error("Failed to send internal event:",f),[3,4];case 4:return[2]}}))}))}),[n,c]);return{emitEvent:e.useCallback((function(e,t){var n=Date.now();e!==p.CHATBOT_BUTTON_CLICKED&&e!==p.CHATBOT_CLOSED&&e!==p.CHATBOT_OPENED&&e!==p.CHATBOT_READY||(r&&r({type:e,timestamp:n,data:t}),f(e,{timestamp:n}))}),[r,f]),onInternalEvent:f}},ce=function(t){var n,i,o,r,s,l,c,u=t.children,p=t.config,f=t.position,h=t.sideSpacing,v=t.bottomSpacing,g=e.useState(!1),m=g[0],b=g[1];e.useEffect((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;b(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]);var y=f||(null===(o=p.interface_properties)||void 0===o?void 0:o.position)||"Right",_=null!==(s=null!=h?h:null===(r=p.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,w=null!==(c=null!=v?v:null===(l=p.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==c?c:20;d.log("config",p,y,_);var E={position:"fixed",zIndex:1e3,display:"flex",flexDirection:"column"},I=a(a({},E),((n={bottom:"".concat(w,"px")})[y.toLowerCase()]="".concat(null!=_?_:20,"px"),n.alignItems="Right"===y?"flex-end":"flex-start",n.top=void 0,n["Right"===y?"left":"right"]=void 0,n)),x=a(a({},E),((i={top:0})[y.toLowerCase()]="".concat(null!=_?_:20,"px"),i.alignItems="center",i.bottom=void 0,i["Right"===y?"left":"right"]=void 0,i)),T=m?x:I;return e.useEffect((function(){console.log("Container screen width changed, isMobile:",m,"Style:",T)}),[m,T]),e.createElement("div",{className:"robylon-chatbot-container",style:T},u)},de=e.forwardRef((function(t,n){var i,o,r,s=t.api_key,l=t.user_id,c=t.user_token,u=t.user_profile,f=t.onEvent,h=t.position,v=t.sideSpacing,g=t.bottomSpacing;t.show_launcher;var m=t.launcher_type,b=t.launcher_properties_text,y="string"==typeof v?""===v||isNaN(Number(v))?void 0:Number(v):v,_="string"==typeof g?""===g||isNaN(Number(g))?void 0:Number(g):g,w="string"==typeof h?"left"===h.toLowerCase()?"Left":"right"===h.toLowerCase()?"Right":void 0:h;e.useEffect((function(){}));var E=e.useMemo((function(){return{api_key:s,user_id:l,user_token:c,user_profile:u}}),[s,l,c,u]),I=e.useCallback((function(e){null==f||f(e)}),[f]),T=se(E),C=T.isInitialized,S=T.error,A=T.chatbotConfig,O=T.isIframeVisible,R=T.toggleIframeVisibility,k=T.closeIframe,D=e.useMemo((function(){return{api_key:s,user_profile:E.user_profile,onEvent:I,chatbotConfig:A?{isAnonymous:A.isAnonymous,userId:A.userId}:null}}),[s,E.user_profile,I,null==A?void 0:A.isAnonymous,null==A?void 0:A.userId]),z=le(a({},D)),M=z.emitEvent,H=z.onInternalEvent;e.useImperativeHandle(n,(function(){return{show:function(){C&&A?O||(R(),M(p.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot show - chatbot not ready yet")},hide:function(){C&&A?O&&(k(),M(p.CHATBOT_CLOSED)):console.warn("Robylon Chatbot: Cannot hide - chatbot not ready yet")},toggle:function(){C&&A?(R(),M(O?p.CHATBOT_CLOSED:p.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot toggle - chatbot not ready yet")},isReady:C&&!!A}}),[C,A,O,R,k,M]),e.useEffect((function(){C&&A&&M(p.CHATBOT_READY)}),[C,A,M]);var j=e.useState(!1),F=j[0],W=j[1];e.useEffect((function(){var e,t,n,i,o,r;if(!(!0===(null==A?void 0:A.show_launcher)))return W(!1),function(){r&&clearTimeout(r)};var a=!0===(null===(e=null==A?void 0:A.launcher_delay)||void 0===e?void 0:e.enabled),s=null!==(o=null!==(n=null===(t=null==A?void 0:A.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==A?void 0:A.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0;return a&&Number(s)>0?(W(!1),r=window.setTimeout((function(){W(!0)}),1e3*Number(s))):W(!0),function(){r&&clearTimeout(r)}}),[null==A?void 0:A.show_launcher,null===(i=null==A?void 0:A.launcher_delay)||void 0===i?void 0:i.enabled,null===(o=null==A?void 0:A.launcher_delay)||void 0===o?void 0:o.seconds,null===(r=null==A?void 0:A.launcher_delay)||void 0===r?void 0:r.delay]),e.useEffect((function(){if(s)try{L.initialize(s,l)}catch(e){L.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:B,errorType:G,context:{timestamp:Date.now()}})}else L.trackError(new Error(Y[N](s)),"RobylonChatbot",{errorCode:N,errorType:G,context:{timestamp:Date.now()}})}),[s,l]);var U=e.useCallback((function(){k(),M(p.CHATBOT_CLOSED)}),[k,M]),P=e.useCallback((function(){R(),M(O?p.CHATBOT_CLOSED:p.CHATBOT_BUTTON_CLICKED)}),[R,M,O]),V=e.useMemo((function(){var e,t,n,i,o;return{config:A,toggleIframe:P,isIframeVisible:O,onEvent:I,onInternalEvent:H,position:w,sideSpacing:y,bottomSpacing:_,launcher_type:m,launcher_properties_text:b,shouldFadeIn:!0===(null===(e=null==A?void 0:A.launcher_delay)||void 0===e?void 0:e.enabled)&&(null!==(o=null!==(n=null===(t=null==A?void 0:A.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==A?void 0:A.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0)>0||!1}}),[A,P,O,I,H,w,y,_,m,b]);d.log("floatingButtonProps",V);var K=e.useMemo((function(){return{config:A,isVisible:O,onClose:U,onEvent:I,onInternalEvent:H,position:w,bottomSpacing:_}}),[A,O,U,I,H,w,_]);return s&&!S&&A?e.createElement(X,{componentName:"RobylonChatbot"},C?e.createElement(ce,{config:A,position:w,sideSpacing:y,bottomSpacing:_},e.createElement(X,{componentName:"ChatbotIframe"},e.createElement(Q,a({},K))),e.createElement(X,{componentName:"ChatbotFloatingButton"},F?e.createElement(x,a({},V)):null)):null):null})),ue=e.memo(de,(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)&&e.position===t.position&&e.sideSpacing===t.sideSpacing&&e.bottomSpacing===t.bottomSpacing&&e.show_launcher===t.show_launcher&&e.launcher_type===t.launcher_type&&e.launcher_properties_text===t.launcher_properties_text&&!0})),pe=function(){function e(e){var t=this;this.resizeObserver=null,this.proactiveElement=null,this.config=e,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount();try{this.buttonElement.style.opacity="0",this.buttonElement.style.transition="transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",requestAnimationFrame((function(){t.buttonElement.style.opacity="1"}))}catch(e){}this.setupResizeListener(),this.renderProactiveIfNeeded()}return e.prototype.render=function(){var e=this;v().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:m};n.launcher_type===exports.LauncherType.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()},this.renderProactiveIfNeeded()},e.prototype.createLauncherElement=function(){var e,t,n=this.config,i=n.config,o=n.isIframeVisible,r=v().copilotUrl;switch(console.log("config in floating button",i),i.launcher_type){case exports.LauncherType.TEXT:return this.createTextLauncher();case exports.LauncherType.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case exports.LauncherType.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:c(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:b,fontFamily:m,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=v().copilotUrl,s=this.config.config,l=s.brand_colour,d=s.launcher_properties,u=s.image_url,p=document.createElement("div");Object.assign(p.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 f=document.createElement("div");Object.assign(f.style,{flex:"1",minWidth:"0"});var h=document.createElement("p");Object.assign(h.style,{margin:"0",color:c(l),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:b,fontFamily:m,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),h.textContent=(null==d?void 0:d.text)||"";var g=document.createElement("div");Object.assign(g.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var y=document.createElement("img");return y.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"):u||"".concat(a,"/chatbubble.png"),y.alt="Chat",Object.assign(y.style,{width:"100%",height:"100%",objectFit:"cover"}),f.appendChild(h),g.appendChild(y),p.appendChild(f),p.appendChild(g),p},e.prototype.applyResponsiveStyles=function(e){var t,n,i,o,r,s,l,c,d,u=(null===window||void 0===window?void 0:window.innerWidth)<560,p=this.config.config,f=this.config.position||(null===(i=p.interface_properties)||void 0===i?void 0:i.position)||"Right",h=null!==(s=null!==(o=this.config.sideSpacing)&&void 0!==o?o:null===(r=p.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==s?s:20,v=null!==(d=null!==(l=this.config.bottomSpacing)&&void 0!==l?l:null===(c=p.interface_properties)||void 0===c?void 0:c.bottom_spacing)&&void 0!==d?d:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var g=a(a({},e),u?((t={position:"fixed",bottom:"".concat(v,"px")})[f.toLowerCase()]="".concat(h,"px"),t):((n={bottom:"".concat(v,"px")})[f.toLowerCase()]="".concat(h,"px"),n));Object.assign(this.buttonElement.style,g)},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!==exports.LauncherType.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===exports.LauncherType.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:p.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(p.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config.isIframeVisible,this.config=a(a({},this.config),e),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render(),this.renderProactiveIfNeeded()},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),this.proactiveElement&&this.proactiveElement.parentElement&&(this.proactiveElement.parentElement.removeChild(this.proactiveElement),this.proactiveElement=null)},e.prototype.renderProactiveIfNeeded=function(){var e,t,n,i,o,r,a,s,l,c=this,d=null===(t=null===(e=this.config)||void 0===e?void 0:e.config)||void 0===t?void 0:t.proactive_message_obj;if(!(I(d)&&!this.config.isIframeVisible))return this.proactiveElement&&this.proactiveElement.parentElement&&this.proactiveElement.parentElement.removeChild(this.proactiveElement),void(this.proactiveElement=null);if(!this.proactiveElement){var u=document.createElement("div");u.style.position="fixed";var p=null!==(o=null!==(n=this.config.bottomSpacing)&&void 0!==n?n:null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==o?o:20,f=null!==(s=null!==(r=this.config.sideSpacing)&&void 0!==r?r:null===(a=this.config.config.interface_properties)||void 0===a?void 0:a.side_spacing)&&void 0!==s?s:20,h=this.config.position||(null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.position)||"Right";u.style.bottom="".concat(p+(this.config.config.launcher_type===exports.LauncherType.IMAGE?48:40)+8,"px"),"Right"===h?u.style.right="".concat(f,"px"):u.style.left="".concat(f,"px"),u.style.maxWidth="22.875rem",u.style.zIndex="2147483646";var v=document.createElement("div");v.style.background="#fff",v.style.color="#111",v.style.borderRadius="16px",v.style.boxShadow="0 0 40px 0 rgba(14, 14, 15, 0.24)",v.style.padding="16px",v.style.cursor="pointer",v.style.fontFamily=m,v.style.fontSize="14px",v.style.lineHeight=String(b),v.textContent=(null==d?void 0:d.content)||"",v.onclick=function(){c.config.toggleIframe(),_()};var g=document.createElement("div");g.style.position="absolute",g.style.top="-32px",g.style.width="24px",g.style.height="24px",g.style.borderRadius="50%",g.style.background="#fff",g.style.boxShadow="0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",g.style.display="flex",g.style.alignItems="center",g.style.justifyContent="center",g.style.cursor="pointer","Right"===h?(g.style.right="0px",g.style.left="auto"):(g.style.left="0px",g.style.right="auto"),g.onclick=function(e){e.stopPropagation(),_(),c.proactiveElement&&c.proactiveElement.parentElement&&c.proactiveElement.parentElement.removeChild(c.proactiveElement),c.proactiveElement=null},g.innerHTML='\n <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none">\n <path d="M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334" stroke="#444547" stroke-width="0.816326" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n ',u.appendChild(v),u.appendChild(g),document.body.appendChild(u),this.proactiveElement=u}},e}(),fe=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,h,g,m,b,y,_=v().copilotUrl;if(e.origin===_){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(f.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:p.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(p.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:p.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(p.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:p.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(p.CHAT_INITIALIZATION_FAILED,{error:null===(h=e.data)||void 0===h?void 0:h.error})),"SESSION_REFRESHED"===(null===(g=e.data)||void 0===g?void 0:g.type)&&(null===(b=(m=t.config).onEvent)||void 0===b||b.call(m,{type:p.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(p.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(y=e.data)||void 0===y?void 0:y.type)&&t.config.onInternalEvent(f.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=this.config.position||(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,r;if(this.iframeElement){var a=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",s=null!==(r=null!==(i=this.config.bottomSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.bottom_spacing)&&void 0!==r?r:20;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(s,"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=v().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,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(){L.trackError(new Error(Y[U]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:J,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=this.config.position||(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 f=v().copilotUrl,h=new URL(this.iframeElement.src).origin||f;this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},h),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}},h),this.hasRegistered=!0),null===(c=(l=this.config).onEvent)||void 0===c||c.call(l,{type:p.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(p.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=a(a({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=v().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},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}(),he=function(){function e(e,t,n,i){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config={config:e,position:t,sideSpacing:n,bottomSpacing:i},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,s,l,c,d=(null===window||void 0===window?void 0:window.innerWidth)<560,u=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",p=null!==(r=null!==(i=this.config.sideSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.side_spacing)&&void 0!==r?r:20,f=null!==(c=null!==(s=this.config.bottomSpacing)&&void 0!==s?s:null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==c?c:20;this.containerElement.style.position="",this.containerElement.style.top="",this.containerElement.style.bottom="",this.containerElement.style.right="",this.containerElement.style.left="",this.containerElement.style.alignItems="";var h={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},v=a(a({},h),((e={bottom:"".concat(f,"px")})[u.toLowerCase()]="".concat(p,"px"),e.alignItems="Right"===u?"flex-end":"flex-start",e)),g=a(a({},h),((t={top:"0"})[u.toLowerCase()]="".concat(p,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,d?g:v)},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}(),ve=function(e,t,n){return s(void 0,void 0,void 0,(function(){var i,o,r,a,s,c,u,p;return l(this,(function(l){switch(l.label){case 0:return l.trys.push([0,5,,6]),i=v().apiUrl,o="".concat(i,"/chat/chatbot/get/"),d.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{},launcher_info:$()},[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(a=l.sent()).ok?[3,3]:[4,a.text()];case 2:throw s=l.sent(),new Error(Y[j](a.status,s));case 3:return[4,a.json()];case 4:if(c=l.sent(),!(null===(p=null==c?void 0:c.user)||void 0===p?void 0:p.org_info))throw new Error(Y[W](["user","org_info"]));return[2,c];case 5:throw u=l.sent(),L.trackError(u instanceof Error?u:new Error(Y[F]({error:String(u)})),"fetchChatbotConfig",{errorCode:u instanceof Error&&u.message.includes("API Request Failed")?j:F,errorType:K,context:{apiKey:e,userId:t,timestamp:Date.now()}}),u;case 6:return[2]}}))}))},ge=function(e){return s(void 0,void 0,void 0,(function(){var t,n,i,o,r,s,c,d,u,p,f,h,v,g,m,b,y,_,w,E,I,x,T,C,S,O,R,k,D,L,N,z,M,H;return l(this,(function(l){switch(l.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=ne("rblyn_anon")||te(),ie("rblyn_anon",n,365),i=!0),[4,ve(t.api_key,n,t.user_token)];case 1:return o=l.sent(),r=A(),s=$(),B=t.user_profile,c=B?Object.fromEntries(Object.entries(B).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},d=a(a(a({},r),{__INT_SYS_INFO__:a(a({},r),s)}),c),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",show_launcher:null===(p=null===(u=o.user.org_info)||void 0===u?void 0:u.show_launcher)||void 0===p||p,brand_colour:(null===(h=null===(f=o.user.org_info.brand_config)||void 0===f?void 0:f.colors)||void 0===h?void 0:h.brand_color)||"",image_url:(null===(g=null===(v=o.user.org_info)||void 0===v?void 0:v.brand_config)||void 0===g?void 0:g.launcher_logo_url)||"",userProfile:d,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(m=o.user.org_info.brand_config)||void 0===m?void 0:m.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===(y=o.user.org_info.brand_config)||void 0===y?void 0:y.redirect_url)||""},launcher_type:(null===(_=o.user.org_info.brand_config)||void 0===_?void 0:_.launcher_type)||exports.LauncherType.IMAGE,launcher_properties:{text:(null===(E=null===(w=o.user.org_info.brand_config)||void 0===w?void 0:w.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)||""}},proactive_message_obj:(null===(O=null===(S=null===(C=null==o?void 0:o.user)||void 0===C?void 0:C.org_info)||void 0===S?void 0:S.brand_config)||void 0===O?void 0:O.proactive_message_obj)||void 0,interface_properties:{position:(null===(k=null===(R=o.user.org_info.brand_config)||void 0===R?void 0:R.interface_properties)||void 0===k?void 0:k.position)||exports.WidgetPositionEnums.RIGHT,side_spacing:(null===(L=null===(D=o.user.org_info.brand_config)||void 0===D?void 0:D.interface_properties)||void 0===L?void 0:L.side_spacing)||20,bottom_spacing:(null===(z=null===(N=o.user.org_info.brand_config)||void 0===N?void 0:N.interface_properties)||void 0===z?void 0:z.bottom_spacing)||20},interface_type:(null===(M=o.user.org_info.brand_config)||void 0===M?void 0:M.interface_type)||exports.ChatbotInterfaceType.WIDGET,launcher_delay:(null===(H=o.user.org_info.brand_config)||void 0===H?void 0:H.launcher_delay)||{enabled:!1,delay:0}}]}var B}))}))},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){}}},be=function(){function e(e){var t=this;this.container=null,this.floatingButton=null,this.launcherDelayTimeout=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){var n,i,o,r,a;if(!t.isDestroyed){var s=e.isInitialized,l=e.error,c=e.chatbotConfig,d=e.isIframeVisible;if(!l&&c&&s){if(t.eventEmitter=me({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:c.isAnonymous,userId:c.userId}}),t.container||(t.container=new he(c,t.config.position,t.config.sideSpacing,t.config.bottomSpacing)),t.iframe)t.iframe.update({config:c,isVisible:d,position:t.config.position,bottomSpacing:t.config.bottomSpacing});else if(t.iframe=new fe({config:c,isVisible:d,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,bottomSpacing:t.config.bottomSpacing}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var u=t.iframe.getElement();u&&t.container&&t.container.getElement().prepend(u)}var p=!0===(null==c?void 0:c.show_launcher),f=!0===(null===(n=null==c?void 0:c.launcher_delay)||void 0===n?void 0:n.enabled),h=null!==(a=null!==(o=null===(i=null==c?void 0:c.launcher_delay)||void 0===i?void 0:i.seconds)&&void 0!==o?o:null===(r=null==c?void 0:c.launcher_delay)||void 0===r?void 0:r.delay)&&void 0!==a?a:0,v=function(){if(t.floatingButton)t.floatingButton.update({config:c,isIframeVisible:d,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing});else if(t.floatingButton=new pe({config:c,toggleIframe:t.toggleIframe,isIframeVisible:d,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var e=t.floatingButton.getElement();e&&t.container&&t.container.getElement().appendChild(e)}};t.launcherDelayTimeout&&(clearTimeout(t.launcherDelayTimeout),t.launcherDelayTimeout=null),p?f&&Number(h)>0&&!t.floatingButton?t.launcherDelayTimeout=window.setTimeout((function(){v(),t.launcherDelayTimeout=null}),1e3*Number(h)):v():t.floatingButton&&(t.floatingButton.destroy(),t.floatingButton=null)}}},this.toggleIframe=function(){var e=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(e.isIframeVisible?p.CHATBOT_CLOSED:p.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(p.CHATBOT_CLOSED)};var n,i,o,r,c=a(a({},e),{position:"string"==typeof e.position?"left"===e.position.toLowerCase()?"Left":"right"===e.position.toLowerCase()?"Right":void 0:void 0,sideSpacing:"string"==typeof e.sideSpacing?""===e.sideSpacing||isNaN(Number(e.sideSpacing))?void 0:Number(e.sideSpacing):e.sideSpacing,bottomSpacing:"string"==typeof e.bottomSpacing?""===e.bottomSpacing||isNaN(Number(e.bottomSpacing))?void 0:Number(e.bottomSpacing):e.bottomSpacing});if(this.config=c,!e.api_key)throw L.trackError(new Error(Y[N](e.api_key)),"RobylonChatbot",{errorCode:N,errorType:G,context:{timestamp:Date.now()}}),new Error("API key is required");try{L.initialize(e.api_key,e.user_id)}catch(e){L.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:B,errorType:G,context:{timestamp:Date.now()}})}this.stateManager=(n={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},i={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},o=[],{getState:function(){return i},initialize:function(){return s(void 0,void 0,void 0,(function(){var e,t,i;return l(this,(function(o){switch(o.label){case 0:if(!n.api_key)return L.trackError(new Error(Y[N](n.api_key)),"ChatbotStateManager",{errorCode:N,errorType:G,context:{timestamp:Date.now()}}),[2];r({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,ge(n)];case 2:return e=o.sent(),[4,new Promise((function(t,n){ae(e,(function(){r({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return o.sent(),[3,6];case 4:return t=o.sent(),i=t instanceof Error?t.message:"Failed to initialize chatbot",r({error:i}),L.trackError(t instanceof Error?t:new Error(i),"ChatbotStateManager",{errorCode:H,errorType:G,context:{timestamp:Date.now()}}),[3,6];case 5:return r({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){r({isIframeVisible:!i.isIframeVisible})},closeIframe:function(){r({isIframeVisible:!1})},updateState:r=function(e){i=a(a({},i),e),o.forEach((function(e){return e(i)}))},subscribe:function(e){return o.push(e),function(){var t=o.indexOf(e);t>-1&&o.splice(t,1)}},unsubscribe:function(e){var t=o.indexOf(e);t>-1&&o.splice(t,1)}}),this.eventEmitter=me({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),window.RobylonShouldShowProactive=I,window.RobylonHideProactive=_,this.initialize()}return e.prototype.initialize=function(){return s(this,void 0,void 0,(function(){var e;return l(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(),L.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:H,errorType:G,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(p.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(p.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.launcherDelayTimeout&&(clearTimeout(this.launcherDelayTimeout),this.launcherDelayTimeout=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 ye(e){return new be(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=ye(i)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(e){var n=Array.prototype.slice.call(arguments,1);return"init"===e?t=ye(n[0]||{}):t&&"function"==typeof t[e]?t[e].apply(t,n):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var _e={create:ye,getState:function(){return"initialized"}};exports.Chatbot=ue,exports.RobylonChatbot=_e,exports.useChatbot=function(t){var n=e.useState({isLoading:!0,isInitialized:!1,error:null}),i=n[0],o=n[1],r=function(e){o((function(t){return a(a({},t),{isInitialized:e})}))},s=function(e){o((function(t){return a(a({},t),{error:e})}))};return e.useEffect((function(){!function(){try{ae(t,r,s)}catch(e){o((function(t){return a(a({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[t.chatbotId,t.userId]),i};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
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 l,forwardRef as s,useImperativeHandle as c}from"react";var d=function(e,t){return d=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])},d(e,t)};var u,p,f,v,h=function(){return h=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},h.apply(this,arguments)};function g(e,t,n,i){return new(n||(n=Promise))((function(o,r){function a(e){try{s(i.next(e))}catch(e){r(e)}}function l(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((i=i.apply(e,t||[])).next())}))}function m(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=l(0),a.throw=l(1),a.return=l(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(l){return function(s){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(r=0)),r;)try{if(n=1,i&&(o=2&l[0]?i.return:l[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,l[1])).done)return o;switch(i=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return r.label++,{value:l[1],done:!1};case 5:r.label++,i=l[1],l=[0];continue;case 7:l=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){r=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){r.label=l[1];break}if(6===l[0]&&r.label<o[1]){r.label=o[1],o=l;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(l);break}o[2]&&r.ops.pop(),r.trys.pop();continue}l=t.call(e,r)}catch(e){l=[6,e],i=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,s])}}}"function"==typeof SuppressedError&&SuppressedError,function(e){e.WIDGET="WIDGET",e.POPOVER="POPOVER",e.EMBED="EMBED"}(u||(u={})),function(e){e.RIGHT="Right",e.LEFT="Left"}(p||(p={})),function(e){e.TEXT="TEXT",e.IMAGE="IMAGE",e.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(f||(f={})),function(e){e.WORKING_HOURS="WORKING_HOURS",e.ALWAYS="ALWAYS"}(v||(v={}));var b=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"},y={log:function(){},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(){}};y.log("Raw API_URL:","https://stage-api.robylon.ai");var _={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};y.log("CONFIG",_);var w,E,I=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},x=function(){return{copilotUrl:_.copilotUrl||"https://app.robylon.ai",environment:_.environment||"production",apiUrl:_.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",e.CHATBOT_READY="CHATBOT_READY"}(w||(w={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(E||(E={}));var T,C="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",S="21px",A=!1,O=function(){A=!0};console.log("isProactiveHiddenThisPage",(function(){return A}));var R,D=((T={})[v.WORKING_HOURS]=function(e,t){var n=t.getHours(),i=t.getMinutes();return(n>10||10===n&&i>=0)&&(n<19||19===n&&0===i)},T[v.ALWAYS]=function(e,t){return!0},T),k=function(e,t){var n;if(void 0===t&&(t=new Date),console.log("proactiveHiddenThisPage shouldShowProactiveMessage",A),!(null===(n=null==e?void 0:e.content)||void 0===n?void 0:n.trim()))return!1;if(A)return!1;var i=(null==e?void 0:e.send_time_type)||"";if(!i)return!0;var o=D[i];return!!o&&o(e,t)},L=t((function(t){var r,a,l,s,c,d,u,p,v,g,m,_,E,I,T,A,O,R,D,L=t.config,N=t.toggleIframe,z=t.isIframeVisible,M=t.onEvent,H=t.onInternalEvent,B=t.position,j=t.sideSpacing,F=t.bottomSpacing,U=t.launcher_type,W=t.launcher_properties_text,P=t.shouldFadeIn,V=n(null),G=x().copilotUrl,K=i(!1),J=K[0],Z=K[1],Y=i(!1),Q=Y[0],X=Y[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;Z(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),o((function(){V.current&&requestAnimationFrame((function(){null==M||M({type:w.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),H(w.CHATBOT_BUTTON_LOADED)}))}),[M,H]),o((function(){if(V.current&&P){V.current.style.opacity="0";var e=requestAnimationFrame((function(){V.current&&(V.current.style.opacity="1")}));return function(){return cancelAnimationFrame(e)}}}),[P]);var q=B||(null===(l=L.interface_properties)||void 0===l?void 0:l.position)||"Right",$=null!==(c=null!=j?j:null===(s=L.interface_properties)||void 0===s?void 0:s.side_spacing)&&void 0!==c?c:20,ee=null!==(u=null!=F?F:null===(d=L.interface_properties)||void 0===d?void 0:d.bottom_spacing)&&void 0!==u?u:20,te=U||(null==L?void 0:L.launcher_type)||f.IMAGE,ne=W||(null===(p=null==L?void 0:L.launcher_properties)||void 0===p?void 0:p.text),ie={zIndex:1e3,display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",boxSizing:"border-box"};te===f.IMAGE&&(ie.width="48px",ie.height="48px",ie.borderRadius="50%",ie.backgroundColor=L.brand_colour);var oe=h(h({},ie),((r={position:void 0,bottom:"0",borderRadius:te===f.IMAGE?"50%":"9999px"})[q.toLowerCase()]="0",r)),re=h(h({},ie),((a={position:"fixed",bottom:"".concat(ee,"px"),borderRadius:te===f.IMAGE?"50%":"9999px"})[q.toLowerCase()]="".concat($,"px"),a)),ae=J?re:oe;o((function(){y.log("Screen width changed, isMobile:",J,"Style:",ae)}),[J,ae]),y.log("config in floating button",L);var le=k(null==L?void 0:L.proactive_message_obj)&&!z&&!Q;return e.createElement(e.Fragment,null,le?e.createElement("div",{className:"proactive-message-container",style:{position:"fixed",bottom:"".concat((null!==(g=null!=F?F:null===(v=L.interface_properties)||void 0===v?void 0:v.bottom_spacing)&&void 0!==g?g:20)+(te===f.IMAGE?48:40)+8,"px"),right:"Right"===(B||(null===(m=L.interface_properties)||void 0===m?void 0:m.position)||"Right")?"".concat(null!==(E=null!=j?j:null===(_=L.interface_properties)||void 0===_?void 0:_.side_spacing)&&void 0!==E?E:20,"px"):"auto",left:"Left"===(B||(null===(I=L.interface_properties)||void 0===I?void 0:I.position)||"Right")?"".concat(null!==(A=null!=j?j:null===(T=L.interface_properties)||void 0===T?void 0:T.side_spacing)&&void 0!==A?A:20,"px"):"auto",maxWidth:"22.875rem",zIndex:2147483646}},e.createElement("div",{onClick:function(){N(),X(!0)},style:{background:"#fff",color:"#111",borderRadius:"12px",boxShadow:"0 0 40px 0 rgba(14, 14, 15, 0.24)",padding:"16px",cursor:"pointer",fontFamily:C,lineHeight:S,fontSize:"14px"}},null===(O=null==L?void 0:L.proactive_message_obj)||void 0===O?void 0:O.content),e.createElement("div",{onClick:function(e){e.stopPropagation(),X(!0),console.log("Clicked close")},style:{position:"absolute",top:"-32px",right:"Right"===(B||(null===(R=L.interface_properties)||void 0===R?void 0:R.position)||"Right")?"0px":"auto",left:"Left"===(B||(null===(D=L.interface_properties)||void 0===D?void 0:D.position)||"Right")?"0px":"auto",width:"24px",height:"24px",borderRadius:"50%",background:"#fff",boxShadow:" 0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",userSelect:"none"},"aria-label":"Close proactive message"},e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 14 14",fill:"none"},e.createElement("path",{d:"M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334",stroke:"#444547",strokeWidth:"0.816326",strokeLinecap:"round",strokeLinejoin:"round"})))):null,e.createElement("div",{ref:V,className:"message-bubble-container",style:h(h({},ae),{transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",transform:z?"scale(0.85)":"scale(1)",opacity:P?0:1}),onClick:N},function(){switch(te){case f.TEXT:return e.createElement("div",{style:{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:L.brand_colour,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box",fontFamily:C,lineHeight:S}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:b(L.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:C,lineHeight:S,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},ne)));case f.TEXTUAL_IMAGE:return function(){var t,n;return e.createElement("div",{style:{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:L.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:C,lineHeight:S}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:b(L.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:C,lineHeight:S,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},ne)),e.createElement("div",{style:{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:0}},e.createElement("img",{src:(null==L?void 0:L.launcher_type)?(null===(n=null===(t=null==L?void 0:L.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(G,"/chatbubble.png"):(null==L?void 0:L.image_url)||"".concat(G,"/chatbubble.png"),alt:"Chat",style:{width:"100%",height:"100%",objectFit:"cover"}})))}();case f.IMAGE:default:return function(){var t,n;return z?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==L?void 0:L.launcher_type)?(null===(n=null===(t=null==L?void 0:L.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(G,"/chatbubble.png"):(null==L?void 0:L.image_url)||"".concat(G,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}})}()}}()))})),N=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]},z=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]},M=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)}},H=function(){return{platform:"web",os:N(),browser:z(),sdk_version:"1.1.40-staging.5",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:M()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(R||(R={}));var B,j=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],F=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&j.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))}))},U=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};F(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)};F(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){I()&&(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(){I()&&(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:H(),event_type:R.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){y.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 g(this,void 0,void 0,(function(){var e,t,n;return m(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];y.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,h(h({},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 g(this,void 0,void 0,(function(){var t,n,i,o,r,a;return m(this,(function(l){switch(l.label){case 0:return l.trys.push([0,4,,5]),t=x().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=l.sent()).ok?[3,3]:(o=(i=y).error,r=["Failed to send error log:"],[4,n.text()]);case 2:o.apply(i,r.concat([l.sent()])),l.label=3;case 3:return[3,5];case 4:return a=l.sent(),y.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return g(this,void 0,void 0,(function(){var i,o,r;return m(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:h(h({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:H(),event_type:R.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}),y.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:h(h({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:H(),event_type:R.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return g(this,void 0,void 0,(function(){var i,o;return m(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:H(),event_type:R.INFO,user_id:this.userId},[4,this.sendLog(o)]):(y.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),W=U.getInstance(),P="MISSING_API_KEY",V="INVALID_API_KEY",G="CONFIG_FETCH_FAILED",K="SDK_INIT_FAILED",J="ERROR_TRACKING_INIT_FAILED",Z="API_REQUEST_FAILED",Y="NETWORK_ERROR",Q="INVALID_RESPONSE",X="IFRAME_LOAD_FAILED",q="COOKIE_ACCESS_ERROR",$="COMPONENT_RENDER_ERROR",ee="INITIALIZATION_ERROR",te="API_ERROR",ne="RUNTIME_ERROR",ie="COMPONENT_ERROR",oe=((B={})[P]=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.")},B[V]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},B[G]=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):"")},B[Z]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},B[Y]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},B[X]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},B[Q]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},B[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):"")},B[K]=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)):"")},B[q]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},B[$]=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):"")},B),re=t((function(t){var i,a,l,s,c=t.config,d=t.isVisible,u=t.onClose,p=t.onEvent,f=t.onInternalEvent,v=t.position,h=t.bottomSpacing,g=n(null),m=n(!1),b=n(!1),y=v||(null===(i=c.interface_properties)||void 0===i?void 0:i.position)||"Right",_=null!==(l=null!=h?h:null===(a=c.interface_properties)||void 0===a?void 0:a.bottom_spacing)&&void 0!==l?l:20,I=r((function(){var e,t=g.current;if(t){var n=((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(_,"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)"})[y.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(t.style,n)}}),[_,y]);return o((function(){var e=g.current;if(e&&!m.current){var t=x().copilotUrl;Object.assign(e.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(y.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"}),e.src="".concat(t,"/chatbot-plugin?id=").concat(c.chatbotId),m.current=!0,I();var n=function(){var n,i,o=new URL(e.src).origin||t;null===(n=e.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)};return e.addEventListener("load",n),function(){return e.removeEventListener("load",n)}}}),[c.chatbotId,null===(s=c.interface_properties)||void 0===s?void 0:s.position,I]),o((function(){var e,t,n,i,o,r=g.current;if(r&&m.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 l=x().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"},l),(null==b?void 0:b.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}},l),b.current=!0)}}}),[d,c.userId,c.token,c.userProfile]),o((function(){if(g.current&&m.current){var e=x().copilotUrl;d&&(null==p||p({type:w.CHATBOT_OPENED,timestamp:Date.now()}),f(w.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,l,s;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(E.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==p||p({type:w.CHATBOT_LOADED,timestamp:Date.now()}),f(w.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==p||p({type:w.CHAT_INITIALIZED,timestamp:Date.now()}),f(w.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==p||p({type:w.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),f(w.CHAT_INITIALIZATION_FAILED,{error:null===(a=t.data)||void 0===a?void 0:a.error})),"SESSION_REFRESHED"===(null===(l=t.data)||void 0===l?void 0:l.type)&&(null==p||p({type:w.SESSION_REFRESHED,timestamp:Date.now()}),f(w.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(s=t.data)||void 0===s?void 0:s.type)&&f(E.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=g.current;if(e&&m.current){var t=function(){W.trackError(new Error(oe[X]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:X,errorType:ne,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(g.current&&c&&d){var t=g.current,n=x().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:c.userProfile},n)}}),[c.userProfile,d]),e.createElement("iframe",{ref:g,id:"chat-iframe-rbyln",style:{display:"none"}})})),ae=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}d(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){W.trackError(new Error(oe[$]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:$,errorType:ie,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(a),le=function(){var e,t=navigator.userAgent;if(null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands){var n=navigator.userAgentData.brands.find((function(e){return"Google Chrome"===e.brand}));if(null==n?void 0:n.version)return n.version}var i=t.match(/(Chrome|Firefox|Safari|Edge|Opera)\/(\d+\.\d+)/);return i?i[2]:"Unknown"},se=function(){var e,t,n=H();return{current_page_url:(null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.href)||"",browser_language:(null===navigator||void 0===navigator?void 0:navigator.language)||(null===(t=null===navigator||void 0===navigator?void 0:navigator.languages)||void 0===t?void 0:t[0])||"en",browser_version:le(),os:null==n?void 0:n.os,referral_url:(null===document||void 0===document?void 0:document.referrer)||""}},ce=function(e,t,n){return g(void 0,void 0,void 0,(function(){var i,o,r,a,l,s,c,d;return m(this,(function(u){switch(u.label){case 0:i=x().apiUrl,o="".concat(i,"/chat/chatbot/get/"),y.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{},launcher_info:se()},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 l=u.sent(),new Error(oe[Z](a.status,l));case 4:return[4,a.json()];case 5:if(s=u.sent(),!(null===(d=null==s?void 0:s.user)||void 0===d?void 0:d.org_info))throw new Error(oe[Q](["user","org_info"]));return[2,s];case 6:throw c=u.sent(),W.trackError(c instanceof Error?c:new Error(oe[Y]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?Z:Y,errorType:te,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]}}))}))},de=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)}))},ue=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()},pe=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=/")},fe=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},ve=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 y.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="×",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:b(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;y.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),y.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:fe(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;y.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(y.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;y.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"),y.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}(),he=function(e,t,n){if(e.chatbotId&&e.userId)try{new ve(e);t(!0),y.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},ge=function(e){var t=l((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],s=n[1],c=l((function(){return t.user_profile?Object.fromEntries(Object.entries(t.user_profile).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)]),d=r((function(e){s((function(t){return h(h({},t),e)}))}),[]),v=r((function(){return g(void 0,void 0,void 0,(function(){var e,n,i,o,r,a,l,s,v,g,b,y,_,w,E,I,x,T,C,S,A,O,R,D,k,L,N,z,M,B,j,F,U,V,G,J;return m(this,(function(m){switch(m.label){case 0:if(!t.api_key)return W.trackError(new Error(oe[P](t.api_key)),"useChatbotState",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}}),[2];d({isInitializing:!0}),m.label=1;case 1:return m.trys.push([1,4,5,6]),e=t.user_id||void 0,n=!1,e||(e=ue("rblyn_anon")||de(),pe("rblyn_anon",e,365),n=!0),[4,ce(t.api_key,e,t.user_token)];case 2:return i=m.sent(),o=H(),r=se(),a=h(h(h({},o),{__INT_SYS_INFO__:h(h({},o),r)}),c),l={chatbotId:t.api_key,userId:e,token:t.user_token,isAnonymous:n,domain:"",show_launcher:null===(b=null===(g=i.user.org_info)||void 0===g?void 0:g.show_launcher)||void 0===b||b,brand_colour:(null===(_=null===(y=i.user.org_info.brand_config)||void 0===y?void 0:y.colors)||void 0===_?void 0:_.brand_color)||"",image_url:(null===(E=null===(w=i.user.org_info)||void 0===w?void 0:w.brand_config)||void 0===E?void 0:E.launcher_logo_url)||"",userProfile:a,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(I=i.user.org_info.brand_config)||void 0===I?void 0:I.display_name)||"",welcome_message:(null===(x=i.user.org_info.brand_config)||void 0===x?void 0:x.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(T=i.user.org_info.brand_config)||void 0===T?void 0:T.redirect_url)||""},interface_properties:{position:(null===(S=null===(C=i.user.org_info.brand_config)||void 0===C?void 0:C.interface_properties)||void 0===S?void 0:S.position)||p.RIGHT,side_spacing:null!==(R=null===(O=null===(A=i.user.org_info.brand_config)||void 0===A?void 0:A.interface_properties)||void 0===O?void 0:O.side_spacing)&&void 0!==R?R:20,bottom_spacing:null!==(L=null===(k=null===(D=i.user.org_info.brand_config)||void 0===D?void 0:D.interface_properties)||void 0===k?void 0:k.bottom_spacing)&&void 0!==L?L:20},interface_type:(null===(N=i.user.org_info.brand_config)||void 0===N?void 0:N.interface_type)||u.WIDGET,launcher_type:(null===(z=i.user.org_info.brand_config)||void 0===z?void 0:z.launcher_type)||f.IMAGE,launcher_properties:{text:(null===(B=null===(M=i.user.org_info.brand_config)||void 0===M?void 0:M.launcher_properties)||void 0===B?void 0:B.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)||""}},proactive_message_obj:(null===(V=i.user.org_info.brand_config)||void 0===V?void 0:V.proactive_message_obj)||void 0,launcher_delay:(null===(J=null===(G=i.user.org_info)||void 0===G?void 0:G.brand_config)||void 0===J?void 0:J.launcher_delay)||{enabled:!1,delay:0}},[4,new Promise((function(e,t){he(l,(function(){d({isInitialized:!0,chatbotConfig:l}),e()}),(function(e){t(e)}))}))];case 3:return m.sent(),[3,6];case 4:return s=m.sent(),v=s instanceof Error?s.message:"Failed to initialize chatbot",d({error:v}),W.trackError(s instanceof Error?s:new Error(v),"useChatbotState",{errorCode:K,errorType:ee,context:{timestamp:Date.now()}}),[3,6];case 5:return d({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[t.api_key,t.user_id,t.user_token]);o((function(){t.api_key&&v()}),[v]),o((function(){a.chatbotConfig&&s((function(e){return h(h({},e),{chatbotConfig:h(h({},e.chatbotConfig),{userProfile:h(h({},H()),c)})})}))}),[c]);var b=r((function(){s((function(e){return h(h({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),y=r((function(){d({isIframeVisible:!1})}),[]);return h(h({},a),{toggleIframeVisibility:b,closeIframe:y})},me=function(e){var t=e.api_key,n=e.chatbotConfig,i=e.user_profile,o=e.onEvent,a=l((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]),s=l((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 g(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,l,c,d,u;return void 0===n&&(n={}),m(this,(function(p){switch(p.label){case 0:if(!t)return[2];p.label=1;case 1:return p.trys.push([1,3,,4]),i=x().apiUrl,o=H(),r=h({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:s},n),l={org_id:t,event_data:r,metadata:h({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(l)})];case 2:if(!(c=p.sent()).ok)throw new Error("Failed to send internal event: ".concat(c.statusText));return[3,4];case 3:return d=p.sent(),y.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!==w.CHATBOT_BUTTON_CLICKED&&e!==w.CHATBOT_CLOSED&&e!==w.CHATBOT_OPENED&&e!==w.CHATBOT_READY||(o&&o({type:e,timestamp:n,data:t}),c(e,{timestamp:n}))}),[o,c]),onInternalEvent:c}},be=function(t){var n,r,a,l,s,c,d,u=t.children,p=t.config,f=t.position,v=t.sideSpacing,g=t.bottomSpacing,m=i(!1),b=m[0],_=m[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;_(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]);var w=f||(null===(a=p.interface_properties)||void 0===a?void 0:a.position)||"Right",E=null!==(s=null!=v?v:null===(l=p.interface_properties)||void 0===l?void 0:l.side_spacing)&&void 0!==s?s:20,I=null!==(d=null!=g?g:null===(c=p.interface_properties)||void 0===c?void 0:c.bottom_spacing)&&void 0!==d?d:20;y.log("config",p,w,E);var x={position:"fixed",zIndex:1e3,display:"flex",flexDirection:"column"},T=h(h({},x),((n={bottom:"".concat(I,"px")})[w.toLowerCase()]="".concat(null!=E?E:20,"px"),n.alignItems="Right"===w?"flex-end":"flex-start",n.top=void 0,n["Right"===w?"left":"right"]=void 0,n)),C=h(h({},x),((r={top:0})[w.toLowerCase()]="".concat(null!=E?E:20,"px"),r.alignItems="center",r.bottom=void 0,r["Right"===w?"left":"right"]=void 0,r)),S=b?C:T;return o((function(){console.log("Container screen width changed, isMobile:",b,"Style:",S)}),[b,S]),e.createElement("div",{className:"robylon-chatbot-container",style:S},u)},ye=s((function(t,n){var a,s,d,u=t.api_key,p=t.user_id,f=t.user_token,v=t.user_profile,g=t.onEvent,m=t.position,b=t.sideSpacing,_=t.bottomSpacing;t.show_launcher;var E=t.launcher_type,I=t.launcher_properties_text,x="string"==typeof b?""===b||isNaN(Number(b))?void 0:Number(b):b,T="string"==typeof _?""===_||isNaN(Number(_))?void 0:Number(_):_,C="string"==typeof m?"left"===m.toLowerCase()?"Left":"right"===m.toLowerCase()?"Right":void 0:m;o((function(){}));var S=l((function(){return{api_key:u,user_id:p,user_token:f,user_profile:v}}),[u,p,f,v]),A=r((function(e){null==g||g(e)}),[g]),O=ge(S),R=O.isInitialized,D=O.error,k=O.chatbotConfig,N=O.isIframeVisible,z=O.toggleIframeVisibility,M=O.closeIframe,H=l((function(){return{api_key:u,user_profile:S.user_profile,onEvent:A,chatbotConfig:k?{isAnonymous:k.isAnonymous,userId:k.userId}:null}}),[u,S.user_profile,A,null==k?void 0:k.isAnonymous,null==k?void 0:k.userId]),B=me(h({},H)),j=B.emitEvent,F=B.onInternalEvent;c(n,(function(){return{show:function(){R&&k?N||(z(),j(w.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot show - chatbot not ready yet")},hide:function(){R&&k?N&&(M(),j(w.CHATBOT_CLOSED)):console.warn("Robylon Chatbot: Cannot hide - chatbot not ready yet")},toggle:function(){R&&k?(z(),j(N?w.CHATBOT_CLOSED:w.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot toggle - chatbot not ready yet")},isReady:R&&!!k}}),[R,k,N,z,M,j]),o((function(){R&&k&&j(w.CHATBOT_READY)}),[R,k,j]);var U=i(!1),V=U[0],G=U[1];o((function(){var e,t,n,i,o,r;if(!(!0===(null==k?void 0:k.show_launcher)))return G(!1),function(){r&&clearTimeout(r)};var a=!0===(null===(e=null==k?void 0:k.launcher_delay)||void 0===e?void 0:e.enabled),l=null!==(o=null!==(n=null===(t=null==k?void 0:k.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==k?void 0:k.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0;return a&&Number(l)>0?(G(!1),r=window.setTimeout((function(){G(!0)}),1e3*Number(l))):G(!0),function(){r&&clearTimeout(r)}}),[null==k?void 0:k.show_launcher,null===(a=null==k?void 0:k.launcher_delay)||void 0===a?void 0:a.enabled,null===(s=null==k?void 0:k.launcher_delay)||void 0===s?void 0:s.seconds,null===(d=null==k?void 0:k.launcher_delay)||void 0===d?void 0:d.delay]),o((function(){if(u)try{W.initialize(u,p)}catch(e){W.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:J,errorType:ee,context:{timestamp:Date.now()}})}else W.trackError(new Error(oe[P](u)),"RobylonChatbot",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}})}),[u,p]);var K=r((function(){M(),j(w.CHATBOT_CLOSED)}),[M,j]),Z=r((function(){z(),j(N?w.CHATBOT_CLOSED:w.CHATBOT_BUTTON_CLICKED)}),[z,j,N]),Y=l((function(){var e,t,n,i,o;return{config:k,toggleIframe:Z,isIframeVisible:N,onEvent:A,onInternalEvent:F,position:C,sideSpacing:x,bottomSpacing:T,launcher_type:E,launcher_properties_text:I,shouldFadeIn:!0===(null===(e=null==k?void 0:k.launcher_delay)||void 0===e?void 0:e.enabled)&&(null!==(o=null!==(n=null===(t=null==k?void 0:k.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==k?void 0:k.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0)>0||!1}}),[k,Z,N,A,F,C,x,T,E,I]);y.log("floatingButtonProps",Y);var Q=l((function(){return{config:k,isVisible:N,onClose:K,onEvent:A,onInternalEvent:F,position:C,bottomSpacing:T}}),[k,N,K,A,F,C,T]);return u&&!D&&k?e.createElement(ae,{componentName:"RobylonChatbot"},R?e.createElement(be,{config:k,position:C,sideSpacing:x,bottomSpacing:T},e.createElement(ae,{componentName:"ChatbotIframe"},e.createElement(re,h({},Q))),e.createElement(ae,{componentName:"ChatbotFloatingButton"},V?e.createElement(L,h({},Y)):null)):null):null})),_e=t(ye,(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)&&e.position===t.position&&e.sideSpacing===t.sideSpacing&&e.bottomSpacing===t.bottomSpacing&&e.show_launcher===t.show_launcher&&e.launcher_type===t.launcher_type&&e.launcher_properties_text===t.launcher_properties_text&&!0})),we=function(e){var t=i({isLoading:!0,isInitialized:!1,error:null}),n=t[0],r=t[1],a=function(e){r((function(t){return h(h({},t),{isInitialized:e})}))},l=function(e){r((function(t){return h(h({},t),{error:e})}))};return o((function(){!function(){try{he(e,a,l)}catch(e){r((function(t){return h(h({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),n},Ee=function(){function e(e){var t=this;this.resizeObserver=null,this.proactiveElement=null,this.config=e,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount();try{this.buttonElement.style.opacity="0",this.buttonElement.style.transition="transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",requestAnimationFrame((function(){t.buttonElement.style.opacity="1"}))}catch(e){}this.setupResizeListener(),this.renderProactiveIfNeeded()}return e.prototype.render=function(){var e=this;x().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:C};n.launcher_type===f.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()},this.renderProactiveIfNeeded()},e.prototype.createLauncherElement=function(){var e,t,n=this.config,i=n.config,o=n.isIframeVisible,r=x().copilotUrl;switch(console.log("config in floating button",i),i.launcher_type){case f.TEXT:return this.createTextLauncher();case f.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case f.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 l=document.createElement("img");return l.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"),l.alt="Chat",Object.assign(l.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),l}},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:b(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:S,fontFamily:C,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=x().copilotUrl,l=this.config.config,s=l.brand_colour,c=l.launcher_properties,d=l.image_url,u=document.createElement("div");Object.assign(u.style,{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:s,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:b(s),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:S,fontFamily:C,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),f.textContent=(null==c?void 0:c.text)||"";var v=document.createElement("div");Object.assign(v.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var h=document.createElement("img");return h.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"),h.alt="Chat",Object.assign(h.style,{width:"100%",height:"100%",objectFit:"cover"}),p.appendChild(f),v.appendChild(h),u.appendChild(p),u.appendChild(v),u},e.prototype.applyResponsiveStyles=function(e){var t,n,i,o,r,a,l,s,c,d=(null===window||void 0===window?void 0:window.innerWidth)<560,u=this.config.config,p=this.config.position||(null===(i=u.interface_properties)||void 0===i?void 0:i.position)||"Right",f=null!==(a=null!==(o=this.config.sideSpacing)&&void 0!==o?o:null===(r=u.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==a?a:20,v=null!==(c=null!==(l=this.config.bottomSpacing)&&void 0!==l?l:null===(s=u.interface_properties)||void 0===s?void 0:s.bottom_spacing)&&void 0!==c?c:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var g=h(h({},e),d?((t={position:"fixed",bottom:"".concat(v,"px")})[p.toLowerCase()]="".concat(f,"px"),t):((n={bottom:"".concat(v,"px")})[p.toLowerCase()]="".concat(f,"px"),n));Object.assign(this.buttonElement.style,g)},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!==f.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===f.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:w.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(w.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config.isIframeVisible,this.config=h(h({},this.config),e),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render(),this.renderProactiveIfNeeded()},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),this.proactiveElement&&this.proactiveElement.parentElement&&(this.proactiveElement.parentElement.removeChild(this.proactiveElement),this.proactiveElement=null)},e.prototype.renderProactiveIfNeeded=function(){var e,t,n,i,o,r,a,l,s,c=this,d=null===(t=null===(e=this.config)||void 0===e?void 0:e.config)||void 0===t?void 0:t.proactive_message_obj;if(!(k(d)&&!this.config.isIframeVisible))return this.proactiveElement&&this.proactiveElement.parentElement&&this.proactiveElement.parentElement.removeChild(this.proactiveElement),void(this.proactiveElement=null);if(!this.proactiveElement){var u=document.createElement("div");u.style.position="fixed";var p=null!==(o=null!==(n=this.config.bottomSpacing)&&void 0!==n?n:null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==o?o:20,v=null!==(l=null!==(r=this.config.sideSpacing)&&void 0!==r?r:null===(a=this.config.config.interface_properties)||void 0===a?void 0:a.side_spacing)&&void 0!==l?l:20,h=this.config.position||(null===(s=this.config.config.interface_properties)||void 0===s?void 0:s.position)||"Right";u.style.bottom="".concat(p+(this.config.config.launcher_type===f.IMAGE?48:40)+8,"px"),"Right"===h?u.style.right="".concat(v,"px"):u.style.left="".concat(v,"px"),u.style.maxWidth="22.875rem",u.style.zIndex="2147483646";var g=document.createElement("div");g.style.background="#fff",g.style.color="#111",g.style.borderRadius="16px",g.style.boxShadow="0 0 40px 0 rgba(14, 14, 15, 0.24)",g.style.padding="16px",g.style.cursor="pointer",g.style.fontFamily=C,g.style.fontSize="14px",g.style.lineHeight=String(S),g.textContent=(null==d?void 0:d.content)||"",g.onclick=function(){c.config.toggleIframe(),O()};var m=document.createElement("div");m.style.position="absolute",m.style.top="-32px",m.style.width="24px",m.style.height="24px",m.style.borderRadius="50%",m.style.background="#fff",m.style.boxShadow="0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",m.style.display="flex",m.style.alignItems="center",m.style.justifyContent="center",m.style.cursor="pointer","Right"===h?(m.style.right="0px",m.style.left="auto"):(m.style.left="0px",m.style.right="auto"),m.onclick=function(e){e.stopPropagation(),O(),c.proactiveElement&&c.proactiveElement.parentElement&&c.proactiveElement.parentElement.removeChild(c.proactiveElement),c.proactiveElement=null},m.innerHTML='\n <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none">\n <path d="M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334" stroke="#444547" stroke-width="0.816326" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n ',u.appendChild(g),u.appendChild(m),document.body.appendChild(u),this.proactiveElement=u}},e}(),Ie=function(){function e(e){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(e){var n,i,o,r,a,l,s,c,d,u,p,f,v,h,g,m=x().copilotUrl;if(e.origin===m){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(E.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:w.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(w.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=e.data)||void 0===a?void 0:a.type)&&(null===(s=(l=t.config).onEvent)||void 0===s||s.call(l,{type:w.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(w.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:w.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(w.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===(h=(v=t.config).onEvent)||void 0===h||h.call(v,{type:w.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(w.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=e.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(E.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=this.config.position||(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,r;if(this.iframeElement){var a=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",l=null!==(r=null!==(i=this.config.bottomSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.bottom_spacing)&&void 0!==r?r:20;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(l,"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=x().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(){W.trackError(new Error(oe[X]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:X,errorType:ne,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,l,s,c,d=this;this.config.isVisible=e;var u=this.config.position||(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=x().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===(l=this.config.config)||void 0===l?void 0:l.isAnonymous}},f),this.hasRegistered=!0),null===(c=(s=this.config).onEvent)||void 0===c||c.call(s,{type:w.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(w.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=h(h({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=x().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}(),xe=function(){function e(e,t,n,i){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config={config:e,position:t,sideSpacing:n,bottomSpacing:i},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,l,s,c=(null===window||void 0===window?void 0:window.innerWidth)<560,d=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",u=null!==(r=null!==(i=this.config.sideSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.side_spacing)&&void 0!==r?r:20,p=null!==(s=null!==(a=this.config.bottomSpacing)&&void 0!==a?a:null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==s?s: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 f={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},v=h(h({},f),((e={bottom:"".concat(p,"px")})[d.toLowerCase()]="".concat(u,"px"),e.alignItems="Right"===d?"flex-end":"flex-start",e)),g=h(h({},f),((t={top:"0"})[d.toLowerCase()]="".concat(u,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,c?g:v)},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}(),Te=function(e,t,n){return g(void 0,void 0,void 0,(function(){var i,o,r,a,l,s,c,d;return m(this,(function(u){switch(u.label){case 0:return u.trys.push([0,5,,6]),i=x().apiUrl,o="".concat(i,"/chat/chatbot/get/"),y.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{},launcher_info:se()},[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 l=u.sent(),new Error(oe[Z](a.status,l));case 3:return[4,a.json()];case 4:if(s=u.sent(),!(null===(d=null==s?void 0:s.user)||void 0===d?void 0:d.org_info))throw new Error(oe[Q](["user","org_info"]));return[2,s];case 5:throw c=u.sent(),W.trackError(c instanceof Error?c:new Error(oe[Y]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?Z:Y,errorType:te,context:{apiKey:e,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},Ce=function(e){return g(void 0,void 0,void 0,(function(){var t,n,i,o,r,a,l,s,c,d,v,g,b,y,_,w,E,I,x,T,C,S,A,O,R,D,k,L,N,z,M,B,j,F;return m(this,(function(m){switch(m.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=ue("rblyn_anon")||de(),pe("rblyn_anon",n,365),i=!0),[4,Te(t.api_key,n,t.user_token)];case 1:return o=m.sent(),r=H(),a=se(),U=t.user_profile,l=U?Object.fromEntries(Object.entries(U).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},s=h(h(h({},r),{__INT_SYS_INFO__:h(h({},r),a)}),l),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",show_launcher:null===(d=null===(c=o.user.org_info)||void 0===c?void 0:c.show_launcher)||void 0===d||d,brand_colour:(null===(g=null===(v=o.user.org_info.brand_config)||void 0===v?void 0:v.colors)||void 0===g?void 0:g.brand_color)||"",image_url:(null===(y=null===(b=o.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===y?void 0:y.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(_=o.user.org_info.brand_config)||void 0===_?void 0:_.display_name)||"",welcome_message:(null===(w=o.user.org_info.brand_config)||void 0===w?void 0:w.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(E=o.user.org_info.brand_config)||void 0===E?void 0:E.redirect_url)||""},launcher_type:(null===(I=o.user.org_info.brand_config)||void 0===I?void 0:I.launcher_type)||f.IMAGE,launcher_properties:{text:(null===(T=null===(x=o.user.org_info.brand_config)||void 0===x?void 0:x.launcher_properties)||void 0===T?void 0:T.text)||""},images:{launcher_image_url:{url:(null===(A=null===(S=null===(C=o.user.org_info.brand_config)||void 0===C?void 0:C.images)||void 0===S?void 0:S.launcher_image_url)||void 0===A?void 0:A.url)||""}},proactive_message_obj:(null===(D=null===(R=null===(O=null==o?void 0:o.user)||void 0===O?void 0:O.org_info)||void 0===R?void 0:R.brand_config)||void 0===D?void 0:D.proactive_message_obj)||void 0,interface_properties:{position:(null===(L=null===(k=o.user.org_info.brand_config)||void 0===k?void 0:k.interface_properties)||void 0===L?void 0:L.position)||p.RIGHT,side_spacing:(null===(z=null===(N=o.user.org_info.brand_config)||void 0===N?void 0:N.interface_properties)||void 0===z?void 0:z.side_spacing)||20,bottom_spacing:(null===(B=null===(M=o.user.org_info.brand_config)||void 0===M?void 0:M.interface_properties)||void 0===B?void 0:B.bottom_spacing)||20},interface_type:(null===(j=o.user.org_info.brand_config)||void 0===j?void 0:j.interface_type)||u.WIDGET,launcher_delay:(null===(F=o.user.org_info.brand_config)||void 0===F?void 0:F.launcher_delay)||{enabled:!1,delay:0}}]}var U}))}))},Se=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){}}},Ae=function(){function e(e){var t=this;this.container=null,this.floatingButton=null,this.launcherDelayTimeout=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){var n,i,o,r,a;if(!t.isDestroyed){var l=e.isInitialized,s=e.error,c=e.chatbotConfig,d=e.isIframeVisible;if(!s&&c&&l){if(t.eventEmitter=Se({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:c.isAnonymous,userId:c.userId}}),t.container||(t.container=new xe(c,t.config.position,t.config.sideSpacing,t.config.bottomSpacing)),t.iframe)t.iframe.update({config:c,isVisible:d,position:t.config.position,bottomSpacing:t.config.bottomSpacing});else if(t.iframe=new Ie({config:c,isVisible:d,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,bottomSpacing:t.config.bottomSpacing}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var u=t.iframe.getElement();u&&t.container&&t.container.getElement().prepend(u)}var p=!0===(null==c?void 0:c.show_launcher),f=!0===(null===(n=null==c?void 0:c.launcher_delay)||void 0===n?void 0:n.enabled),v=null!==(a=null!==(o=null===(i=null==c?void 0:c.launcher_delay)||void 0===i?void 0:i.seconds)&&void 0!==o?o:null===(r=null==c?void 0:c.launcher_delay)||void 0===r?void 0:r.delay)&&void 0!==a?a:0,h=function(){if(t.floatingButton)t.floatingButton.update({config:c,isIframeVisible:d,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing});else if(t.floatingButton=new Ee({config:c,toggleIframe:t.toggleIframe,isIframeVisible:d,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var e=t.floatingButton.getElement();e&&t.container&&t.container.getElement().appendChild(e)}};t.launcherDelayTimeout&&(clearTimeout(t.launcherDelayTimeout),t.launcherDelayTimeout=null),p?f&&Number(v)>0&&!t.floatingButton?t.launcherDelayTimeout=window.setTimeout((function(){h(),t.launcherDelayTimeout=null}),1e3*Number(v)):h():t.floatingButton&&(t.floatingButton.destroy(),t.floatingButton=null)}}},this.toggleIframe=function(){var e=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(e.isIframeVisible?w.CHATBOT_CLOSED:w.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(w.CHATBOT_CLOSED)};var n,i,o,r,a=h(h({},e),{position:"string"==typeof e.position?"left"===e.position.toLowerCase()?"Left":"right"===e.position.toLowerCase()?"Right":void 0:void 0,sideSpacing:"string"==typeof e.sideSpacing?""===e.sideSpacing||isNaN(Number(e.sideSpacing))?void 0:Number(e.sideSpacing):e.sideSpacing,bottomSpacing:"string"==typeof e.bottomSpacing?""===e.bottomSpacing||isNaN(Number(e.bottomSpacing))?void 0:Number(e.bottomSpacing):e.bottomSpacing});if(this.config=a,!e.api_key)throw W.trackError(new Error(oe[P](e.api_key)),"RobylonChatbot",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}}),new Error("API key is required");try{W.initialize(e.api_key,e.user_id)}catch(e){W.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:J,errorType:ee,context:{timestamp:Date.now()}})}this.stateManager=(n={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},i={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},o=[],{getState:function(){return i},initialize:function(){return g(void 0,void 0,void 0,(function(){var e,t,i;return m(this,(function(o){switch(o.label){case 0:if(!n.api_key)return W.trackError(new Error(oe[P](n.api_key)),"ChatbotStateManager",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}}),[2];r({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,Ce(n)];case 2:return e=o.sent(),[4,new Promise((function(t,n){he(e,(function(){r({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return o.sent(),[3,6];case 4:return t=o.sent(),i=t instanceof Error?t.message:"Failed to initialize chatbot",r({error:i}),W.trackError(t instanceof Error?t:new Error(i),"ChatbotStateManager",{errorCode:K,errorType:ee,context:{timestamp:Date.now()}}),[3,6];case 5:return r({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){r({isIframeVisible:!i.isIframeVisible})},closeIframe:function(){r({isIframeVisible:!1})},updateState:r=function(e){i=h(h({},i),e),o.forEach((function(e){return e(i)}))},subscribe:function(e){return o.push(e),function(){var t=o.indexOf(e);t>-1&&o.splice(t,1)}},unsubscribe:function(e){var t=o.indexOf(e);t>-1&&o.splice(t,1)}}),this.eventEmitter=Se({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),window.RobylonShouldShowProactive=k,window.RobylonHideProactive=O,this.initialize()}return e.prototype.initialize=function(){return g(this,void 0,void 0,(function(){var e;return m(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(),W.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:K,errorType:ee,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(w.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(w.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.launcherDelayTimeout&&(clearTimeout(this.launcherDelayTimeout),this.launcherDelayTimeout=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 Oe(e){return new Ae(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=Oe(i)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(e){var n=Array.prototype.slice.call(arguments,1);return"init"===e?t=Oe(n[0]||{}):t&&"function"==typeof t[e]?t[e].apply(t,n):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var Re={create:Oe,getState:function(){return"initialized"}};export{_e as Chatbot,u as ChatbotInterfaceType,f as LauncherType,v as ProactiveSendTimeType,Re as RobylonChatbot,p as WidgetPositionEnums,we 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 l,forwardRef as s,useImperativeHandle as c}from"react";var d=function(e,t){return d=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])},d(e,t)};var u,p,f,v,h=function(){return h=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},h.apply(this,arguments)};function g(e,t,n,i){return new(n||(n=Promise))((function(o,r){function a(e){try{s(i.next(e))}catch(e){r(e)}}function l(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}s((i=i.apply(e,t||[])).next())}))}function m(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=l(0),a.throw=l(1),a.return=l(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function l(l){return function(s){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,l[0]&&(r=0)),r;)try{if(n=1,i&&(o=2&l[0]?i.return:l[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,l[1])).done)return o;switch(i=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return r.label++,{value:l[1],done:!1};case 5:r.label++,i=l[1],l=[0];continue;case 7:l=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){r=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){r.label=l[1];break}if(6===l[0]&&r.label<o[1]){r.label=o[1],o=l;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(l);break}o[2]&&r.ops.pop(),r.trys.pop();continue}l=t.call(e,r)}catch(e){l=[6,e],i=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,s])}}}"function"==typeof SuppressedError&&SuppressedError,function(e){e.WIDGET="WIDGET",e.POPOVER="POPOVER",e.EMBED="EMBED"}(u||(u={})),function(e){e.RIGHT="Right",e.LEFT="Left"}(p||(p={})),function(e){e.TEXT="TEXT",e.IMAGE="IMAGE",e.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(f||(f={})),function(e){e.WORKING_HOURS="WORKING_HOURS",e.ALWAYS="ALWAYS"}(v||(v={}));var b=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"},y={log:function(){},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(){}};y.log("Raw API_URL:","https://stage-api.robylon.ai");var _={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};y.log("CONFIG",_);var w,E,I=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},x=function(){return{copilotUrl:_.copilotUrl||"https://app.robylon.ai",environment:_.environment||"production",apiUrl:_.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",e.CHATBOT_READY="CHATBOT_READY"}(w||(w={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(E||(E={}));var T,C="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",S="21px",A=!1,O=function(){A=!0};console.log("isProactiveHiddenThisPage",(function(){return A}));var R,D=((T={})[v.WORKING_HOURS]=function(e,t){var n=t.getHours(),i=t.getMinutes();return(n>10||10===n&&i>=0)&&(n<19||19===n&&0===i)},T[v.ALWAYS]=function(e,t){return!0},T),k=function(e,t){var n;if(void 0===t&&(t=new Date),console.log("proactiveHiddenThisPage shouldShowProactiveMessage",A),!(null===(n=null==e?void 0:e.content)||void 0===n?void 0:n.trim()))return!1;if(A)return!1;var i=(null==e?void 0:e.send_time_type)||"";if(!i)return!0;var o=D[i];return!!o&&o(e,t)},L=t((function(t){var r,a,l,s,c,d,u,p,v,g,m,_,E,I,T,A,O,R,D,L=t.config,N=t.toggleIframe,z=t.isIframeVisible,M=t.onEvent,H=t.onInternalEvent,B=t.position,j=t.sideSpacing,F=t.bottomSpacing,U=t.launcher_type,W=t.launcher_properties_text,P=t.shouldFadeIn,V=n(null),G=x().copilotUrl,K=i(!1),J=K[0],Z=K[1],Y=i(!1),Q=Y[0],X=Y[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;Z(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]),o((function(){V.current&&requestAnimationFrame((function(){null==M||M({type:w.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),H(w.CHATBOT_BUTTON_LOADED)}))}),[M,H]),o((function(){if(V.current&&P){V.current.style.opacity="0";var e=requestAnimationFrame((function(){V.current&&(V.current.style.opacity="1")}));return function(){return cancelAnimationFrame(e)}}}),[P]);var q=B||(null===(l=L.interface_properties)||void 0===l?void 0:l.position)||"Right",$=null!==(c=null!=j?j:null===(s=L.interface_properties)||void 0===s?void 0:s.side_spacing)&&void 0!==c?c:20,ee=null!==(u=null!=F?F:null===(d=L.interface_properties)||void 0===d?void 0:d.bottom_spacing)&&void 0!==u?u:20,te=U||(null==L?void 0:L.launcher_type)||f.IMAGE,ne=W||(null===(p=null==L?void 0:L.launcher_properties)||void 0===p?void 0:p.text),ie={zIndex:1e3,display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",boxSizing:"border-box"};te===f.IMAGE&&(ie.width="48px",ie.height="48px",ie.borderRadius="50%",ie.backgroundColor=L.brand_colour);var oe=h(h({},ie),((r={position:void 0,bottom:"0",borderRadius:te===f.IMAGE?"50%":"9999px"})[q.toLowerCase()]="0",r)),re=h(h({},ie),((a={position:"fixed",bottom:"".concat(ee,"px"),borderRadius:te===f.IMAGE?"50%":"9999px"})[q.toLowerCase()]="".concat($,"px"),a)),ae=J?re:oe;o((function(){y.log("Screen width changed, isMobile:",J,"Style:",ae)}),[J,ae]),y.log("config in floating button",L);var le=k(null==L?void 0:L.proactive_message_obj)&&!z&&!Q;return e.createElement(e.Fragment,null,le?e.createElement("div",{className:"proactive-message-container",style:{position:"fixed",bottom:"".concat((null!==(g=null!=F?F:null===(v=L.interface_properties)||void 0===v?void 0:v.bottom_spacing)&&void 0!==g?g:20)+(te===f.IMAGE?48:40)+8,"px"),right:"Right"===(B||(null===(m=L.interface_properties)||void 0===m?void 0:m.position)||"Right")?"".concat(null!==(E=null!=j?j:null===(_=L.interface_properties)||void 0===_?void 0:_.side_spacing)&&void 0!==E?E:20,"px"):"auto",left:"Left"===(B||(null===(I=L.interface_properties)||void 0===I?void 0:I.position)||"Right")?"".concat(null!==(A=null!=j?j:null===(T=L.interface_properties)||void 0===T?void 0:T.side_spacing)&&void 0!==A?A:20,"px"):"auto",maxWidth:"22.875rem",zIndex:2147483646}},e.createElement("div",{onClick:function(){N(),X(!0)},style:{background:"#fff",color:"#111",borderRadius:"12px",boxShadow:"0 0 40px 0 rgba(14, 14, 15, 0.24)",padding:"16px",cursor:"pointer",fontFamily:C,lineHeight:S,fontSize:"14px"}},null===(O=null==L?void 0:L.proactive_message_obj)||void 0===O?void 0:O.content),e.createElement("div",{onClick:function(e){e.stopPropagation(),X(!0),console.log("Clicked close")},style:{position:"absolute",top:"-32px",right:"Right"===(B||(null===(R=L.interface_properties)||void 0===R?void 0:R.position)||"Right")?"0px":"auto",left:"Left"===(B||(null===(D=L.interface_properties)||void 0===D?void 0:D.position)||"Right")?"0px":"auto",width:"24px",height:"24px",borderRadius:"50%",background:"#fff",boxShadow:" 0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",userSelect:"none"},"aria-label":"Close proactive message"},e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 14 14",fill:"none"},e.createElement("path",{d:"M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334",stroke:"#444547",strokeWidth:"0.816326",strokeLinecap:"round",strokeLinejoin:"round"})))):null,e.createElement("div",{ref:V,className:"message-bubble-container",style:h(h({},ae),{transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",transform:z?"scale(0.85)":"scale(1)",opacity:P?0:1}),onClick:N},function(){switch(te){case f.TEXT:return e.createElement("div",{style:{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:L.brand_colour,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box",fontFamily:C,lineHeight:S}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:b(L.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:C,lineHeight:S,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},ne)));case f.TEXTUAL_IMAGE:return function(){var t,n;return e.createElement("div",{style:{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:L.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:C,lineHeight:S}},e.createElement("div",{style:{flex:1,minWidth:0}},e.createElement("p",{style:{margin:0,color:b(L.brand_colour),fontSize:"0.875rem",fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",fontFamily:C,lineHeight:S,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}},ne)),e.createElement("div",{style:{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:0}},e.createElement("img",{src:(null==L?void 0:L.launcher_type)?(null===(n=null===(t=null==L?void 0:L.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(G,"/chatbubble.png"):(null==L?void 0:L.image_url)||"".concat(G,"/chatbubble.png"),alt:"Chat",style:{width:"100%",height:"100%",objectFit:"cover"}})))}();case f.IMAGE:default:return function(){var t,n;return z?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==L?void 0:L.launcher_type)?(null===(n=null===(t=null==L?void 0:L.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(G,"/chatbubble.png"):(null==L?void 0:L.image_url)||"".concat(G,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}})}()}}()))})),N=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]},z=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]},M=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)}},H=function(){return{platform:"web",os:N(),browser:z(),sdk_version:"1.1.40-staging.6",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:M()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(R||(R={}));var B,j=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],F=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&j.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))}))},U=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};F(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)};F(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){I()&&(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(){I()&&(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:H(),event_type:R.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){y.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 g(this,void 0,void 0,(function(){var e,t,n;return m(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];y.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,h(h({},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 g(this,void 0,void 0,(function(){var t,n,i,o,r,a;return m(this,(function(l){switch(l.label){case 0:return l.trys.push([0,4,,5]),t=x().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=l.sent()).ok?[3,3]:(o=(i=y).error,r=["Failed to send error log:"],[4,n.text()]);case 2:o.apply(i,r.concat([l.sent()])),l.label=3;case 3:return[3,5];case 4:return a=l.sent(),y.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return g(this,void 0,void 0,(function(){var i,o,r;return m(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:h(h({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:H(),event_type:R.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}),y.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:h(h({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:H(),event_type:R.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return g(this,void 0,void 0,(function(){var i,o;return m(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:H(),event_type:R.INFO,user_id:this.userId},[4,this.sendLog(o)]):(y.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),W=U.getInstance(),P="MISSING_API_KEY",V="INVALID_API_KEY",G="CONFIG_FETCH_FAILED",K="SDK_INIT_FAILED",J="ERROR_TRACKING_INIT_FAILED",Z="API_REQUEST_FAILED",Y="NETWORK_ERROR",Q="INVALID_RESPONSE",X="IFRAME_LOAD_FAILED",q="COOKIE_ACCESS_ERROR",$="COMPONENT_RENDER_ERROR",ee="INITIALIZATION_ERROR",te="API_ERROR",ne="RUNTIME_ERROR",ie="COMPONENT_ERROR",oe=((B={})[P]=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.")},B[V]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},B[G]=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):"")},B[Z]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},B[Y]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},B[X]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},B[Q]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},B[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):"")},B[K]=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)):"")},B[q]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},B[$]=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):"")},B),re=t((function(t){var i,a,l,s,c=t.config,d=t.isVisible,u=t.onClose,p=t.onEvent,f=t.onInternalEvent,v=t.position,h=t.bottomSpacing,g=n(null),m=n(!1),b=n(!1),y=v||(null===(i=c.interface_properties)||void 0===i?void 0:i.position)||"Right",_=null!==(l=null!=h?h:null===(a=c.interface_properties)||void 0===a?void 0:a.bottom_spacing)&&void 0!==l?l:20,I=r((function(){var e,t=g.current;if(t){var n=((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(_,"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)"})[y.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(t.style,n)}}),[_,y]);return o((function(){var e=g.current;if(e&&!m.current){var t=x().copilotUrl;Object.assign(e.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(y.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"}),e.src="".concat(t,"/chatbot-plugin?id=").concat(c.chatbotId),m.current=!0,I();var n=function(){var n,i,o=new URL(e.src).origin||t;null===(n=e.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)};return e.addEventListener("load",n),function(){return e.removeEventListener("load",n)}}}),[c.chatbotId,null===(s=c.interface_properties)||void 0===s?void 0:s.position,I]),o((function(){var e,t,n,i,o,r=g.current;if(r&&m.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 l=x().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"},l),(null==b?void 0:b.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}},l),b.current=!0)}}}),[d,c.userId,c.token,c.userProfile]),o((function(){if(g.current&&m.current){var e=x().copilotUrl;d&&(null==p||p({type:w.CHATBOT_OPENED,timestamp:Date.now()}),f(w.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,l,s;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(E.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==p||p({type:w.CHATBOT_LOADED,timestamp:Date.now()}),f(w.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==p||p({type:w.CHAT_INITIALIZED,timestamp:Date.now()}),f(w.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==p||p({type:w.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),f(w.CHAT_INITIALIZATION_FAILED,{error:null===(a=t.data)||void 0===a?void 0:a.error})),"SESSION_REFRESHED"===(null===(l=t.data)||void 0===l?void 0:l.type)&&(null==p||p({type:w.SESSION_REFRESHED,timestamp:Date.now()}),f(w.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(s=t.data)||void 0===s?void 0:s.type)&&f(E.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=g.current;if(e&&m.current){var t=function(){W.trackError(new Error(oe[X]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:X,errorType:ne,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(g.current&&c&&d){var t=g.current,n=x().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:c.userProfile},n)}}),[c.userProfile,d]),e.createElement("iframe",{ref:g,id:"chat-iframe-rbyln",style:{display:"none"}})})),ae=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}d(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){W.trackError(new Error(oe[$]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:$,errorType:ie,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(a),le=function(){var e,t=navigator.userAgent;if(null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands){var n=navigator.userAgentData.brands.find((function(e){return"Google Chrome"===e.brand}));if(null==n?void 0:n.version)return n.version}var i=t.match(/(Chrome|Firefox|Safari|Edge|Opera)\/(\d+\.\d+)/);return i?i[2]:"Unknown"},se=function(){var e,t,n=H();return{current_page_url:(null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.href)||"",browser_language:(null===navigator||void 0===navigator?void 0:navigator.language)||(null===(t=null===navigator||void 0===navigator?void 0:navigator.languages)||void 0===t?void 0:t[0])||"en",browser_version:le(),os:null==n?void 0:n.os,referral_url:(null===document||void 0===document?void 0:document.referrer)||""}},ce=function(e,t,n){return g(void 0,void 0,void 0,(function(){var i,o,r,a,l,s,c,d;return m(this,(function(u){switch(u.label){case 0:i=x().apiUrl,o="".concat(i,"/chat/chatbot/get/"),y.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{},launcher_info:se()},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 l=u.sent(),new Error(oe[Z](a.status,l));case 4:return[4,a.json()];case 5:if(s=u.sent(),!(null===(d=null==s?void 0:s.user)||void 0===d?void 0:d.org_info))throw new Error(oe[Q](["user","org_info"]));return[2,s];case 6:throw c=u.sent(),W.trackError(c instanceof Error?c:new Error(oe[Y]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?Z:Y,errorType:te,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]}}))}))},de=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)}))},ue=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()},pe=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=/")},fe=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},ve=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 y.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="×",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:b(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;y.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),y.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:fe(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;y.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(y.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;y.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"),y.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}(),he=function(e,t,n){if(e.chatbotId&&e.userId)try{new ve(e);t(!0),y.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},ge=function(e){var t=l((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],s=n[1],c=l((function(){return t.user_profile?Object.fromEntries(Object.entries(t.user_profile).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)]),d=r((function(e){s((function(t){return h(h({},t),e)}))}),[]),v=r((function(){return g(void 0,void 0,void 0,(function(){var e,n,i,o,r,a,l,s,v,g,b,y,_,w,E,I,x,T,C,S,A,O,R,D,k,L,N,z,M,B,j,F,U,V,G,J;return m(this,(function(m){switch(m.label){case 0:if(!t.api_key)return W.trackError(new Error(oe[P](t.api_key)),"useChatbotState",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}}),[2];d({isInitializing:!0}),m.label=1;case 1:return m.trys.push([1,4,5,6]),e=t.user_id||void 0,n=!1,e||(e=ue("rblyn_anon")||de(),pe("rblyn_anon",e,365),n=!0),[4,ce(t.api_key,e,t.user_token)];case 2:return i=m.sent(),o=H(),r=se(),a=h(h(h({},o),{__INT_SYS_INFO__:h(h({},o),r)}),c),l={chatbotId:t.api_key,userId:e,token:t.user_token,isAnonymous:n,domain:"",show_launcher:null===(b=null===(g=i.user.org_info)||void 0===g?void 0:g.show_launcher)||void 0===b||b,brand_colour:(null===(_=null===(y=i.user.org_info.brand_config)||void 0===y?void 0:y.colors)||void 0===_?void 0:_.brand_color)||"",image_url:(null===(E=null===(w=i.user.org_info)||void 0===w?void 0:w.brand_config)||void 0===E?void 0:E.launcher_logo_url)||"",userProfile:a,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(I=i.user.org_info.brand_config)||void 0===I?void 0:I.display_name)||"",welcome_message:(null===(x=i.user.org_info.brand_config)||void 0===x?void 0:x.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(T=i.user.org_info.brand_config)||void 0===T?void 0:T.redirect_url)||""},interface_properties:{position:(null===(S=null===(C=i.user.org_info.brand_config)||void 0===C?void 0:C.interface_properties)||void 0===S?void 0:S.position)||p.RIGHT,side_spacing:null!==(R=null===(O=null===(A=i.user.org_info.brand_config)||void 0===A?void 0:A.interface_properties)||void 0===O?void 0:O.side_spacing)&&void 0!==R?R:20,bottom_spacing:null!==(L=null===(k=null===(D=i.user.org_info.brand_config)||void 0===D?void 0:D.interface_properties)||void 0===k?void 0:k.bottom_spacing)&&void 0!==L?L:20},interface_type:(null===(N=i.user.org_info.brand_config)||void 0===N?void 0:N.interface_type)||u.WIDGET,launcher_type:(null===(z=i.user.org_info.brand_config)||void 0===z?void 0:z.launcher_type)||f.IMAGE,launcher_properties:{text:(null===(B=null===(M=i.user.org_info.brand_config)||void 0===M?void 0:M.launcher_properties)||void 0===B?void 0:B.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)||""}},proactive_message_obj:(null===(V=i.user.org_info.brand_config)||void 0===V?void 0:V.proactive_message_obj)||void 0,launcher_delay:(null===(J=null===(G=i.user.org_info)||void 0===G?void 0:G.brand_config)||void 0===J?void 0:J.launcher_delay)||{enabled:!1,delay:0}},[4,new Promise((function(e,t){he(l,(function(){d({isInitialized:!0,chatbotConfig:l}),e()}),(function(e){t(e)}))}))];case 3:return m.sent(),[3,6];case 4:return s=m.sent(),v=s instanceof Error?s.message:"Failed to initialize chatbot",d({error:v}),W.trackError(s instanceof Error?s:new Error(v),"useChatbotState",{errorCode:K,errorType:ee,context:{timestamp:Date.now()}}),[3,6];case 5:return d({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[t.api_key,t.user_id,t.user_token]);o((function(){t.api_key&&v()}),[v]),o((function(){a.chatbotConfig&&s((function(e){return h(h({},e),{chatbotConfig:h(h({},e.chatbotConfig),{userProfile:h(h({},H()),c)})})}))}),[c]);var b=r((function(){s((function(e){return h(h({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),y=r((function(){d({isIframeVisible:!1})}),[]);return h(h({},a),{toggleIframeVisibility:b,closeIframe:y})},me=function(e){var t=e.api_key,n=e.chatbotConfig,i=e.user_profile,o=e.onEvent,a=l((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]),s=l((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 g(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,l,c,d,u;return void 0===n&&(n={}),m(this,(function(p){switch(p.label){case 0:if(!t)return[2];p.label=1;case 1:return p.trys.push([1,3,,4]),i=x().apiUrl,o=H(),r=h({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:s},n),l={org_id:t,event_data:r,metadata:h({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(l)})];case 2:if(!(c=p.sent()).ok)throw new Error("Failed to send internal event: ".concat(c.statusText));return[3,4];case 3:return d=p.sent(),y.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!==w.CHATBOT_BUTTON_CLICKED&&e!==w.CHATBOT_CLOSED&&e!==w.CHATBOT_OPENED&&e!==w.CHATBOT_READY||(o&&o({type:e,timestamp:n,data:t}),c(e,{timestamp:n}))}),[o,c]),onInternalEvent:c}},be=function(t){var n,r,a,l,s,c,d,u=t.children,p=t.config,f=t.position,v=t.sideSpacing,g=t.bottomSpacing,m=i(!1),b=m[0],_=m[1];o((function(){var e=function(){var e=(null===window||void 0===window?void 0:window.innerWidth)<560;_(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}),[]);var w=f||(null===(a=p.interface_properties)||void 0===a?void 0:a.position)||"Right",E=null!==(s=null!=v?v:null===(l=p.interface_properties)||void 0===l?void 0:l.side_spacing)&&void 0!==s?s:20,I=null!==(d=null!=g?g:null===(c=p.interface_properties)||void 0===c?void 0:c.bottom_spacing)&&void 0!==d?d:20;y.log("config",p,w,E);var x={position:"fixed",zIndex:1e3,display:"flex",flexDirection:"column"},T=h(h({},x),((n={bottom:"".concat(I,"px")})[w.toLowerCase()]="".concat(null!=E?E:20,"px"),n.alignItems="Right"===w?"flex-end":"flex-start",n.top=void 0,n["Right"===w?"left":"right"]=void 0,n)),C=h(h({},x),((r={top:0})[w.toLowerCase()]="".concat(null!=E?E:20,"px"),r.alignItems="center",r.bottom=void 0,r["Right"===w?"left":"right"]=void 0,r)),S=b?C:T;return o((function(){console.log("Container screen width changed, isMobile:",b,"Style:",S)}),[b,S]),e.createElement("div",{className:"robylon-chatbot-container",style:S},u)},ye=s((function(t,n){var a,s,d,u=t.api_key,p=t.user_id,f=t.user_token,v=t.user_profile,g=t.onEvent,m=t.position,b=t.sideSpacing,_=t.bottomSpacing;t.show_launcher;var E=t.launcher_type,I=t.launcher_properties_text,x="string"==typeof b?""===b||isNaN(Number(b))?void 0:Number(b):b,T="string"==typeof _?""===_||isNaN(Number(_))?void 0:Number(_):_,C="string"==typeof m?"left"===m.toLowerCase()?"Left":"right"===m.toLowerCase()?"Right":void 0:m;o((function(){}));var S=l((function(){return{api_key:u,user_id:p,user_token:f,user_profile:v}}),[u,p,f,v]),A=r((function(e){null==g||g(e)}),[g]),O=ge(S),R=O.isInitialized,D=O.error,k=O.chatbotConfig,N=O.isIframeVisible,z=O.toggleIframeVisibility,M=O.closeIframe,H=l((function(){return{api_key:u,user_profile:S.user_profile,onEvent:A,chatbotConfig:k?{isAnonymous:k.isAnonymous,userId:k.userId}:null}}),[u,S.user_profile,A,null==k?void 0:k.isAnonymous,null==k?void 0:k.userId]),B=me(h({},H)),j=B.emitEvent,F=B.onInternalEvent;c(n,(function(){return{show:function(){R&&k?N||(z(),j(w.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot show - chatbot not ready yet")},hide:function(){R&&k?N&&(M(),j(w.CHATBOT_CLOSED)):console.warn("Robylon Chatbot: Cannot hide - chatbot not ready yet")},toggle:function(){R&&k?(z(),j(N?w.CHATBOT_CLOSED:w.CHATBOT_BUTTON_CLICKED)):console.warn("Robylon Chatbot: Cannot toggle - chatbot not ready yet")},isReady:R&&!!k}}),[R,k,N,z,M,j]),o((function(){R&&k&&j(w.CHATBOT_READY)}),[R,k,j]);var U=i(!1),V=U[0],G=U[1];o((function(){var e,t,n,i,o,r;if(!(!0===(null==k?void 0:k.show_launcher)))return G(!1),function(){r&&clearTimeout(r)};var a=!0===(null===(e=null==k?void 0:k.launcher_delay)||void 0===e?void 0:e.enabled),l=null!==(o=null!==(n=null===(t=null==k?void 0:k.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==k?void 0:k.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0;return a&&Number(l)>0?(G(!1),r=window.setTimeout((function(){G(!0)}),1e3*Number(l))):G(!0),function(){r&&clearTimeout(r)}}),[null==k?void 0:k.show_launcher,null===(a=null==k?void 0:k.launcher_delay)||void 0===a?void 0:a.enabled,null===(s=null==k?void 0:k.launcher_delay)||void 0===s?void 0:s.seconds,null===(d=null==k?void 0:k.launcher_delay)||void 0===d?void 0:d.delay]),o((function(){if(u)try{W.initialize(u,p)}catch(e){W.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:J,errorType:ee,context:{timestamp:Date.now()}})}else W.trackError(new Error(oe[P](u)),"RobylonChatbot",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}})}),[u,p]);var K=r((function(){M(),j(w.CHATBOT_CLOSED)}),[M,j]),Z=r((function(){z(),j(N?w.CHATBOT_CLOSED:w.CHATBOT_BUTTON_CLICKED)}),[z,j,N]),Y=l((function(){var e,t,n,i,o;return{config:k,toggleIframe:Z,isIframeVisible:N,onEvent:A,onInternalEvent:F,position:C,sideSpacing:x,bottomSpacing:T,launcher_type:E,launcher_properties_text:I,shouldFadeIn:!0===(null===(e=null==k?void 0:k.launcher_delay)||void 0===e?void 0:e.enabled)&&(null!==(o=null!==(n=null===(t=null==k?void 0:k.launcher_delay)||void 0===t?void 0:t.seconds)&&void 0!==n?n:null===(i=null==k?void 0:k.launcher_delay)||void 0===i?void 0:i.delay)&&void 0!==o?o:0)>0||!1}}),[k,Z,N,A,F,C,x,T,E,I]);y.log("floatingButtonProps",Y);var Q=l((function(){return{config:k,isVisible:N,onClose:K,onEvent:A,onInternalEvent:F,position:C,bottomSpacing:T}}),[k,N,K,A,F,C,T]);return u&&!D&&k?e.createElement(ae,{componentName:"RobylonChatbot"},R?e.createElement(be,{config:k,position:C,sideSpacing:x,bottomSpacing:T},e.createElement(ae,{componentName:"ChatbotIframe"},e.createElement(re,h({},Q))),e.createElement(ae,{componentName:"ChatbotFloatingButton"},V?e.createElement(L,h({},Y)):null)):null):null})),_e=t(ye,(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)&&e.position===t.position&&e.sideSpacing===t.sideSpacing&&e.bottomSpacing===t.bottomSpacing&&e.show_launcher===t.show_launcher&&e.launcher_type===t.launcher_type&&e.launcher_properties_text===t.launcher_properties_text&&!0})),we=function(e){var t=i({isLoading:!0,isInitialized:!1,error:null}),n=t[0],r=t[1],a=function(e){r((function(t){return h(h({},t),{isInitialized:e})}))},l=function(e){r((function(t){return h(h({},t),{error:e})}))};return o((function(){!function(){try{he(e,a,l)}catch(e){r((function(t){return h(h({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),n},Ee=function(){function e(e){var t=this;this.resizeObserver=null,this.proactiveElement=null,this.config=e,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount();try{this.buttonElement.style.opacity="0",this.buttonElement.style.transition="transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",requestAnimationFrame((function(){t.buttonElement.style.opacity="1"}))}catch(e){}this.setupResizeListener(),this.renderProactiveIfNeeded()}return e.prototype.render=function(){var e=this;x().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:C};n.launcher_type===f.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()},this.renderProactiveIfNeeded()},e.prototype.createLauncherElement=function(){var e,t,n=this.config,i=n.config,o=n.isIframeVisible,r=x().copilotUrl;switch(console.log("config in floating button",i),i.launcher_type){case f.TEXT:return this.createTextLauncher();case f.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case f.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 l=document.createElement("img");return l.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"),l.alt="Chat",Object.assign(l.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),l}},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:b(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:S,fontFamily:C,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=x().copilotUrl,l=this.config.config,s=l.brand_colour,c=l.launcher_properties,d=l.image_url,u=document.createElement("div");Object.assign(u.style,{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor:s,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:b(s),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:S,fontFamily:C,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),f.textContent=(null==c?void 0:c.text)||"";var v=document.createElement("div");Object.assign(v.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var h=document.createElement("img");return h.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"),h.alt="Chat",Object.assign(h.style,{width:"100%",height:"100%",objectFit:"cover"}),p.appendChild(f),v.appendChild(h),u.appendChild(p),u.appendChild(v),u},e.prototype.applyResponsiveStyles=function(e){var t,n,i,o,r,a,l,s,c,d=(null===window||void 0===window?void 0:window.innerWidth)<560,u=this.config.config,p=this.config.position||(null===(i=u.interface_properties)||void 0===i?void 0:i.position)||"Right",f=null!==(a=null!==(o=this.config.sideSpacing)&&void 0!==o?o:null===(r=u.interface_properties)||void 0===r?void 0:r.side_spacing)&&void 0!==a?a:20,v=null!==(c=null!==(l=this.config.bottomSpacing)&&void 0!==l?l:null===(s=u.interface_properties)||void 0===s?void 0:s.bottom_spacing)&&void 0!==c?c:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var g=h(h({},e),d?((t={position:"fixed",bottom:"".concat(v,"px")})[p.toLowerCase()]="".concat(f,"px"),t):((n={bottom:"".concat(v,"px")})[p.toLowerCase()]="".concat(f,"px"),n));Object.assign(this.buttonElement.style,g)},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!==f.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===f.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:w.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(w.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config.isIframeVisible,this.config=h(h({},this.config),e),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render(),this.renderProactiveIfNeeded()},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),this.proactiveElement&&this.proactiveElement.parentElement&&(this.proactiveElement.parentElement.removeChild(this.proactiveElement),this.proactiveElement=null)},e.prototype.renderProactiveIfNeeded=function(){var e,t,n,i,o,r,a,l,s,c=this,d=null===(t=null===(e=this.config)||void 0===e?void 0:e.config)||void 0===t?void 0:t.proactive_message_obj;if(!(k(d)&&!this.config.isIframeVisible))return this.proactiveElement&&this.proactiveElement.parentElement&&this.proactiveElement.parentElement.removeChild(this.proactiveElement),void(this.proactiveElement=null);if(!this.proactiveElement){var u=document.createElement("div");u.style.position="fixed";var p=null!==(o=null!==(n=this.config.bottomSpacing)&&void 0!==n?n:null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.bottom_spacing)&&void 0!==o?o:20,v=null!==(l=null!==(r=this.config.sideSpacing)&&void 0!==r?r:null===(a=this.config.config.interface_properties)||void 0===a?void 0:a.side_spacing)&&void 0!==l?l:20,h=this.config.position||(null===(s=this.config.config.interface_properties)||void 0===s?void 0:s.position)||"Right";u.style.bottom="".concat(p+(this.config.config.launcher_type===f.IMAGE?48:40)+8,"px"),"Right"===h?u.style.right="".concat(v,"px"):u.style.left="".concat(v,"px"),u.style.maxWidth="22.875rem",u.style.zIndex="2147483646";var g=document.createElement("div");g.style.background="#fff",g.style.color="#111",g.style.borderRadius="16px",g.style.boxShadow="0 0 40px 0 rgba(14, 14, 15, 0.24)",g.style.padding="16px",g.style.cursor="pointer",g.style.fontFamily=C,g.style.fontSize="14px",g.style.lineHeight=String(S),g.textContent=(null==d?void 0:d.content)||"",g.onclick=function(){c.config.toggleIframe(),O()};var m=document.createElement("div");m.style.position="absolute",m.style.top="-32px",m.style.width="24px",m.style.height="24px",m.style.borderRadius="50%",m.style.background="#fff",m.style.boxShadow="0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",m.style.display="flex",m.style.alignItems="center",m.style.justifyContent="center",m.style.cursor="pointer","Right"===h?(m.style.right="0px",m.style.left="auto"):(m.style.left="0px",m.style.right="auto"),m.onclick=function(e){e.stopPropagation(),O(),c.proactiveElement&&c.proactiveElement.parentElement&&c.proactiveElement.parentElement.removeChild(c.proactiveElement),c.proactiveElement=null},m.innerHTML='\n <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none">\n <path d="M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334" stroke="#444547" stroke-width="0.816326" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n ',u.appendChild(g),u.appendChild(m),document.body.appendChild(u),this.proactiveElement=u}},e}(),Ie=function(){function e(e){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(e){var n,i,o,r,a,l,s,c,d,u,p,f,v,h,g,m=x().copilotUrl;if(e.origin===m){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(E.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:w.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(w.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=e.data)||void 0===a?void 0:a.type)&&(null===(s=(l=t.config).onEvent)||void 0===s||s.call(l,{type:w.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(w.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:w.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(w.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===(h=(v=t.config).onEvent)||void 0===h||h.call(v,{type:w.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(w.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=e.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(E.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=this.config.position||(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,r;if(this.iframeElement){var a=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",l=null!==(r=null!==(i=this.config.bottomSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.bottom_spacing)&&void 0!==r?r:20;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(l,"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=x().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(){W.trackError(new Error(oe[X]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:X,errorType:ne,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,l,s,c,d=this;this.config.isVisible=e;var u=this.config.position||(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=x().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===(l=this.config.config)||void 0===l?void 0:l.isAnonymous}},f),this.hasRegistered=!0),null===(c=(s=this.config).onEvent)||void 0===c||c.call(s,{type:w.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(w.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=h(h({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=x().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}(),xe=function(){function e(e,t,n,i){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config={config:e,position:t,sideSpacing:n,bottomSpacing:i},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,l,s,c=(null===window||void 0===window?void 0:window.innerWidth)<560,d=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",u=null!==(r=null!==(i=this.config.sideSpacing)&&void 0!==i?i:null===(o=this.config.config.interface_properties)||void 0===o?void 0:o.side_spacing)&&void 0!==r?r:20,p=null!==(s=null!==(a=this.config.bottomSpacing)&&void 0!==a?a:null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==s?s: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 f={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},v=h(h({},f),((e={bottom:"".concat(p,"px")})[d.toLowerCase()]="".concat(u,"px"),e.alignItems="Right"===d?"flex-end":"flex-start",e)),g=h(h({},f),((t={top:"0"})[d.toLowerCase()]="".concat(u,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,c?g:v)},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}(),Te=function(e,t,n){return g(void 0,void 0,void 0,(function(){var i,o,r,a,l,s,c,d;return m(this,(function(u){switch(u.label){case 0:return u.trys.push([0,5,,6]),i=x().apiUrl,o="".concat(i,"/chat/chatbot/get/"),y.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{},launcher_info:se()},[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 l=u.sent(),new Error(oe[Z](a.status,l));case 3:return[4,a.json()];case 4:if(s=u.sent(),!(null===(d=null==s?void 0:s.user)||void 0===d?void 0:d.org_info))throw new Error(oe[Q](["user","org_info"]));return[2,s];case 5:throw c=u.sent(),W.trackError(c instanceof Error?c:new Error(oe[Y]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?Z:Y,errorType:te,context:{apiKey:e,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},Ce=function(e){return g(void 0,void 0,void 0,(function(){var t,n,i,o,r,a,l,s,c,d,v,g,b,y,_,w,E,I,x,T,C,S,A,O,R,D,k,L,N,z,M,B,j,F;return m(this,(function(m){switch(m.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=ue("rblyn_anon")||de(),pe("rblyn_anon",n,365),i=!0),[4,Te(t.api_key,n,t.user_token)];case 1:return o=m.sent(),r=H(),a=se(),U=t.user_profile,l=U?Object.fromEntries(Object.entries(U).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},s=h(h(h({},r),{__INT_SYS_INFO__:h(h({},r),a)}),l),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",show_launcher:null===(d=null===(c=o.user.org_info)||void 0===c?void 0:c.show_launcher)||void 0===d||d,brand_colour:(null===(g=null===(v=o.user.org_info.brand_config)||void 0===v?void 0:v.colors)||void 0===g?void 0:g.brand_color)||"",image_url:(null===(y=null===(b=o.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===y?void 0:y.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(_=o.user.org_info.brand_config)||void 0===_?void 0:_.display_name)||"",welcome_message:(null===(w=o.user.org_info.brand_config)||void 0===w?void 0:w.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(E=o.user.org_info.brand_config)||void 0===E?void 0:E.redirect_url)||""},launcher_type:(null===(I=o.user.org_info.brand_config)||void 0===I?void 0:I.launcher_type)||f.IMAGE,launcher_properties:{text:(null===(T=null===(x=o.user.org_info.brand_config)||void 0===x?void 0:x.launcher_properties)||void 0===T?void 0:T.text)||""},images:{launcher_image_url:{url:(null===(A=null===(S=null===(C=o.user.org_info.brand_config)||void 0===C?void 0:C.images)||void 0===S?void 0:S.launcher_image_url)||void 0===A?void 0:A.url)||""}},proactive_message_obj:(null===(D=null===(R=null===(O=null==o?void 0:o.user)||void 0===O?void 0:O.org_info)||void 0===R?void 0:R.brand_config)||void 0===D?void 0:D.proactive_message_obj)||void 0,interface_properties:{position:(null===(L=null===(k=o.user.org_info.brand_config)||void 0===k?void 0:k.interface_properties)||void 0===L?void 0:L.position)||p.RIGHT,side_spacing:(null===(z=null===(N=o.user.org_info.brand_config)||void 0===N?void 0:N.interface_properties)||void 0===z?void 0:z.side_spacing)||20,bottom_spacing:(null===(B=null===(M=o.user.org_info.brand_config)||void 0===M?void 0:M.interface_properties)||void 0===B?void 0:B.bottom_spacing)||20},interface_type:(null===(j=o.user.org_info.brand_config)||void 0===j?void 0:j.interface_type)||u.WIDGET,launcher_delay:(null===(F=o.user.org_info.brand_config)||void 0===F?void 0:F.launcher_delay)||{enabled:!1,delay:0}}]}var U}))}))},Se=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){}}},Ae=function(){function e(e){var t=this;this.container=null,this.floatingButton=null,this.launcherDelayTimeout=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){var n,i,o,r,a;if(!t.isDestroyed){var l=e.isInitialized,s=e.error,c=e.chatbotConfig,d=e.isIframeVisible;if(!s&&c&&l){if(t.eventEmitter=Se({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:c.isAnonymous,userId:c.userId}}),t.container||(t.container=new xe(c,t.config.position,t.config.sideSpacing,t.config.bottomSpacing)),t.iframe)t.iframe.update({config:c,isVisible:d,position:t.config.position,bottomSpacing:t.config.bottomSpacing});else if(t.iframe=new Ie({config:c,isVisible:d,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,bottomSpacing:t.config.bottomSpacing}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var u=t.iframe.getElement();u&&t.container&&t.container.getElement().prepend(u)}var p=!0===(null==c?void 0:c.show_launcher),f=!0===(null===(n=null==c?void 0:c.launcher_delay)||void 0===n?void 0:n.enabled),v=null!==(a=null!==(o=null===(i=null==c?void 0:c.launcher_delay)||void 0===i?void 0:i.seconds)&&void 0!==o?o:null===(r=null==c?void 0:c.launcher_delay)||void 0===r?void 0:r.delay)&&void 0!==a?a:0,h=function(){if(t.floatingButton)t.floatingButton.update({config:c,isIframeVisible:d,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing});else if(t.floatingButton=new Ee({config:c,toggleIframe:t.toggleIframe,isIframeVisible:d,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var e=t.floatingButton.getElement();e&&t.container&&t.container.getElement().appendChild(e)}};t.launcherDelayTimeout&&(clearTimeout(t.launcherDelayTimeout),t.launcherDelayTimeout=null),p?f&&Number(v)>0&&!t.floatingButton?t.launcherDelayTimeout=window.setTimeout((function(){h(),t.launcherDelayTimeout=null}),1e3*Number(v)):h():t.floatingButton&&(t.floatingButton.destroy(),t.floatingButton=null)}}},this.toggleIframe=function(){var e=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(e.isIframeVisible?w.CHATBOT_CLOSED:w.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(w.CHATBOT_CLOSED)};var n,i,o,r,a=h(h({},e),{position:"string"==typeof e.position?"left"===e.position.toLowerCase()?"Left":"right"===e.position.toLowerCase()?"Right":void 0:void 0,sideSpacing:"string"==typeof e.sideSpacing?""===e.sideSpacing||isNaN(Number(e.sideSpacing))?void 0:Number(e.sideSpacing):e.sideSpacing,bottomSpacing:"string"==typeof e.bottomSpacing?""===e.bottomSpacing||isNaN(Number(e.bottomSpacing))?void 0:Number(e.bottomSpacing):e.bottomSpacing});if(this.config=a,!e.api_key)throw W.trackError(new Error(oe[P](e.api_key)),"RobylonChatbot",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}}),new Error("API key is required");try{W.initialize(e.api_key,e.user_id)}catch(e){W.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:J,errorType:ee,context:{timestamp:Date.now()}})}this.stateManager=(n={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},i={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},o=[],{getState:function(){return i},initialize:function(){return g(void 0,void 0,void 0,(function(){var e,t,i;return m(this,(function(o){switch(o.label){case 0:if(!n.api_key)return W.trackError(new Error(oe[P](n.api_key)),"ChatbotStateManager",{errorCode:P,errorType:ee,context:{timestamp:Date.now()}}),[2];r({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,Ce(n)];case 2:return e=o.sent(),[4,new Promise((function(t,n){he(e,(function(){r({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return o.sent(),[3,6];case 4:return t=o.sent(),i=t instanceof Error?t.message:"Failed to initialize chatbot",r({error:i}),W.trackError(t instanceof Error?t:new Error(i),"ChatbotStateManager",{errorCode:K,errorType:ee,context:{timestamp:Date.now()}}),[3,6];case 5:return r({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){r({isIframeVisible:!i.isIframeVisible})},closeIframe:function(){r({isIframeVisible:!1})},updateState:r=function(e){i=h(h({},i),e),o.forEach((function(e){return e(i)}))},subscribe:function(e){return o.push(e),function(){var t=o.indexOf(e);t>-1&&o.splice(t,1)}},unsubscribe:function(e){var t=o.indexOf(e);t>-1&&o.splice(t,1)}}),this.eventEmitter=Se({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),window.RobylonShouldShowProactive=k,window.RobylonHideProactive=O,this.initialize()}return e.prototype.initialize=function(){return g(this,void 0,void 0,(function(){var e;return m(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(),W.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:K,errorType:ee,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(w.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(w.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.launcherDelayTimeout&&(clearTimeout(this.launcherDelayTimeout),this.launcherDelayTimeout=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 Oe(e){return new Ae(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=Oe(i)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(e){var n=Array.prototype.slice.call(arguments,1);return"init"===e?t=Oe(n[0]||{}):t&&"function"==typeof t[e]?t[e].apply(t,n):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var Re={create:Oe,getState:function(){return"initialized"}};export{_e as Chatbot,u as ChatbotInterfaceType,f as LauncherType,v as ProactiveSendTimeType,Re as RobylonChatbot,p as WidgetPositionEnums,we as useChatbot};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((i="undefined"!=typeof globalThis?globalThis:i||self).RobylonChatbot={})}(this,(function(i){"use strict";var t,n,o,e,r=function(){return r=Object.assign||function(i){for(var t,n=1,o=arguments.length;o>n;n++)for(var e in t=arguments[n])({}).hasOwnProperty.call(t,e)&&(i[e]=t[e]);return i},r.apply(this,arguments)};function s(i,t,n,o){return new(n||(n=Promise))((function(e,r){function s(i){try{a(o.next(i))}catch(i){r(i)}}function d(i){try{a(o.throw(i))}catch(i){r(i)}}function a(i){var t;i.done?e(i.value):(t=i.value,t instanceof n?t:new n((function(i){i(t)}))).then(s,d)}a((o=o.apply(i,t||[])).next())}))}function d(i,t){var n,o,e,r={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=d(0),s.throw=d(1),s.return=d(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function d(d){return function(a){return function(d){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,d[0]&&(r=0)),r;)try{if(n=1,o&&(e=2&d[0]?o.return:d[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,d[1])).done)return e;switch(o=0,e&&(d=[2&d[0],e.value]),d[0]){case 0:case 1:e=d;break;case 4:return r.label++,{value:d[1],done:!1};case 5:r.label++,o=d[1],d=[0];continue;case 7:d=r.ops.pop(),r.trys.pop();continue;default:if(!((e=(e=r.trys).length>0&&e[e.length-1])||6!==d[0]&&2!==d[0])){r=0;continue}if(3===d[0]&&(!e||d[1]>e[0]&&d[1]<e[3])){r.label=d[1];break}if(6===d[0]&&r.label<e[1]){r.label=e[1],e=d;break}if(e&&r.label<e[2]){r.label=e[2],r.ops.push(d);break}e[2]&&r.ops.pop(),r.trys.pop();continue}d=t.call(i,r)}catch(i){d=[6,i],o=0}finally{n=e=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([d,a])}}}"function"==typeof SuppressedError&&SuppressedError,function(i){i.WIDGET="WIDGET",i.POPOVER="POPOVER",i.EMBED="EMBED"}(t||(t={})),function(i){i.RIGHT="Right",i.LEFT="Left"}(n||(n={})),function(i){i.TEXT="TEXT",i.IMAGE="IMAGE",i.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(o||(o={})),function(i){i.WORKING_HOURS="WORKING_HOURS",i.ALWAYS="ALWAYS"}(e||(e={}));var a=function(i,t){void 0===t&&(t=.5);var n,o,e,r,s=function(i){i=i.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(i,t,n,o){return t+t+n+n+o+o}));var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}}(i);return(n=s.r,o=s.g,e=s.b,.2126*(r=[n,o,e].map((function(i){return(i/=255)>.03928?Math.pow((i+.055)/1.055,2.4):i/12.92})))[0]+.7152*r[1]+.0722*r[2])>t?"#0E0E0F":"#FFFFFF"},l={log:function(){},error:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.error.apply(console,i)},warn:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.warn.apply(console,i)},info:function(){}};l.log("Raw API_URL:","https://stage-api.robylon.ai");var u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};l.log("CONFIG",u);var c,h,v=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},f=function(){return{copilotUrl:u.copilotUrl||"https://app.robylon.ai",environment:u.environment||"production",apiUrl:u.apiUrl||"https://app.robylon.ai"}};!function(i){i.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",i.CHATBOT_BUTTON_CLICKED="CHATBOT_BUTTON_CLICKED",i.CHATBOT_OPENED="CHATBOT_OPENED",i.CHATBOT_CLOSED="CHATBOT_CLOSED",i.CHATBOT_APP_READY="CHATBOT_APP_READY",i.CHATBOT_LOADED="CHATBOT_LOADED",i.CHAT_INITIALIZED="CHAT_INITIALIZED",i.SESSION_REFRESHED="SESSION_REFRESHED",i.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED",i.CHATBOT_READY="CHATBOT_READY"}(c||(c={})),function(i){i.CHAT_MOVED="CHAT_MOVED",i.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(h||(h={}));var p,m="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",w="21px",b=!1,g=function(){b=!0};console.log("isProactiveHiddenThisPage",(function(){return b}));var x,I=((p={})[e.WORKING_HOURS]=function(i,t){var n=t.getHours(),o=t.getMinutes();return(n>10||10===n&&o>=0)&&(19>n||19===n&&0===o)},p[e.ALWAYS]=function(i,t){return!0},p),y=function(i,t){var n;if(void 0===t&&(t=new Date),console.log("proactiveHiddenThisPage shouldShowProactiveMessage",b),!(null===(n=null==i?void 0:i.content)||void 0===n?void 0:n.trim()))return!1;if(b)return!1;var o=(null==i?void 0:i.send_time_type)||"";if(!o)return!0;var e=I[o];return!!e&&e(i,t)},_=function(){function i(i){var t=this;this.resizeObserver=null,this.proactiveElement=null,this.config=i,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount();try{this.buttonElement.style.opacity="0",this.buttonElement.style.transition="transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",requestAnimationFrame((function(){t.buttonElement.style.opacity="1"}))}catch(i){}this.setupResizeListener(),this.renderProactiveIfNeeded()}return i.prototype.render=function(){var i=this;f().copilotUrl;var t=this.config,n=t.config,e={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97)",transform:t.isIframeVisible?"scale(0.85)":"scale(1)",fontFamily:m};n.launcher_type===o.IMAGE&&Object.assign(e,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:n.brand_colour}),this.applyResponsiveStyles(e),this.buttonElement.className="message-bubble-container",this.buttonElement.innerHTML="",this.buttonElement.appendChild(this.createLauncherElement()),this.buttonElement.onclick=function(){i.config.toggleIframe()},this.renderProactiveIfNeeded()},i.prototype.createLauncherElement=function(){var i,t,n=this.config,e=n.config,r=n.isIframeVisible,s=f().copilotUrl;switch(console.log("config in floating button",e),e.launcher_type){case o.TEXT:return this.createTextLauncher();case o.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case o.IMAGE:default:if(r){var d=document.createElement("div");return d.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 ',d}var a=document.createElement("img");return a.src=e.launcher_type?(null===(t=null===(i=e.images)||void 0===i?void 0:i.launcher_image_url)||void 0===t?void 0:t.url)||"".concat(s,"/chatbubble.png"):e.image_url||"".concat(s,"/chatbubble.png"),a.alt="Chat",Object.assign(a.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),a}},i.prototype.createTextLauncher=function(){var i=this.config.config,t=i.brand_colour,n=i.launcher_properties,o=document.createElement("div");Object.assign(o.style,{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:t,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box"});var e=document.createElement("div");Object.assign(e.style,{flex:"1",minWidth:"0"});var r=document.createElement("p");return Object.assign(r.style,{margin:"0",color:a(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:w,fontFamily:m,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),r.textContent=(null==n?void 0:n.text)||"",e.appendChild(r),o.appendChild(e),o},i.prototype.createTextualImageLauncher=function(){var i,t,n,o,e,r,s=f().copilotUrl,d=this.config.config,l=d.brand_colour,u=d.launcher_properties,c=d.image_url,h=document.createElement("div");Object.assign(h.style,{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor: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 v=document.createElement("div");Object.assign(v.style,{flex:"1",minWidth:"0"});var p=document.createElement("p");Object.assign(p.style,{margin:"0",color:a(l),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:w,fontFamily:m,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),p.textContent=(null==u?void 0:u.text)||"";var b=document.createElement("div");Object.assign(b.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var g=document.createElement("img");return g.src=(null===(t=null===(i=null==this?void 0:this.config)||void 0===i?void 0:i.config)||void 0===t?void 0:t.launcher_type)?(null===(r=null===(e=null===(o=null===(n=null==this?void 0:this.config)||void 0===n?void 0:n.config)||void 0===o?void 0:o.images)||void 0===e?void 0:e.launcher_image_url)||void 0===r?void 0:r.url)||"".concat(s,"/chatbubble.png"):c||"".concat(s,"/chatbubble.png"),g.alt="Chat",Object.assign(g.style,{width:"100%",height:"100%",objectFit:"cover"}),v.appendChild(p),b.appendChild(g),h.appendChild(v),h.appendChild(b),h},i.prototype.applyResponsiveStyles=function(i){var t,n,o,e,s,d,a,l,u,c=560>(null===window||void 0===window?void 0:window.innerWidth),h=this.config.config,v=this.config.position||(null===(o=h.interface_properties)||void 0===o?void 0:o.position)||"Right",f=null!==(d=null!==(e=this.config.sideSpacing)&&void 0!==e?e:null===(s=h.interface_properties)||void 0===s?void 0:s.side_spacing)&&void 0!==d?d:20,p=null!==(u=null!==(a=this.config.bottomSpacing)&&void 0!==a?a:null===(l=h.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==u?u:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var m=r(r({},i),c?((t={position:"fixed",bottom:"".concat(p,"px")})[v.toLowerCase()]="".concat(f,"px"),t):((n={bottom:"".concat(p,"px")})[v.toLowerCase()]="".concat(f,"px"),n));Object.assign(this.buttonElement.style,m)},i.prototype.handleResize=function(){var i={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",borderRadius:this.config.config.launcher_type&&this.config.config.launcher_type!==o.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===o.IMAGE&&Object.assign(i,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:this.config.config.brand_colour}),this.applyResponsiveStyles(i)},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.getElement=function(){return this.buttonElement},i.prototype.mount=function(){var i=this;requestAnimationFrame((function(){var t,n;null===(n=(t=i.config).onEvent)||void 0===n||n.call(t,{type:c.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),i.config.onInternalEvent(c.CHATBOT_BUTTON_LOADED)}))},i.prototype.update=function(i){this.config.isIframeVisible,this.config=r(r({},this.config),i),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render(),this.renderProactiveIfNeeded()},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement),this.proactiveElement&&this.proactiveElement.parentElement&&(this.proactiveElement.parentElement.removeChild(this.proactiveElement),this.proactiveElement=null)},i.prototype.renderProactiveIfNeeded=function(){var i,t,n,e,r,s,d,a,l,u=this,c=null===(t=null===(i=this.config)||void 0===i?void 0:i.config)||void 0===t?void 0:t.proactive_message_obj;if(!y(c)||this.config.isIframeVisible)return this.proactiveElement&&this.proactiveElement.parentElement&&this.proactiveElement.parentElement.removeChild(this.proactiveElement),void(this.proactiveElement=null);if(!this.proactiveElement){var h=document.createElement("div");h.style.position="fixed";var v=null!==(r=null!==(n=this.config.bottomSpacing)&&void 0!==n?n:null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.bottom_spacing)&&void 0!==r?r:20,f=null!==(a=null!==(s=this.config.sideSpacing)&&void 0!==s?s:null===(d=this.config.config.interface_properties)||void 0===d?void 0:d.side_spacing)&&void 0!==a?a:20,p=this.config.position||(null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.position)||"Right";h.style.bottom="".concat(v+(this.config.config.launcher_type===o.IMAGE?48:40)+8,"px"),"Right"===p?h.style.right="".concat(f,"px"):h.style.left="".concat(f,"px"),h.style.maxWidth="22.875rem",h.style.zIndex="2147483646";var b=document.createElement("div");b.style.background="#fff",b.style.color="#111",b.style.borderRadius="16px",b.style.boxShadow="0 0 40px 0 rgba(14, 14, 15, 0.24)",b.style.padding="16px",b.style.cursor="pointer",b.style.fontFamily=m,b.style.fontSize="14px",b.style.lineHeight=w+"",b.textContent=(null==c?void 0:c.content)||"",b.onclick=function(){u.config.toggleIframe(),g()};var x=document.createElement("div");x.style.position="absolute",x.style.top="-32px",x.style.width="24px",x.style.height="24px",x.style.borderRadius="50%",x.style.background="#fff",x.style.boxShadow="0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",x.style.display="flex",x.style.alignItems="center",x.style.justifyContent="center",x.style.cursor="pointer","Right"===p?(x.style.right="0px",x.style.left="auto"):(x.style.left="0px",x.style.right="auto"),x.onclick=function(i){i.stopPropagation(),g(),u.proactiveElement&&u.proactiveElement.parentElement&&u.proactiveElement.parentElement.removeChild(u.proactiveElement),u.proactiveElement=null},x.innerHTML='\n <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none">\n <path d="M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334" stroke="#444547" stroke-width="0.816326" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n ',h.appendChild(b),h.appendChild(x),document.body.appendChild(h),this.proactiveElement=h}},i}(),E=function(){var i;return(null===(i=navigator.userAgentData)||void 0===i?void 0:i.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},S=function(){var i;if(null===(i=navigator.userAgentData)||void 0===i?void 0:i.brands)for(var t=["Chrome","Firefox","Safari","Edge","Opera"],n=0,o=navigator.userAgentData.brands;n<o.length;n++){var e=o[n];if(t.includes(e.brand))return e.brand}return(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},T=function(){var i,t,n,o;return{width:(null===window||void 0===window?void 0:window.innerWidth)||(null===(i=null===document||void 0===document?void 0:document.documentElement)||void 0===i?void 0:i.clientWidth)||(null===(t=null===document||void 0===document?void 0:document.body)||void 0===t?void 0:t.clientWidth),height:(null===window||void 0===window?void 0:window.innerHeight)||(null===(n=null===document||void 0===document?void 0:document.documentElement)||void 0===n?void 0:n.clientHeight)||(null===(o=null===document||void 0===document?void 0:document.body)||void 0===o?void 0:o.clientHeight)}},A=function(){return{platform:"web",os:E(),browser:S(),sdk_version:"1.1.40-staging.5",device:(i=navigator.userAgent.toLowerCase(),/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(i)?"tablet":/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(i)?"mobile":"desktop"),screen_size:T()};var i};!function(i){i.ERROR="ERROR",i.INFO="INFO"}(x||(x={}));var R,O=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],C=function(i){var t=i.filename,n=i.stack,o=i.message;return!!(t||n||o)&&O.some((function(i){return(null==t?void 0:t.includes(i))||(null==n?void 0:n.includes(i))||(null==o?void 0:o.includes(i))}))},k=function(){function i(){var i=this;this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.handleWindowError=function(t){var n,o={filename:t.filename,stack:null===(n=t.error)||void 0===n?void 0:n.stack,message:t.message};C(o)&&i.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})},this.handleUnhandledRejection=function(t){var n,o,e={stack:null===(n=t.reason)||void 0===n?void 0:n.stack,message:(null===(o=t.reason)||void 0===o?void 0:o.message)||t.reason+""};C(e)&&i.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return i.prototype.setupGlobalHandlers=function(){v()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},i.prototype.cleanup=function(){v()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},i.getInstance=function(){return i.instance||(i.instance=new i),i.instance},i.prototype.initialize=function(i,t){void 0===t&&(t=null);try{if(this.preInitQueue.length>0){var n={org_id:"UNINITALIZED",event_data:{message:"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i)),componentName:"ErrorTrackingService",additionalInfo:{preInitError:!0,apiKey:i,userId:t,timestamp:Date.now()},timestamp:Date.now()},metadata:A(),event_type:x.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=i,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){l.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:Error(n+""),componentName:"ErrorTrackingService",additionalInfo:{apiKey:i,userId:t}})}},i.prototype.processPreInitQueue=function(){return s(this,void 0,void 0,(function(){var i,t,n;return d(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];l.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),i=0,t=this.preInitQueue,o.label=1;case 1:return i<t.length?(n=t[i],[4,this.trackError(n.error,n.componentName,r(r({},n.additionalInfo),{preInitError:!0}))]):[3,4];case 2:o.sent(),o.label=3;case 3:return i++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},i.prototype.sendLog=function(i){return s(this,void 0,void 0,(function(){var t,n,o,e,r,s;return d(this,(function(d){switch(d.label){case 0:return d.trys.push([0,4,,5]),t=f().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 1:return(n=d.sent()).ok?[3,3]:(e=(o=l).error,r=["Failed to send error log:"],[4,n.text()]);case 2:e.apply(o,r.concat([d.sent()])),d.label=3;case 3:return[3,5];case 4:return s=d.sent(),l.error("Error sending log:",s),[3,5];case 5:return[2]}}))}))},i.prototype.trackError=function(i,t,n){return s(this,void 0,void 0,(function(){var o,e,s;return d(this,(function(d){switch(d.label){case 0:if(this.isInitialized)return[3,5];o={org_id:"UNINITALIZED",event_data:{message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:r(r({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:A(),event_type:x.ERROR,user_id:this.userId},d.label=1;case 1:return d.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return d.sent(),[3,4];case 3:return d.sent(),this.preInitQueue.push({error:i,componentName:t,additionalInfo:n}),l.warn("Error tracked before initialization, queuing:",i),[3,4];case 4:return[2];case 5:return e={message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:r(r({},n),{timestamp:Date.now()}),timestamp:Date.now()},s={org_id:this.apiKey||"UNINITALIZED",event_data:e,metadata:A(),event_type:x.ERROR,user_id:this.userId},[4,this.sendLog(s)];case 6:return d.sent(),[2]}}))}))},i.prototype.trackInfo=function(i,t,n){return s(this,void 0,void 0,(function(){var o,e;return d(this,(function(r){switch(r.label){case 0:return this.apiKey?(o={message:i,componentName:t,additionalInfo:n,timestamp:Date.now()},e={org_id:this.apiKey,event_data:o,metadata:A(),event_type:x.INFO,user_id:this.userId},[4,this.sendLog(e)]):(l.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},i}(),D=k.getInstance(),j="MISSING_API_KEY",z="SDK_INIT_FAILED",M="ERROR_TRACKING_INIT_FAILED",N="API_REQUEST_FAILED",U="NETWORK_ERROR",F="INVALID_RESPONSE",L="IFRAME_LOAD_FAILED",P="INITIALIZATION_ERROR",W=((R={})[j]=function(i){return"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i),". A valid API key string is required to initialize the SDK.")},R.INVALID_API_KEY=function(i){return"SDK Initialization Failed: Provided API key '".concat(i,"' is invalid. API key must be a non-empty string in UUID format.")},R.CONFIG_FETCH_FAILED=function(i){return"Failed to fetch chatbot configuration: ".concat(i.statusCode?"Server responded with status ".concat(i.statusCode):"Could not reach server").concat(i.error?". Error: ".concat(i.error):"")},R[N]=function(i,t,n){return"API Request Failed: Server responded with status ".concat(i," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},R[U]=function(i){return"Network Error: Failed to communicate with server".concat(i.url?" at ".concat(i.url):"").concat(i.error?" - ".concat(i.error):"")},R[L]=function(i){return"Failed to load chatbot interface".concat(i.src?" from ".concat(i.src):"").concat(i.error?". Error: ".concat(i.error):"")},R[F]=function(i){return"Invalid API Response: Missing required fields in response data: ".concat(i.join(", "))},R[M]=function(i){return"Error Tracking Service initialization failed".concat(i.apiKey?" for API key ".concat(i.apiKey):"").concat(i.error?". Error: ".concat(i.error):"")},R[z]=function(i){return"SDK Initialization Failed: ".concat(i.reason||"Could not initialize the chatbot SDK").concat(i.config?". Attempted initialization with config: ".concat(JSON.stringify(i.config,null,2)):"")},R.COOKIE_ACCESS_ERROR=function(i,t){return"Cookie Access Error: Failed to ".concat(i).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},R.COMPONENT_RENDER_ERROR=function(i){return"React Component Error: ".concat(i.component||"Unknown component"," failed to render. Error: ").concat(i.error).concat(i.stack?"\nComponent Stack: ".concat(i.stack):"")},R),H=function(){function i(i){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(i){var n,o,e,r,s,d,a,l,u,v,p,m,w,b,g,x=f().copilotUrl;if(i.origin===x){if("closeChatbot"===i.data)return void t.config.onClose();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=i.data)||void 0===n?void 0:n.type))return void t.config.onInternalEvent(h.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(o=i.data)||void 0===o?void 0:o.type)&&(null===(r=(e=t.config).onEvent)||void 0===r||r.call(e,{type:c.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(c.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(s=i.data)||void 0===s?void 0:s.type)&&(null===(a=(d=t.config).onEvent)||void 0===a||a.call(d,{type:c.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(c.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(l=i.data)||void 0===l?void 0:l.type)&&(null===(v=(u=t.config).onEvent)||void 0===v||v.call(u,{type:c.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(c.CHAT_INITIALIZATION_FAILED,{error:null===(p=i.data)||void 0===p?void 0:p.error})),"SESSION_REFRESHED"===(null===(m=i.data)||void 0===m?void 0:m.type)&&(null===(b=(w=t.config).onEvent)||void 0===b||b.call(w,{type:c.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(c.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=i.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(h.CHAT_MOVED,{from:i.data.from,to:i.data.to,trigger:i.data.trigger})}},this.config=i,this.iframeElement=document.createElement("iframe"),this.iframeElement.id="chat-iframe-rbyln",this.resizeHandler=this.applyResponsiveStyles.bind(this),this.render(),this.initialize(),this.setupEventListeners()}return i.prototype.getElement=function(){return this.iframeElement},i.prototype.render=function(){var i,t=this.config.position||(null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.position)||"Right";Object.assign(this.iframeElement.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(t.toLowerCase()),transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 0.15s ease-out",transform:"scale(0.3) translate3d(0,40px,0)",opacity:"0",display:"none"}),this.applyResponsiveStyles()},i.prototype.applyResponsiveStyles=function(){var i,t,n,o,e,r;if(this.iframeElement){var s=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",d=null!==(r=null!==(o=this.config.bottomSpacing)&&void 0!==o?o:null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.bottom_spacing)&&void 0!==r?r:20;560>window.innerWidth?Object.assign(this.iframeElement.style,((i={width:"100vw",minWidth:"300px"})[s.toLowerCase()]="0",i.bottom="0",i.height="100vh",i.flexDirection="column",i.flexGrow="1",i.borderRadius="0",i.top="0",i.maxHeight="100%",i.position="fixed",i)):Object.assign(this.iframeElement.style,((t={width:"26%",minWidth:"400px",height:"calc(100vh - 2rem - 10vh - ".concat(d,"px)"),borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"50rem",position:""})[s.toLowerCase()]=void 0,t))}},i.prototype.initialize=function(){var i=this;if(!this.isInitialized){var t=f().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,o,e=new URL(i.iframeElement.src).origin||t;null===(n=i.iframeElement.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},e)}))}},i.prototype.setupEventListeners=function(){var i=this;window.addEventListener("resize",this.resizeHandler),this.iframeElement.addEventListener("error",(function(){D.trackError(Error(W[L]({src:i.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:L,errorType:"RUNTIME_ERROR",context:{config:i.config.config,iframeUrl:i.iframeElement.src,timestamp:Date.now()}})})),window.addEventListener("message",this.handleMessage)},i.prototype.updateVisibility=function(i){var t,n,o,e,r,s,d,a,l,u=this;this.config.isVisible=i;var h=this.config.position||(null===(t=this.config.config.interface_properties)||void 0===t?void 0:t.position)||"Right";if(i?(this.iframeElement.style.display="block",this.iframeElement.getBoundingClientRect(),this.iframeElement.style.opacity="1",this.iframeElement.style.transform="scale(1) translate3d(0,0,0)"):(this.iframeElement.style.opacity="0",this.iframeElement.style.transform="scale(0.3) translate3d(".concat((h.toLowerCase(),"0"),",40px,0)"),setTimeout((function(){u.config.isVisible||(u.iframeElement.style.display="none")}),200)),this.iframeElement.contentWindow&&i){var v=f().copilotUrl,p=new URL(this.iframeElement.src).origin||v;this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},p),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,action:"registerUserId",data:{userId:null===(e=this.config.config)||void 0===e?void 0:e.userId,token:null===(r=this.config.config)||void 0===r?void 0:r.token,userProfile:null===(s=this.config.config)||void 0===s?void 0:s.userProfile,isAnonymous:null===(d=this.config.config)||void 0===d?void 0:d.isAnonymous}},p),this.hasRegistered=!0),null===(l=(a=this.config).onEvent)||void 0===l||l.call(a,{type:c.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(c.CHATBOT_OPENED)}},i.prototype.update=function(i){var t=this.config.isVisible;if(this.config=r(r({},this.config),i),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=f().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},i.prototype.destroy=function(){window.removeEventListener("resize",this.resizeHandler),window.removeEventListener("message",this.handleMessage),this.iframeElement&&this.iframeElement.parentNode&&this.iframeElement.parentNode.removeChild(this.iframeElement)},i}(),B=function(){function i(i,t,n,o){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config={config:i,position:t,sideSpacing:n,bottomSpacing:o},this.render(),this.mount(),this.setupResizeListener()}return i.prototype.render=function(){this.applyStyles(),this.containerElement.className="robylon-chatbot-container"},i.prototype.applyStyles=function(){var i,t,n,o,e,s,d,a,l,u=560>(null===window||void 0===window?void 0:window.innerWidth),c=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",h=null!==(s=null!==(o=this.config.sideSpacing)&&void 0!==o?o:null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.side_spacing)&&void 0!==s?s:20,v=null!==(l=null!==(d=this.config.bottomSpacing)&&void 0!==d?d:null===(a=this.config.config.interface_properties)||void 0===a?void 0:a.bottom_spacing)&&void 0!==l?l: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 f={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},p=r(r({},f),((i={bottom:"".concat(v,"px")})[c.toLowerCase()]="".concat(h,"px"),i.alignItems="Right"===c?"flex-end":"flex-start",i)),m=r(r({},f),((t={top:"0"})[c.toLowerCase()]="".concat(h,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,u?m:p)},i.prototype.handleResize=function(){this.applyStyles()},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.mount=function(){document.body.appendChild(this.containerElement)},i.prototype.getElement=function(){return this.containerElement},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.containerElement&&this.containerElement.parentNode&&this.containerElement.parentNode.removeChild(this.containerElement)},i}(),J=function(i){var t=i?"USER_DATA=%7B%22attributes%22%3A%5B%7B%22key%22%3A%22USER_ATTRIBUTE_USER_EMAIL%22%2C%22value%22%3A%22dinesh.goel%40robylon.ai%22%7D%2C%7B%22key%22%3A%22USER_ATTRIBUTE_UNIQUE_ID%22%2C%22value%22%3A%2266011f2c28d1787d13c6c796%22%7D%5D%2C%22subscribedToOldSdk%22%3Afalse%2C%22deviceUuid%22%3A%2226c02feb-2664-451d-8469-9cf1378547c6%22%2C%22deviceAdded%22%3Atrue%7D; _ga_3YS9P6ZDWX=GS1.1.1715252584.3.1.1715258696.39.0.0; _ga_V4J24F7YF9=GS1.1.1715273274.2.0.1715273274.0.0.0; city_name=Bengaluru; lang_code=en-in; cookieConcent=A; _gcl_au=1.1.343275043.1717154298; _clck=43guwd%7C2%7Cfmi%7C0%7C1561; _gid=GA1.2.1423066649.1718210058; moe_uuid=26c02feb-2664-451d-8469-9cf1378547c6; _ga_6RM65PWEZY=GS1.1.1718210058.18.1.1718211647.60.0.0; _ga=GA1.1.689213983.1712737672; AMP_MKTG_fe4beb374f=JTdCJTIycmVmZXJyZXIlMjIlM0ElMjJodHRwcyUzQSUyRiUyRmFjY291bnRzLnRlYWNobWludC5jb20lMkYlMjIlMkMlMjJyZWZlcnJpbmdfZG9tYWluJTIyJTNBJTIyYWNjb3VudHMudGVhY2htaW50LmNvbSUyMiU3RA==; AMP_fe4beb374f=JTdCJTIyZGV2aWNlSWQlMjIlM0ElMjI0MWMxMTljZC03YzVjLTRiYTctYTUzZS1mYTgzMjRlYjc0OWUlMjIlMkMlMjJ1c2VySWQlMjIlM0ElMjIxZjI2ODAwOC01OGYxLTQwYTItYjQ0Ni1mYmQ5N2E0NDQyYTAlMjIlMkMlMjJzZXNzaW9uSWQlMjIlM0ExNzE4MjEzMzEwOTc3JTJDJTIyb3B0T3V0JTIyJTNBZmFsc2UlMkMlMjJsYXN0RXZlbnRUaW1lJTIyJTNBMTcxODIxMzMxMDk4MSUyQyUyMmxhc3RFdmVudElkJTIyJTNBMTQlN0Q=; _ga_3YS9P6ZDWX=GS1.1.1718211637.26.1.1718213441.60.0.0; SESSION=%7B%22sessionKey%22%3A%22e4d76f52-9053-4277-99a4-f1ba667fd5f2%22%2C%22sessionStartTime%22%3A%222024-06-12T16%3A34%3A19.047Z%22%2C%22sessionMaxTime%22%3A1800%2C%22customIdentifiersToTrack%22%3A%5B%5D%2C%22sessionExpiryTime%22%3A1718215247464%2C%22numberOfSessions%22%3A17%7D":document.cookie;return t=t.split(";").map((function(i){var t=i.split("="),n=t[0],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},Y=function(){var i,t=navigator.userAgent;if(null===(i=navigator.userAgentData)||void 0===i?void 0:i.brands){var n=navigator.userAgentData.brands.find((function(i){return"Google Chrome"===i.brand}));if(null==n?void 0:n.version)return n.version}var o=t.match(/(Chrome|Firefox|Safari|Edge|Opera)\/(\d+\.\d+)/);return o?o[2]:"Unknown"},Z=function(){var i,t,n=A();return{current_page_url:(null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.href)||"",browser_language:(null===navigator||void 0===navigator?void 0:navigator.language)||(null===(t=null===navigator||void 0===navigator?void 0:navigator.languages)||void 0===t?void 0:t[0])||"en",browser_version:Y(),os:null==n?void 0:n.os,referral_url:(null===document||void 0===document?void 0:document.referrer)||""}},G=function(i,t,n){return s(void 0,void 0,void 0,(function(){var o,e,r,s,a,u,c,h;return d(this,(function(d){switch(d.label){case 0:return d.trys.push([0,5,,6]),o=f().apiUrl,l.log("endpointUrl",e="".concat(o,"/chat/chatbot/get/")),r={client_user_id:t||null,org_id:i,token:n||void 0,extra_info:{},launcher_info:Z()},[4,fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(s=d.sent()).ok?[3,3]:[4,s.text()];case 2:throw a=d.sent(),Error(W[N](s.status,a));case 3:return[4,s.json()];case 4:if(u=d.sent(),!(null===(h=null==u?void 0:u.user)||void 0===h?void 0:h.org_info))throw Error(W[F](["user","org_info"]));return[2,u];case 5:throw c=d.sent(),D.trackError(c instanceof Error?c:Error(W[U]({error:c+""})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?N:U,errorType:"API_ERROR",context:{apiKey:i,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},K=function(i){return s(void 0,void 0,void 0,(function(){var e,s,a,l,u,c,h,v,f,p,m,w,b,g,x,I,y,_,E,S,T,R,O,C,k,D,j,z,M,N,U,F,L,P;return d(this,(function(d){switch(d.label){case 0:return e=function(i){return{api_key:(i.api_key||"")+"",user_id:i.user_id?i.user_id+"":null,user_token:i.user_token?i.user_token+"":void 0,user_profile:i.user_profile||{}}}(i),s=e.user_id||void 0,a=!1,s||(s=function(){var i,t="; ".concat(document.cookie).split("; rblyn_anon=");if(2===t.length)return null===(i=t.pop())||void 0===i?void 0:i.split(";").shift()}()||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var t=16*Math.random()|0;return("x"===i?t:3&t|8).toString(16)})),H=s,(B=new Date).setTime(B.getTime()+31536e6),document.cookie="".concat("rblyn_anon","=").concat(H,";expires=").concat(B.toUTCString(),";path=/"),a=!0),[4,G(e.api_key,s,e.user_token)];case 1:return l=d.sent(),u=A(),c=Z(),W=e.user_profile,h=W?Object.fromEntries(Object.entries(W).map((function(i){var t=i[0],n=i[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,n+""]}))):{},v=r(r(r({},u),{__INT_SYS_INFO__:r(r({},u),c)}),h),[2,{chatbotId:e.api_key,userId:s,token:e.user_token,isAnonymous:a,domain:"",show_launcher:null===(p=null===(f=l.user.org_info)||void 0===f?void 0:f.show_launcher)||void 0===p||p,brand_colour:(null===(w=null===(m=l.user.org_info.brand_config)||void 0===m?void 0:m.colors)||void 0===w?void 0:w.brand_color)||"",image_url:(null===(g=null===(b=l.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===g?void 0:g.launcher_logo_url)||"",userProfile:v,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(x=l.user.org_info.brand_config)||void 0===x?void 0:x.display_name)||"",welcome_message:(null===(I=l.user.org_info.brand_config)||void 0===I?void 0:I.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(y=l.user.org_info.brand_config)||void 0===y?void 0:y.redirect_url)||""},launcher_type:(null===(_=l.user.org_info.brand_config)||void 0===_?void 0:_.launcher_type)||o.IMAGE,launcher_properties:{text:(null===(S=null===(E=l.user.org_info.brand_config)||void 0===E?void 0:E.launcher_properties)||void 0===S?void 0:S.text)||""},images:{launcher_image_url:{url:(null===(O=null===(R=null===(T=l.user.org_info.brand_config)||void 0===T?void 0:T.images)||void 0===R?void 0:R.launcher_image_url)||void 0===O?void 0:O.url)||""}},proactive_message_obj:(null===(D=null===(k=null===(C=null==l?void 0:l.user)||void 0===C?void 0:C.org_info)||void 0===k?void 0:k.brand_config)||void 0===D?void 0:D.proactive_message_obj)||void 0,interface_properties:{position:(null===(z=null===(j=l.user.org_info.brand_config)||void 0===j?void 0:j.interface_properties)||void 0===z?void 0:z.position)||n.RIGHT,side_spacing:(null===(N=null===(M=l.user.org_info.brand_config)||void 0===M?void 0:M.interface_properties)||void 0===N?void 0:N.side_spacing)||20,bottom_spacing:(null===(F=null===(U=l.user.org_info.brand_config)||void 0===U?void 0:U.interface_properties)||void 0===F?void 0:F.bottom_spacing)||20},interface_type:(null===(L=l.user.org_info.brand_config)||void 0===L?void 0:L.interface_type)||t.WIDGET,launcher_delay:(null===(P=l.user.org_info.brand_config)||void 0===P?void 0:P.launcher_delay)||{enabled:!1,delay:0}}]}var W,H,B}))}))},V=function(){function i(i){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=i,this.validateDomain()&&this.init(),null===window||void 0===window||window.addEventListener("message",this.onCloseListener.bind(this),!1)}return i.prototype.onCloseListener=function(i){i.origin===this.config.domain&&"closeChatbot"===i.data&&this.closeIframe()},i.prototype.validateDomain=function(){var i,t=this.config.domain,n=null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.origin;return l.log("expectedDomain, to current domain",t,n,t===n),t===n},i.prototype.createChatBubblContainer=function(){var i,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var o=document.createElement("div");o.classList.add("close-btn"),o.textContent="✕",Object.assign(o.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(i=this.config.chat_interface_config)||void 0===i?void 0:i.chat_bubble_prompts)||[]).forEach((function(i){var o=t.createMessageBubble(i);n.appendChild(o)})),n.appendChild(o),document.body.appendChild(n)},i.prototype.createMessageBubble=function(i){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=i,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var o=document.createElement("button");return o.innerHTML="×",Object.assign(o.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),o.addEventListener("click",(function(){t.remove()})),t.appendChild(o),t.appendChild(n),t},i.prototype.createFloatingButton=function(){var i=document.createElement("div");i.classList.add("message-bubble-container"),Object.assign(i.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:a(this.config.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),document.body.appendChild(i),this.logoContainer=i,this.loadImage(this.logoContainer),this.createChatBubblContainer(),this.logoContainer.addEventListener("click",this.toggleIframe.bind(this))},i.prototype.loadImage=function(i){var t,n,o=document.createElement("img");o.src=this.config.launcher_type?(null===(n=null===(t=this.config.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(this.config.domain,"/chatbubble.png"):this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),o.alt="Chat",Object.assign(o.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=o,i.innerHTML="",i.appendChild(o)},i.prototype.createIframe=function(){var i=this;l.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),l.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){560>(null===window||void 0===window?void 0:window.innerWidth)?Object.assign(t.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(t.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"})};n(),null===window||void 0===window||window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o,e,r;if(i.iframe){var s=new URL(i.iframe.src).origin||i.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},s),null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hostname,action:"registerUserId",data:{userId:i.config.userId,token:i.config.token,userProfile:i.config.userProfile}},s)}})),null===window||void 0===window||window.addEventListener("message",(function(n){var o,e;if(n.origin===i.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===i.config.chatbotId,s={cookies:J(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname};null===(e=t.contentWindow)||void 0===e||e.postMessage(s,i.config.domain||"*")}"expand"===n.data&&(i.adjustIframeWidth(),t.style.height="calc(100vh - 120px)",t.style.bottom="86px"),"collapse"===n.data&&Object.assign(t.style,{width:"26%",height:"calc(100vh - 32px - 10vh)",bottom:"86px",top:"calc(32px + 10vh)"})}}))},i.prototype.adjustIframeWidth=function(){if(this.iframe){var i=null===window||void 0===window?void 0:window.innerWidth;l.log("screenWidth",i),this.iframe.style.width=832>i?"".concat(i-64,"px"):"800px"}},i.prototype.loadSvgInline=function(i){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");i.innerHTML="",n&&i.appendChild(n)},i.prototype.toggleIcon=function(i,t){"block"===t.style.display?this.loadSvgInline(i):this.loadImage(i)},i.prototype.toggleIframe=function(){var i;if(l.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;l.log("toggleIframe"),null===(i=this.iframe.contentWindow)||void 0===i||i.postMessage({domain:null===window||void 0===window?void 0:window.location.hostname,name:"none"===this.iframe.style.display?"openFrame":"closeFrame"},t),this.iframe.style.display="none"===this.iframe.style.display?"block":"none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="block"===this.iframe.style.display?"none":"cover",this.bubblePromptContainer&&(this.bubblePromptContainer.style.display="none"),l.log("this.bubblePromptContainer",this.bubblePromptContainer)}},i.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},i.prototype.init=function(){this.createIframe(),this.createFloatingButton()},i}(),Q=function(i){var t={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},n=[],o=function(i){t=r(r({},t),i),n.forEach((function(i){return i(t)}))};return{getState:function(){return t},initialize:function(){return s(void 0,void 0,void 0,(function(){var t,n,e;return d(this,(function(r){switch(r.label){case 0:if(!i.api_key)return D.trackError(Error(W[j](i.api_key)),"ChatbotStateManager",{errorCode:j,errorType:P,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,K(i)];case 2:return t=r.sent(),[4,new Promise((function(i,n){!function(n,e,r){if(n.chatbotId&&n.userId)try{new V(n),o({isInitialized:!0,chatbotConfig:t}),i(),l.log("Robylon SDK initialized successfully.")}catch(i){r(i instanceof Error?i.message:"Failed to initialize SDK")}else r("Incomplete configuration for SDK initialization.")}(t,0,(function(i){n(i)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),e=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:e}),D.trackError(n instanceof Error?n:Error(e),"ChatbotStateManager",{errorCode:z,errorType:P,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!t.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o,subscribe:function(i){return n.push(i),function(){var t=n.indexOf(i);t>-1&&n.splice(t,1)}},unsubscribe:function(i){var t=n.indexOf(i);t>-1&&n.splice(t,1)}}},q=function(i){i.api_key,i.user_profile;var t=i.onEvent;return i.chatbotConfig,{emit:function(i,n){var o={type:i,timestamp:Date.now(),data:n};null==t||t(o)},onInternalEvent:function(i,t){}}},X=function(){function i(i){var t=this;this.container=null,this.floatingButton=null,this.launcherDelayTimeout=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(i){var n,o,e,r,s;if(!t.isDestroyed){var d=i.isInitialized,a=i.error,l=i.chatbotConfig,u=i.isIframeVisible;if(!a&&l&&d){if(t.eventEmitter=q({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:l.isAnonymous,userId:l.userId}}),t.container||(t.container=new B(l,t.config.position,t.config.sideSpacing,t.config.bottomSpacing)),t.iframe)t.iframe.update({config:l,isVisible:u,position:t.config.position,bottomSpacing:t.config.bottomSpacing});else if(t.iframe=new H({config:l,isVisible:u,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,bottomSpacing:t.config.bottomSpacing}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var c=t.iframe.getElement();c&&t.container&&t.container.getElement().prepend(c)}var h=!0===(null==l?void 0:l.show_launcher),v=!0===(null===(n=null==l?void 0:l.launcher_delay)||void 0===n?void 0:n.enabled),f=null!==(s=null!==(e=null===(o=null==l?void 0:l.launcher_delay)||void 0===o?void 0:o.seconds)&&void 0!==e?e:null===(r=null==l?void 0:l.launcher_delay)||void 0===r?void 0:r.delay)&&void 0!==s?s:0,p=function(){if(t.floatingButton)t.floatingButton.update({config:l,isIframeVisible:u,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing});else if(t.floatingButton=new _({config:l,toggleIframe:t.toggleIframe,isIframeVisible:u,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var i=t.floatingButton.getElement();i&&t.container&&t.container.getElement().appendChild(i)}};t.launcherDelayTimeout&&(clearTimeout(t.launcherDelayTimeout),t.launcherDelayTimeout=null),h?v&&+f>0&&!t.floatingButton?t.launcherDelayTimeout=window.setTimeout((function(){p(),t.launcherDelayTimeout=null}),1e3*+f):p():t.floatingButton&&(t.floatingButton.destroy(),t.floatingButton=null)}}},this.toggleIframe=function(){var i=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(i.isIframeVisible?c.CHATBOT_CLOSED:c.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(c.CHATBOT_CLOSED)};var n=r(r({},i),{position:"string"==typeof i.position?"left"===i.position.toLowerCase()?"Left":"right"===i.position.toLowerCase()?"Right":void 0:void 0,sideSpacing:"string"==typeof i.sideSpacing?""===i.sideSpacing||isNaN(+i.sideSpacing)?void 0:+i.sideSpacing:i.sideSpacing,bottomSpacing:"string"==typeof i.bottomSpacing?""===i.bottomSpacing||isNaN(+i.bottomSpacing)?void 0:+i.bottomSpacing:i.bottomSpacing});if(this.config=n,!i.api_key)throw D.trackError(Error(W[j](i.api_key)),"RobylonChatbot",{errorCode:j,errorType:P,context:{timestamp:Date.now()}}),Error("API key is required");try{D.initialize(i.api_key,i.user_id)}catch(i){D.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot",{errorCode:M,errorType:P,context:{timestamp:Date.now()}})}this.stateManager=Q({api_key:i.api_key,user_id:i.user_id,user_token:i.user_token,user_profile:i.user_profile}),this.eventEmitter=q({api_key:i.api_key,user_profile:i.user_profile,onEvent:i.onEvent,chatbotConfig:null}),window.RobylonShouldShowProactive=y,window.RobylonHideProactive=g,this.initialize()}return i.prototype.initialize=function(){return s(this,void 0,void 0,(function(){var i;return d(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.stateManager.initialize()];case 1:return t.sent(),this.stateManager.subscribe(this.handleStateChange),this.handleStateChange(this.stateManager.getState()),[3,3];case 2:return i=t.sent(),D.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot.initialize",{errorCode:z,errorType:P,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},i.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(c.CHATBOT_BUTTON_CLICKED))},i.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(c.CHATBOT_CLOSED))},i.prototype.toggle=function(){this.toggleIframe()},i.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.launcherDelayTimeout&&(clearTimeout(this.launcherDelayTimeout),this.launcherDelayTimeout=null),this.iframe&&(this.iframe.destroy(),this.iframe=null),this.container&&(this.container.destroy(),this.container=null),this.stateManager.unsubscribe(this.handleStateChange)},i.prototype.getState=function(){return this.stateManager.getState().isInitialized?"initialized":"uninitialized"},i}();function $(i){return new X(i)}"undefined"!=typeof window&&function(){if("undefined"!=typeof window){var i=window.RobylonChatbot;if(i&&Array.isArray(i.q)){var t=null;i.q.forEach((function(i){var n=i[0];if("init"===n){var o=i[1]||{};t=$(o)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(i){var n=[].slice.call(arguments,1);return"init"===i?t=$(n[0]||{}):t&&"function"==typeof t[i]?t[i].apply(t,n):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var ii={create:$,getState:function(){return"initialized"}};i.create=$,i.default=ii,Object.defineProperty(i,"i",{value:!0})}));
|
|
1
|
+
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((i="undefined"!=typeof globalThis?globalThis:i||self).RobylonChatbot={})}(this,(function(i){"use strict";var t,n,o,e,r=function(){return r=Object.assign||function(i){for(var t,n=1,o=arguments.length;o>n;n++)for(var e in t=arguments[n])({}).hasOwnProperty.call(t,e)&&(i[e]=t[e]);return i},r.apply(this,arguments)};function s(i,t,n,o){return new(n||(n=Promise))((function(e,r){function s(i){try{a(o.next(i))}catch(i){r(i)}}function d(i){try{a(o.throw(i))}catch(i){r(i)}}function a(i){var t;i.done?e(i.value):(t=i.value,t instanceof n?t:new n((function(i){i(t)}))).then(s,d)}a((o=o.apply(i,t||[])).next())}))}function d(i,t){var n,o,e,r={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=d(0),s.throw=d(1),s.return=d(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function d(d){return function(a){return function(d){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,d[0]&&(r=0)),r;)try{if(n=1,o&&(e=2&d[0]?o.return:d[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,d[1])).done)return e;switch(o=0,e&&(d=[2&d[0],e.value]),d[0]){case 0:case 1:e=d;break;case 4:return r.label++,{value:d[1],done:!1};case 5:r.label++,o=d[1],d=[0];continue;case 7:d=r.ops.pop(),r.trys.pop();continue;default:if(!((e=(e=r.trys).length>0&&e[e.length-1])||6!==d[0]&&2!==d[0])){r=0;continue}if(3===d[0]&&(!e||d[1]>e[0]&&d[1]<e[3])){r.label=d[1];break}if(6===d[0]&&r.label<e[1]){r.label=e[1],e=d;break}if(e&&r.label<e[2]){r.label=e[2],r.ops.push(d);break}e[2]&&r.ops.pop(),r.trys.pop();continue}d=t.call(i,r)}catch(i){d=[6,i],o=0}finally{n=e=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([d,a])}}}"function"==typeof SuppressedError&&SuppressedError,function(i){i.WIDGET="WIDGET",i.POPOVER="POPOVER",i.EMBED="EMBED"}(t||(t={})),function(i){i.RIGHT="Right",i.LEFT="Left"}(n||(n={})),function(i){i.TEXT="TEXT",i.IMAGE="IMAGE",i.TEXTUAL_IMAGE="TEXTUAL_IMAGE"}(o||(o={})),function(i){i.WORKING_HOURS="WORKING_HOURS",i.ALWAYS="ALWAYS"}(e||(e={}));var a=function(i,t){void 0===t&&(t=.5);var n,o,e,r,s=function(i){i=i.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(function(i,t,n,o){return t+t+n+n+o+o}));var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}}(i);return(n=s.r,o=s.g,e=s.b,.2126*(r=[n,o,e].map((function(i){return(i/=255)>.03928?Math.pow((i+.055)/1.055,2.4):i/12.92})))[0]+.7152*r[1]+.0722*r[2])>t?"#0E0E0F":"#FFFFFF"},l={log:function(){},error:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.error.apply(console,i)},warn:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t];console.warn.apply(console,i)},info:function(){}};l.log("Raw API_URL:","https://stage-api.robylon.ai");var u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};l.log("CONFIG",u);var c,h,v=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},f=function(){return{copilotUrl:u.copilotUrl||"https://app.robylon.ai",environment:u.environment||"production",apiUrl:u.apiUrl||"https://app.robylon.ai"}};!function(i){i.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",i.CHATBOT_BUTTON_CLICKED="CHATBOT_BUTTON_CLICKED",i.CHATBOT_OPENED="CHATBOT_OPENED",i.CHATBOT_CLOSED="CHATBOT_CLOSED",i.CHATBOT_APP_READY="CHATBOT_APP_READY",i.CHATBOT_LOADED="CHATBOT_LOADED",i.CHAT_INITIALIZED="CHAT_INITIALIZED",i.SESSION_REFRESHED="SESSION_REFRESHED",i.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED",i.CHATBOT_READY="CHATBOT_READY"}(c||(c={})),function(i){i.CHAT_MOVED="CHAT_MOVED",i.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(h||(h={}));var p,m="system-ui, Inter, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",w="21px",b=!1,g=function(){b=!0};console.log("isProactiveHiddenThisPage",(function(){return b}));var x,I=((p={})[e.WORKING_HOURS]=function(i,t){var n=t.getHours(),o=t.getMinutes();return(n>10||10===n&&o>=0)&&(19>n||19===n&&0===o)},p[e.ALWAYS]=function(i,t){return!0},p),y=function(i,t){var n;if(void 0===t&&(t=new Date),console.log("proactiveHiddenThisPage shouldShowProactiveMessage",b),!(null===(n=null==i?void 0:i.content)||void 0===n?void 0:n.trim()))return!1;if(b)return!1;var o=(null==i?void 0:i.send_time_type)||"";if(!o)return!0;var e=I[o];return!!e&&e(i,t)},_=function(){function i(i){var t=this;this.resizeObserver=null,this.proactiveElement=null,this.config=i,this.buttonElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.render(),this.mount();try{this.buttonElement.style.opacity="0",this.buttonElement.style.transition="transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 280ms ease",requestAnimationFrame((function(){t.buttonElement.style.opacity="1"}))}catch(i){}this.setupResizeListener(),this.renderProactiveIfNeeded()}return i.prototype.render=function(){var i=this;f().copilotUrl;var t=this.config,n=t.config,e={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97)",transform:t.isIframeVisible?"scale(0.85)":"scale(1)",fontFamily:m};n.launcher_type===o.IMAGE&&Object.assign(e,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:n.brand_colour}),this.applyResponsiveStyles(e),this.buttonElement.className="message-bubble-container",this.buttonElement.innerHTML="",this.buttonElement.appendChild(this.createLauncherElement()),this.buttonElement.onclick=function(){i.config.toggleIframe()},this.renderProactiveIfNeeded()},i.prototype.createLauncherElement=function(){var i,t,n=this.config,e=n.config,r=n.isIframeVisible,s=f().copilotUrl;switch(console.log("config in floating button",e),e.launcher_type){case o.TEXT:return this.createTextLauncher();case o.TEXTUAL_IMAGE:return this.createTextualImageLauncher();case o.IMAGE:default:if(r){var d=document.createElement("div");return d.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 ',d}var a=document.createElement("img");return a.src=e.launcher_type?(null===(t=null===(i=e.images)||void 0===i?void 0:i.launcher_image_url)||void 0===t?void 0:t.url)||"".concat(s,"/chatbubble.png"):e.image_url||"".concat(s,"/chatbubble.png"),a.alt="Chat",Object.assign(a.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%",boxSizing:"border-box"}),a}},i.prototype.createTextLauncher=function(){var i=this.config.config,t=i.brand_colour,n=i.launcher_properties,o=document.createElement("div");Object.assign(o.style,{width:"fit-content",maxWidth:"160px",height:"40px",borderRadius:"9999px",backgroundColor:t,display:"flex",alignItems:"center",padding:"9px 20px",boxShadow:"0px 0px 16px 0px rgba(0, 0, 0, 0.24)",boxSizing:"border-box"});var e=document.createElement("div");Object.assign(e.style,{flex:"1",minWidth:"0"});var r=document.createElement("p");return Object.assign(r.style,{margin:"0",color:a(t),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:w,fontFamily:m,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),r.textContent=(null==n?void 0:n.text)||"",e.appendChild(r),o.appendChild(e),o},i.prototype.createTextualImageLauncher=function(){var i,t,n,o,e,r,s=f().copilotUrl,d=this.config.config,l=d.brand_colour,u=d.launcher_properties,c=d.image_url,h=document.createElement("div");Object.assign(h.style,{maxWidth:"13rem",width:"fit-content",height:"40px",borderRadius:"9999px",backgroundColor: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 v=document.createElement("div");Object.assign(v.style,{flex:"1",minWidth:"0"});var p=document.createElement("p");Object.assign(p.style,{margin:"0",color:a(l),fontSize:"0.875rem",fontWeight:"600",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:w,fontFamily:m,WebkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",textSizeAdjust:"100%"}),p.textContent=(null==u?void 0:u.text)||"";var b=document.createElement("div");Object.assign(b.style,{width:"40px",height:"40px",borderRadius:"9999px",overflow:"hidden",position:"relative",flexShrink:"0"});var g=document.createElement("img");return g.src=(null===(t=null===(i=null==this?void 0:this.config)||void 0===i?void 0:i.config)||void 0===t?void 0:t.launcher_type)?(null===(r=null===(e=null===(o=null===(n=null==this?void 0:this.config)||void 0===n?void 0:n.config)||void 0===o?void 0:o.images)||void 0===e?void 0:e.launcher_image_url)||void 0===r?void 0:r.url)||"".concat(s,"/chatbubble.png"):c||"".concat(s,"/chatbubble.png"),g.alt="Chat",Object.assign(g.style,{width:"100%",height:"100%",objectFit:"cover"}),v.appendChild(p),b.appendChild(g),h.appendChild(v),h.appendChild(b),h},i.prototype.applyResponsiveStyles=function(i){var t,n,o,e,s,d,a,l,u,c=560>(null===window||void 0===window?void 0:window.innerWidth),h=this.config.config,v=this.config.position||(null===(o=h.interface_properties)||void 0===o?void 0:o.position)||"Right",f=null!==(d=null!==(e=this.config.sideSpacing)&&void 0!==e?e:null===(s=h.interface_properties)||void 0===s?void 0:s.side_spacing)&&void 0!==d?d:20,p=null!==(u=null!==(a=this.config.bottomSpacing)&&void 0!==a?a:null===(l=h.interface_properties)||void 0===l?void 0:l.bottom_spacing)&&void 0!==u?u:20;this.buttonElement.style.position="",this.buttonElement.style.bottom="",this.buttonElement.style.right="",this.buttonElement.style.left="";var m=r(r({},i),c?((t={position:"fixed",bottom:"".concat(p,"px")})[v.toLowerCase()]="".concat(f,"px"),t):((n={bottom:"".concat(p,"px")})[v.toLowerCase()]="".concat(f,"px"),n));Object.assign(this.buttonElement.style,m)},i.prototype.handleResize=function(){var i={zIndex:"1000",display:"flex",flexDirection:"column-reverse",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden",marginTop:"16px",borderRadius:this.config.config.launcher_type&&this.config.config.launcher_type!==o.IMAGE?"9999px":"50%",boxSizing:"border-box"};this.config.config.launcher_type===o.IMAGE&&Object.assign(i,{width:"48px",height:"48px",borderRadius:"50%",backgroundColor:this.config.config.brand_colour}),this.applyResponsiveStyles(i)},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.getElement=function(){return this.buttonElement},i.prototype.mount=function(){var i=this;requestAnimationFrame((function(){var t,n;null===(n=(t=i.config).onEvent)||void 0===n||n.call(t,{type:c.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),i.config.onInternalEvent(c.CHATBOT_BUTTON_LOADED)}))},i.prototype.update=function(i){this.config.isIframeVisible,this.config=r(r({},this.config),i),this.buttonElement.style.transform=this.config.isIframeVisible?"scale(0.85)":"scale(1)",this.render(),this.renderProactiveIfNeeded()},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement),this.proactiveElement&&this.proactiveElement.parentElement&&(this.proactiveElement.parentElement.removeChild(this.proactiveElement),this.proactiveElement=null)},i.prototype.renderProactiveIfNeeded=function(){var i,t,n,e,r,s,d,a,l,u=this,c=null===(t=null===(i=this.config)||void 0===i?void 0:i.config)||void 0===t?void 0:t.proactive_message_obj;if(!y(c)||this.config.isIframeVisible)return this.proactiveElement&&this.proactiveElement.parentElement&&this.proactiveElement.parentElement.removeChild(this.proactiveElement),void(this.proactiveElement=null);if(!this.proactiveElement){var h=document.createElement("div");h.style.position="fixed";var v=null!==(r=null!==(n=this.config.bottomSpacing)&&void 0!==n?n:null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.bottom_spacing)&&void 0!==r?r:20,f=null!==(a=null!==(s=this.config.sideSpacing)&&void 0!==s?s:null===(d=this.config.config.interface_properties)||void 0===d?void 0:d.side_spacing)&&void 0!==a?a:20,p=this.config.position||(null===(l=this.config.config.interface_properties)||void 0===l?void 0:l.position)||"Right";h.style.bottom="".concat(v+(this.config.config.launcher_type===o.IMAGE?48:40)+8,"px"),"Right"===p?h.style.right="".concat(f,"px"):h.style.left="".concat(f,"px"),h.style.maxWidth="22.875rem",h.style.zIndex="2147483646";var b=document.createElement("div");b.style.background="#fff",b.style.color="#111",b.style.borderRadius="16px",b.style.boxShadow="0 0 40px 0 rgba(14, 14, 15, 0.24)",b.style.padding="16px",b.style.cursor="pointer",b.style.fontFamily=m,b.style.fontSize="14px",b.style.lineHeight=w+"",b.textContent=(null==c?void 0:c.content)||"",b.onclick=function(){u.config.toggleIframe(),g()};var x=document.createElement("div");x.style.position="absolute",x.style.top="-32px",x.style.width="24px",x.style.height="24px",x.style.borderRadius="50%",x.style.background="#fff",x.style.boxShadow="0 2.667px 2.667px 0 rgba(0, 0, 0, 0.25)",x.style.display="flex",x.style.alignItems="center",x.style.justifyContent="center",x.style.cursor="pointer","Right"===p?(x.style.right="0px",x.style.left="auto"):(x.style.left="0px",x.style.right="auto"),x.onclick=function(i){i.stopPropagation(),g(),u.proactiveElement&&u.proactiveElement.parentElement&&u.proactiveElement.parentElement.removeChild(u.proactiveElement),u.proactiveElement=null},x.innerHTML='\n <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none">\n <path d="M10.3334 10.3334L7.00009 7.00009M7.00009 7.00009L3.66675 3.66675M7.00009 7.00009L10.3334 3.66675M7.00009 7.00009L3.66675 10.3334" stroke="#444547" stroke-width="0.816326" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n ',h.appendChild(b),h.appendChild(x),document.body.appendChild(h),this.proactiveElement=h}},i}(),E=function(){var i;return(null===(i=navigator.userAgentData)||void 0===i?void 0:i.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},S=function(){var i;if(null===(i=navigator.userAgentData)||void 0===i?void 0:i.brands)for(var t=["Chrome","Firefox","Safari","Edge","Opera"],n=0,o=navigator.userAgentData.brands;n<o.length;n++){var e=o[n];if(t.includes(e.brand))return e.brand}return(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},T=function(){var i,t,n,o;return{width:(null===window||void 0===window?void 0:window.innerWidth)||(null===(i=null===document||void 0===document?void 0:document.documentElement)||void 0===i?void 0:i.clientWidth)||(null===(t=null===document||void 0===document?void 0:document.body)||void 0===t?void 0:t.clientWidth),height:(null===window||void 0===window?void 0:window.innerHeight)||(null===(n=null===document||void 0===document?void 0:document.documentElement)||void 0===n?void 0:n.clientHeight)||(null===(o=null===document||void 0===document?void 0:document.body)||void 0===o?void 0:o.clientHeight)}},A=function(){return{platform:"web",os:E(),browser:S(),sdk_version:"1.1.40-staging.6",device:(i=navigator.userAgent.toLowerCase(),/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(i)?"tablet":/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(i)?"mobile":"desktop"),screen_size:T()};var i};!function(i){i.ERROR="ERROR",i.INFO="INFO"}(x||(x={}));var R,O=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],C=function(i){var t=i.filename,n=i.stack,o=i.message;return!!(t||n||o)&&O.some((function(i){return(null==t?void 0:t.includes(i))||(null==n?void 0:n.includes(i))||(null==o?void 0:o.includes(i))}))},k=function(){function i(){var i=this;this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.handleWindowError=function(t){var n,o={filename:t.filename,stack:null===(n=t.error)||void 0===n?void 0:n.stack,message:t.message};C(o)&&i.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})},this.handleUnhandledRejection=function(t){var n,o,e={stack:null===(n=t.reason)||void 0===n?void 0:n.stack,message:(null===(o=t.reason)||void 0===o?void 0:o.message)||t.reason+""};C(e)&&i.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return i.prototype.setupGlobalHandlers=function(){v()&&(null===window||void 0===window||window.addEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.addEventListener("unhandledrejection",this.handleUnhandledRejection))},i.prototype.cleanup=function(){v()&&(null===window||void 0===window||window.removeEventListener("error",null==this?void 0:this.handleWindowError),null===window||void 0===window||window.removeEventListener("unhandledrejection",this.handleUnhandledRejection))},i.getInstance=function(){return i.instance||(i.instance=new i),i.instance},i.prototype.initialize=function(i,t){void 0===t&&(t=null);try{if(this.preInitQueue.length>0){var n={org_id:"UNINITALIZED",event_data:{message:"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i)),componentName:"ErrorTrackingService",additionalInfo:{preInitError:!0,apiKey:i,userId:t,timestamp:Date.now()},timestamp:Date.now()},metadata:A(),event_type:x.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=i,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){l.error("Error during ErrorTrackingService initialization:",n),this.preInitQueue.push({error:n instanceof Error?n:Error(n+""),componentName:"ErrorTrackingService",additionalInfo:{apiKey:i,userId:t}})}},i.prototype.processPreInitQueue=function(){return s(this,void 0,void 0,(function(){var i,t,n;return d(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];l.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),i=0,t=this.preInitQueue,o.label=1;case 1:return i<t.length?(n=t[i],[4,this.trackError(n.error,n.componentName,r(r({},n.additionalInfo),{preInitError:!0}))]):[3,4];case 2:o.sent(),o.label=3;case 3:return i++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},i.prototype.sendLog=function(i){return s(this,void 0,void 0,(function(){var t,n,o,e,r,s;return d(this,(function(d){switch(d.label){case 0:return d.trys.push([0,4,,5]),t=f().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 1:return(n=d.sent()).ok?[3,3]:(e=(o=l).error,r=["Failed to send error log:"],[4,n.text()]);case 2:e.apply(o,r.concat([d.sent()])),d.label=3;case 3:return[3,5];case 4:return s=d.sent(),l.error("Error sending log:",s),[3,5];case 5:return[2]}}))}))},i.prototype.trackError=function(i,t,n){return s(this,void 0,void 0,(function(){var o,e,s;return d(this,(function(d){switch(d.label){case 0:if(this.isInitialized)return[3,5];o={org_id:"UNINITALIZED",event_data:{message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:r(r({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:A(),event_type:x.ERROR,user_id:this.userId},d.label=1;case 1:return d.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return d.sent(),[3,4];case 3:return d.sent(),this.preInitQueue.push({error:i,componentName:t,additionalInfo:n}),l.warn("Error tracked before initialization, queuing:",i),[3,4];case 4:return[2];case 5:return e={message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:t,additionalInfo:r(r({},n),{timestamp:Date.now()}),timestamp:Date.now()},s={org_id:this.apiKey||"UNINITALIZED",event_data:e,metadata:A(),event_type:x.ERROR,user_id:this.userId},[4,this.sendLog(s)];case 6:return d.sent(),[2]}}))}))},i.prototype.trackInfo=function(i,t,n){return s(this,void 0,void 0,(function(){var o,e;return d(this,(function(r){switch(r.label){case 0:return this.apiKey?(o={message:i,componentName:t,additionalInfo:n,timestamp:Date.now()},e={org_id:this.apiKey,event_data:o,metadata:A(),event_type:x.INFO,user_id:this.userId},[4,this.sendLog(e)]):(l.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},i}(),D=k.getInstance(),j="MISSING_API_KEY",z="SDK_INIT_FAILED",M="ERROR_TRACKING_INIT_FAILED",N="API_REQUEST_FAILED",U="NETWORK_ERROR",F="INVALID_RESPONSE",L="IFRAME_LOAD_FAILED",P="INITIALIZATION_ERROR",W=((R={})[j]=function(i){return"SDK Initialization Failed: Required parameter 'api_key' is ".concat(void 0===i?"undefined":null===i?"null":""===i?"empty string":"invalid: ".concat(i),". A valid API key string is required to initialize the SDK.")},R.INVALID_API_KEY=function(i){return"SDK Initialization Failed: Provided API key '".concat(i,"' is invalid. API key must be a non-empty string in UUID format.")},R.CONFIG_FETCH_FAILED=function(i){return"Failed to fetch chatbot configuration: ".concat(i.statusCode?"Server responded with status ".concat(i.statusCode):"Could not reach server").concat(i.error?". Error: ".concat(i.error):"")},R[N]=function(i,t,n){return"API Request Failed: Server responded with status ".concat(i," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},R[U]=function(i){return"Network Error: Failed to communicate with server".concat(i.url?" at ".concat(i.url):"").concat(i.error?" - ".concat(i.error):"")},R[L]=function(i){return"Failed to load chatbot interface".concat(i.src?" from ".concat(i.src):"").concat(i.error?". Error: ".concat(i.error):"")},R[F]=function(i){return"Invalid API Response: Missing required fields in response data: ".concat(i.join(", "))},R[M]=function(i){return"Error Tracking Service initialization failed".concat(i.apiKey?" for API key ".concat(i.apiKey):"").concat(i.error?". Error: ".concat(i.error):"")},R[z]=function(i){return"SDK Initialization Failed: ".concat(i.reason||"Could not initialize the chatbot SDK").concat(i.config?". Attempted initialization with config: ".concat(JSON.stringify(i.config,null,2)):"")},R.COOKIE_ACCESS_ERROR=function(i,t){return"Cookie Access Error: Failed to ".concat(i).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},R.COMPONENT_RENDER_ERROR=function(i){return"React Component Error: ".concat(i.component||"Unknown component"," failed to render. Error: ").concat(i.error).concat(i.stack?"\nComponent Stack: ".concat(i.stack):"")},R),H=function(){function i(i){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(i){var n,o,e,r,s,d,a,l,u,v,p,m,w,b,g,x=f().copilotUrl;if(i.origin===x){if("closeChatbot"===i.data)return void t.config.onClose();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=i.data)||void 0===n?void 0:n.type))return void t.config.onInternalEvent(h.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(o=i.data)||void 0===o?void 0:o.type)&&(null===(r=(e=t.config).onEvent)||void 0===r||r.call(e,{type:c.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(c.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(s=i.data)||void 0===s?void 0:s.type)&&(null===(a=(d=t.config).onEvent)||void 0===a||a.call(d,{type:c.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(c.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(l=i.data)||void 0===l?void 0:l.type)&&(null===(v=(u=t.config).onEvent)||void 0===v||v.call(u,{type:c.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(c.CHAT_INITIALIZATION_FAILED,{error:null===(p=i.data)||void 0===p?void 0:p.error})),"SESSION_REFRESHED"===(null===(m=i.data)||void 0===m?void 0:m.type)&&(null===(b=(w=t.config).onEvent)||void 0===b||b.call(w,{type:c.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(c.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=i.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(h.CHAT_MOVED,{from:i.data.from,to:i.data.to,trigger:i.data.trigger})}},this.config=i,this.iframeElement=document.createElement("iframe"),this.iframeElement.id="chat-iframe-rbyln",this.resizeHandler=this.applyResponsiveStyles.bind(this),this.render(),this.initialize(),this.setupEventListeners()}return i.prototype.getElement=function(){return this.iframeElement},i.prototype.render=function(){var i,t=this.config.position||(null===(i=this.config.config.interface_properties)||void 0===i?void 0:i.position)||"Right";Object.assign(this.iframeElement.style,{zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom ".concat(t.toLowerCase()),transition:"transform 0.2s cubic-bezier(0.2, 1.27, 0.29, 0.97), opacity 0.15s ease-out",transform:"scale(0.3) translate3d(0,40px,0)",opacity:"0",display:"none"}),this.applyResponsiveStyles()},i.prototype.applyResponsiveStyles=function(){var i,t,n,o,e,r;if(this.iframeElement){var s=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",d=null!==(r=null!==(o=this.config.bottomSpacing)&&void 0!==o?o:null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.bottom_spacing)&&void 0!==r?r:20;560>window.innerWidth?Object.assign(this.iframeElement.style,((i={width:"100vw",minWidth:"300px"})[s.toLowerCase()]="0",i.bottom="0",i.height="100vh",i.flexDirection="column",i.flexGrow="1",i.borderRadius="0",i.top="0",i.maxHeight="100%",i.position="fixed",i)):Object.assign(this.iframeElement.style,((t={width:"26%",minWidth:"400px",height:"calc(100vh - 2rem - 10vh - ".concat(d,"px)"),borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"50rem",position:""})[s.toLowerCase()]=void 0,t))}},i.prototype.initialize=function(){var i=this;if(!this.isInitialized){var t=f().copilotUrl;this.iframeElement.src="".concat(t,"/chatbot-plugin?id=").concat(this.config.config.chatbotId),this.isInitialized=!0,this.iframeElement.addEventListener("load",(function(){var n,o,e=new URL(i.iframeElement.src).origin||t;null===(n=i.iframeElement.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},e)}))}},i.prototype.setupEventListeners=function(){var i=this;window.addEventListener("resize",this.resizeHandler),this.iframeElement.addEventListener("error",(function(){D.trackError(Error(W[L]({src:i.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:L,errorType:"RUNTIME_ERROR",context:{config:i.config.config,iframeUrl:i.iframeElement.src,timestamp:Date.now()}})})),window.addEventListener("message",this.handleMessage)},i.prototype.updateVisibility=function(i){var t,n,o,e,r,s,d,a,l,u=this;this.config.isVisible=i;var h=this.config.position||(null===(t=this.config.config.interface_properties)||void 0===t?void 0:t.position)||"Right";if(i?(this.iframeElement.style.display="block",this.iframeElement.getBoundingClientRect(),this.iframeElement.style.opacity="1",this.iframeElement.style.transform="scale(1) translate3d(0,0,0)"):(this.iframeElement.style.opacity="0",this.iframeElement.style.transform="scale(0.3) translate3d(".concat((h.toLowerCase(),"0"),",40px,0)"),setTimeout((function(){u.config.isVisible||(u.iframeElement.style.display="none")}),200)),this.iframeElement.contentWindow&&i){var v=f().copilotUrl,p=new URL(this.iframeElement.src).origin||v;this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,name:"openFrame"},p),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,action:"registerUserId",data:{userId:null===(e=this.config.config)||void 0===e?void 0:e.userId,token:null===(r=this.config.config)||void 0===r?void 0:r.token,userProfile:null===(s=this.config.config)||void 0===s?void 0:s.userProfile,isAnonymous:null===(d=this.config.config)||void 0===d?void 0:d.isAnonymous}},p),this.hasRegistered=!0),null===(l=(a=this.config).onEvent)||void 0===l||l.call(a,{type:c.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(c.CHATBOT_OPENED)}},i.prototype.update=function(i){var t=this.config.isVisible;if(this.config=r(r({},this.config),i),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=f().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},n)}},i.prototype.destroy=function(){window.removeEventListener("resize",this.resizeHandler),window.removeEventListener("message",this.handleMessage),this.iframeElement&&this.iframeElement.parentNode&&this.iframeElement.parentNode.removeChild(this.iframeElement)},i}(),B=function(){function i(i,t,n,o){this.resizeObserver=null,this.containerElement=document.createElement("div"),this.handleResizeFunction=this.handleResize.bind(this),this.config={config:i,position:t,sideSpacing:n,bottomSpacing:o},this.render(),this.mount(),this.setupResizeListener()}return i.prototype.render=function(){this.applyStyles(),this.containerElement.className="robylon-chatbot-container"},i.prototype.applyStyles=function(){var i,t,n,o,e,s,d,a,l,u=560>(null===window||void 0===window?void 0:window.innerWidth),c=this.config.position||(null===(n=this.config.config.interface_properties)||void 0===n?void 0:n.position)||"Right",h=null!==(s=null!==(o=this.config.sideSpacing)&&void 0!==o?o:null===(e=this.config.config.interface_properties)||void 0===e?void 0:e.side_spacing)&&void 0!==s?s:20,v=null!==(l=null!==(d=this.config.bottomSpacing)&&void 0!==d?d:null===(a=this.config.config.interface_properties)||void 0===a?void 0:a.bottom_spacing)&&void 0!==l?l: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 f={position:"fixed",zIndex:"1000",display:"flex",flexDirection:"column"},p=r(r({},f),((i={bottom:"".concat(v,"px")})[c.toLowerCase()]="".concat(h,"px"),i.alignItems="Right"===c?"flex-end":"flex-start",i)),m=r(r({},f),((t={top:"0"})[c.toLowerCase()]="".concat(h,"px"),t.alignItems="center",t));Object.assign(this.containerElement.style,u?m:p)},i.prototype.handleResize=function(){this.applyStyles()},i.prototype.setupResizeListener=function(){"undefined"!=typeof ResizeObserver?(this.resizeObserver=new ResizeObserver(this.handleResizeFunction),this.resizeObserver.observe(document.body)):window.addEventListener("resize",this.handleResizeFunction)},i.prototype.mount=function(){document.body.appendChild(this.containerElement)},i.prototype.getElement=function(){return this.containerElement},i.prototype.destroy=function(){this.resizeObserver?(this.resizeObserver.disconnect(),this.resizeObserver=null):window.removeEventListener("resize",this.handleResizeFunction),this.containerElement&&this.containerElement.parentNode&&this.containerElement.parentNode.removeChild(this.containerElement)},i}(),J=function(i){var t=i?"USER_DATA=%7B%22attributes%22%3A%5B%7B%22key%22%3A%22USER_ATTRIBUTE_USER_EMAIL%22%2C%22value%22%3A%22dinesh.goel%40robylon.ai%22%7D%2C%7B%22key%22%3A%22USER_ATTRIBUTE_UNIQUE_ID%22%2C%22value%22%3A%2266011f2c28d1787d13c6c796%22%7D%5D%2C%22subscribedToOldSdk%22%3Afalse%2C%22deviceUuid%22%3A%2226c02feb-2664-451d-8469-9cf1378547c6%22%2C%22deviceAdded%22%3Atrue%7D; _ga_3YS9P6ZDWX=GS1.1.1715252584.3.1.1715258696.39.0.0; _ga_V4J24F7YF9=GS1.1.1715273274.2.0.1715273274.0.0.0; city_name=Bengaluru; lang_code=en-in; cookieConcent=A; _gcl_au=1.1.343275043.1717154298; _clck=43guwd%7C2%7Cfmi%7C0%7C1561; _gid=GA1.2.1423066649.1718210058; moe_uuid=26c02feb-2664-451d-8469-9cf1378547c6; _ga_6RM65PWEZY=GS1.1.1718210058.18.1.1718211647.60.0.0; _ga=GA1.1.689213983.1712737672; AMP_MKTG_fe4beb374f=JTdCJTIycmVmZXJyZXIlMjIlM0ElMjJodHRwcyUzQSUyRiUyRmFjY291bnRzLnRlYWNobWludC5jb20lMkYlMjIlMkMlMjJyZWZlcnJpbmdfZG9tYWluJTIyJTNBJTIyYWNjb3VudHMudGVhY2htaW50LmNvbSUyMiU3RA==; AMP_fe4beb374f=JTdCJTIyZGV2aWNlSWQlMjIlM0ElMjI0MWMxMTljZC03YzVjLTRiYTctYTUzZS1mYTgzMjRlYjc0OWUlMjIlMkMlMjJ1c2VySWQlMjIlM0ElMjIxZjI2ODAwOC01OGYxLTQwYTItYjQ0Ni1mYmQ5N2E0NDQyYTAlMjIlMkMlMjJzZXNzaW9uSWQlMjIlM0ExNzE4MjEzMzEwOTc3JTJDJTIyb3B0T3V0JTIyJTNBZmFsc2UlMkMlMjJsYXN0RXZlbnRUaW1lJTIyJTNBMTcxODIxMzMxMDk4MSUyQyUyMmxhc3RFdmVudElkJTIyJTNBMTQlN0Q=; _ga_3YS9P6ZDWX=GS1.1.1718211637.26.1.1718213441.60.0.0; SESSION=%7B%22sessionKey%22%3A%22e4d76f52-9053-4277-99a4-f1ba667fd5f2%22%2C%22sessionStartTime%22%3A%222024-06-12T16%3A34%3A19.047Z%22%2C%22sessionMaxTime%22%3A1800%2C%22customIdentifiersToTrack%22%3A%5B%5D%2C%22sessionExpiryTime%22%3A1718215247464%2C%22numberOfSessions%22%3A17%7D":document.cookie;return t=t.split(";").map((function(i){var t=i.split("="),n=t[0],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},Y=function(){var i,t=navigator.userAgent;if(null===(i=navigator.userAgentData)||void 0===i?void 0:i.brands){var n=navigator.userAgentData.brands.find((function(i){return"Google Chrome"===i.brand}));if(null==n?void 0:n.version)return n.version}var o=t.match(/(Chrome|Firefox|Safari|Edge|Opera)\/(\d+\.\d+)/);return o?o[2]:"Unknown"},Z=function(){var i,t,n=A();return{current_page_url:(null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.href)||"",browser_language:(null===navigator||void 0===navigator?void 0:navigator.language)||(null===(t=null===navigator||void 0===navigator?void 0:navigator.languages)||void 0===t?void 0:t[0])||"en",browser_version:Y(),os:null==n?void 0:n.os,referral_url:(null===document||void 0===document?void 0:document.referrer)||""}},G=function(i,t,n){return s(void 0,void 0,void 0,(function(){var o,e,r,s,a,u,c,h;return d(this,(function(d){switch(d.label){case 0:return d.trys.push([0,5,,6]),o=f().apiUrl,l.log("endpointUrl",e="".concat(o,"/chat/chatbot/get/")),r={client_user_id:t||null,org_id:i,token:n||void 0,extra_info:{},launcher_info:Z()},[4,fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(s=d.sent()).ok?[3,3]:[4,s.text()];case 2:throw a=d.sent(),Error(W[N](s.status,a));case 3:return[4,s.json()];case 4:if(u=d.sent(),!(null===(h=null==u?void 0:u.user)||void 0===h?void 0:h.org_info))throw Error(W[F](["user","org_info"]));return[2,u];case 5:throw c=d.sent(),D.trackError(c instanceof Error?c:Error(W[U]({error:c+""})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?N:U,errorType:"API_ERROR",context:{apiKey:i,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},K=function(i){return s(void 0,void 0,void 0,(function(){var e,s,a,l,u,c,h,v,f,p,m,w,b,g,x,I,y,_,E,S,T,R,O,C,k,D,j,z,M,N,U,F,L,P;return d(this,(function(d){switch(d.label){case 0:return e=function(i){return{api_key:(i.api_key||"")+"",user_id:i.user_id?i.user_id+"":null,user_token:i.user_token?i.user_token+"":void 0,user_profile:i.user_profile||{}}}(i),s=e.user_id||void 0,a=!1,s||(s=function(){var i,t="; ".concat(document.cookie).split("; rblyn_anon=");if(2===t.length)return null===(i=t.pop())||void 0===i?void 0:i.split(";").shift()}()||"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(i){var t=16*Math.random()|0;return("x"===i?t:3&t|8).toString(16)})),H=s,(B=new Date).setTime(B.getTime()+31536e6),document.cookie="".concat("rblyn_anon","=").concat(H,";expires=").concat(B.toUTCString(),";path=/"),a=!0),[4,G(e.api_key,s,e.user_token)];case 1:return l=d.sent(),u=A(),c=Z(),W=e.user_profile,h=W?Object.fromEntries(Object.entries(W).map((function(i){var t=i[0],n=i[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,n+""]}))):{},v=r(r(r({},u),{__INT_SYS_INFO__:r(r({},u),c)}),h),[2,{chatbotId:e.api_key,userId:s,token:e.user_token,isAnonymous:a,domain:"",show_launcher:null===(p=null===(f=l.user.org_info)||void 0===f?void 0:f.show_launcher)||void 0===p||p,brand_colour:(null===(w=null===(m=l.user.org_info.brand_config)||void 0===m?void 0:m.colors)||void 0===w?void 0:w.brand_color)||"",image_url:(null===(g=null===(b=l.user.org_info)||void 0===b?void 0:b.brand_config)||void 0===g?void 0:g.launcher_logo_url)||"",userProfile:v,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(x=l.user.org_info.brand_config)||void 0===x?void 0:x.display_name)||"",welcome_message:(null===(I=l.user.org_info.brand_config)||void 0===I?void 0:I.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(y=l.user.org_info.brand_config)||void 0===y?void 0:y.redirect_url)||""},launcher_type:(null===(_=l.user.org_info.brand_config)||void 0===_?void 0:_.launcher_type)||o.IMAGE,launcher_properties:{text:(null===(S=null===(E=l.user.org_info.brand_config)||void 0===E?void 0:E.launcher_properties)||void 0===S?void 0:S.text)||""},images:{launcher_image_url:{url:(null===(O=null===(R=null===(T=l.user.org_info.brand_config)||void 0===T?void 0:T.images)||void 0===R?void 0:R.launcher_image_url)||void 0===O?void 0:O.url)||""}},proactive_message_obj:(null===(D=null===(k=null===(C=null==l?void 0:l.user)||void 0===C?void 0:C.org_info)||void 0===k?void 0:k.brand_config)||void 0===D?void 0:D.proactive_message_obj)||void 0,interface_properties:{position:(null===(z=null===(j=l.user.org_info.brand_config)||void 0===j?void 0:j.interface_properties)||void 0===z?void 0:z.position)||n.RIGHT,side_spacing:(null===(N=null===(M=l.user.org_info.brand_config)||void 0===M?void 0:M.interface_properties)||void 0===N?void 0:N.side_spacing)||20,bottom_spacing:(null===(F=null===(U=l.user.org_info.brand_config)||void 0===U?void 0:U.interface_properties)||void 0===F?void 0:F.bottom_spacing)||20},interface_type:(null===(L=l.user.org_info.brand_config)||void 0===L?void 0:L.interface_type)||t.WIDGET,launcher_delay:(null===(P=l.user.org_info.brand_config)||void 0===P?void 0:P.launcher_delay)||{enabled:!1,delay:0}}]}var W,H,B}))}))},V=function(){function i(i){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=i,this.validateDomain()&&this.init(),null===window||void 0===window||window.addEventListener("message",this.onCloseListener.bind(this),!1)}return i.prototype.onCloseListener=function(i){i.origin===this.config.domain&&"closeChatbot"===i.data&&this.closeIframe()},i.prototype.validateDomain=function(){var i,t=this.config.domain,n=null===(i=null===window||void 0===window?void 0:window.location)||void 0===i?void 0:i.origin;return l.log("expectedDomain, to current domain",t,n,t===n),t===n},i.prototype.createChatBubblContainer=function(){var i,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var o=document.createElement("div");o.classList.add("close-btn"),o.textContent="✕",Object.assign(o.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(i=this.config.chat_interface_config)||void 0===i?void 0:i.chat_bubble_prompts)||[]).forEach((function(i){var o=t.createMessageBubble(i);n.appendChild(o)})),n.appendChild(o),document.body.appendChild(n)},i.prototype.createMessageBubble=function(i){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=i,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var o=document.createElement("button");return o.innerHTML="×",Object.assign(o.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),o.addEventListener("click",(function(){t.remove()})),t.appendChild(o),t.appendChild(n),t},i.prototype.createFloatingButton=function(){var i=document.createElement("div");i.classList.add("message-bubble-container"),Object.assign(i.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:a(this.config.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),document.body.appendChild(i),this.logoContainer=i,this.loadImage(this.logoContainer),this.createChatBubblContainer(),this.logoContainer.addEventListener("click",this.toggleIframe.bind(this))},i.prototype.loadImage=function(i){var t,n,o=document.createElement("img");o.src=this.config.launcher_type?(null===(n=null===(t=this.config.images)||void 0===t?void 0:t.launcher_image_url)||void 0===n?void 0:n.url)||"".concat(this.config.domain,"/chatbubble.png"):this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),o.alt="Chat",Object.assign(o.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=o,i.innerHTML="",i.appendChild(o)},i.prototype.createIframe=function(){var i=this;l.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),l.log("iframe.src====>",t.src),document.body.appendChild(t),this.iframe=t;var n=function(){560>(null===window||void 0===window?void 0:window.innerWidth)?Object.assign(t.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(t.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"})};n(),null===window||void 0===window||window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o,e,r;if(i.iframe){var s=new URL(i.iframe.src).origin||i.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname,name:"checkDomain"},s),null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:null===(r=null===window||void 0===window?void 0:window.location)||void 0===r?void 0:r.hostname,action:"registerUserId",data:{userId:i.config.userId,token:i.config.token,userProfile:i.config.userProfile}},s)}})),null===window||void 0===window||window.addEventListener("message",(function(n){var o,e;if(n.origin===i.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===i.config.chatbotId,s={cookies:J(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:null===(o=null===window||void 0===window?void 0:window.location)||void 0===o?void 0:o.hostname};null===(e=t.contentWindow)||void 0===e||e.postMessage(s,i.config.domain||"*")}"expand"===n.data&&(i.adjustIframeWidth(),t.style.height="calc(100vh - 120px)",t.style.bottom="86px"),"collapse"===n.data&&Object.assign(t.style,{width:"26%",height:"calc(100vh - 32px - 10vh)",bottom:"86px",top:"calc(32px + 10vh)"})}}))},i.prototype.adjustIframeWidth=function(){if(this.iframe){var i=null===window||void 0===window?void 0:window.innerWidth;l.log("screenWidth",i),this.iframe.style.width=832>i?"".concat(i-64,"px"):"800px"}},i.prototype.loadSvgInline=function(i){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");i.innerHTML="",n&&i.appendChild(n)},i.prototype.toggleIcon=function(i,t){"block"===t.style.display?this.loadSvgInline(i):this.loadImage(i)},i.prototype.toggleIframe=function(){var i;if(l.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;l.log("toggleIframe"),null===(i=this.iframe.contentWindow)||void 0===i||i.postMessage({domain:null===window||void 0===window?void 0:window.location.hostname,name:"none"===this.iframe.style.display?"openFrame":"closeFrame"},t),this.iframe.style.display="none"===this.iframe.style.display?"block":"none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="block"===this.iframe.style.display?"none":"cover",this.bubblePromptContainer&&(this.bubblePromptContainer.style.display="none"),l.log("this.bubblePromptContainer",this.bubblePromptContainer)}},i.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},i.prototype.init=function(){this.createIframe(),this.createFloatingButton()},i}(),Q=function(i){var t={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},n=[],o=function(i){t=r(r({},t),i),n.forEach((function(i){return i(t)}))};return{getState:function(){return t},initialize:function(){return s(void 0,void 0,void 0,(function(){var t,n,e;return d(this,(function(r){switch(r.label){case 0:if(!i.api_key)return D.trackError(Error(W[j](i.api_key)),"ChatbotStateManager",{errorCode:j,errorType:P,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,K(i)];case 2:return t=r.sent(),[4,new Promise((function(i,n){!function(n,e,r){if(n.chatbotId&&n.userId)try{new V(n),o({isInitialized:!0,chatbotConfig:t}),i(),l.log("Robylon SDK initialized successfully.")}catch(i){r(i instanceof Error?i.message:"Failed to initialize SDK")}else r("Incomplete configuration for SDK initialization.")}(t,0,(function(i){n(i)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),e=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:e}),D.trackError(n instanceof Error?n:Error(e),"ChatbotStateManager",{errorCode:z,errorType:P,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!t.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o,subscribe:function(i){return n.push(i),function(){var t=n.indexOf(i);t>-1&&n.splice(t,1)}},unsubscribe:function(i){var t=n.indexOf(i);t>-1&&n.splice(t,1)}}},q=function(i){i.api_key,i.user_profile;var t=i.onEvent;return i.chatbotConfig,{emit:function(i,n){var o={type:i,timestamp:Date.now(),data:n};null==t||t(o)},onInternalEvent:function(i,t){}}},X=function(){function i(i){var t=this;this.container=null,this.floatingButton=null,this.launcherDelayTimeout=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(i){var n,o,e,r,s;if(!t.isDestroyed){var d=i.isInitialized,a=i.error,l=i.chatbotConfig,u=i.isIframeVisible;if(!a&&l&&d){if(t.eventEmitter=q({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:l.isAnonymous,userId:l.userId}}),t.container||(t.container=new B(l,t.config.position,t.config.sideSpacing,t.config.bottomSpacing)),t.iframe)t.iframe.update({config:l,isVisible:u,position:t.config.position,bottomSpacing:t.config.bottomSpacing});else if(t.iframe=new H({config:l,isVisible:u,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,bottomSpacing:t.config.bottomSpacing}),t.iframe.getElement&&"function"==typeof t.iframe.getElement){var c=t.iframe.getElement();c&&t.container&&t.container.getElement().prepend(c)}var h=!0===(null==l?void 0:l.show_launcher),v=!0===(null===(n=null==l?void 0:l.launcher_delay)||void 0===n?void 0:n.enabled),f=null!==(s=null!==(e=null===(o=null==l?void 0:l.launcher_delay)||void 0===o?void 0:o.seconds)&&void 0!==e?e:null===(r=null==l?void 0:l.launcher_delay)||void 0===r?void 0:r.delay)&&void 0!==s?s:0,p=function(){if(t.floatingButton)t.floatingButton.update({config:l,isIframeVisible:u,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing});else if(t.floatingButton=new _({config:l,toggleIframe:t.toggleIframe,isIframeVisible:u,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent,position:t.config.position,sideSpacing:t.config.sideSpacing,bottomSpacing:t.config.bottomSpacing}),t.floatingButton.getElement&&"function"==typeof t.floatingButton.getElement){var i=t.floatingButton.getElement();i&&t.container&&t.container.getElement().appendChild(i)}};t.launcherDelayTimeout&&(clearTimeout(t.launcherDelayTimeout),t.launcherDelayTimeout=null),h?v&&+f>0&&!t.floatingButton?t.launcherDelayTimeout=window.setTimeout((function(){p(),t.launcherDelayTimeout=null}),1e3*+f):p():t.floatingButton&&(t.floatingButton.destroy(),t.floatingButton=null)}}},this.toggleIframe=function(){var i=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(i.isIframeVisible?c.CHATBOT_CLOSED:c.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(c.CHATBOT_CLOSED)};var n=r(r({},i),{position:"string"==typeof i.position?"left"===i.position.toLowerCase()?"Left":"right"===i.position.toLowerCase()?"Right":void 0:void 0,sideSpacing:"string"==typeof i.sideSpacing?""===i.sideSpacing||isNaN(+i.sideSpacing)?void 0:+i.sideSpacing:i.sideSpacing,bottomSpacing:"string"==typeof i.bottomSpacing?""===i.bottomSpacing||isNaN(+i.bottomSpacing)?void 0:+i.bottomSpacing:i.bottomSpacing});if(this.config=n,!i.api_key)throw D.trackError(Error(W[j](i.api_key)),"RobylonChatbot",{errorCode:j,errorType:P,context:{timestamp:Date.now()}}),Error("API key is required");try{D.initialize(i.api_key,i.user_id)}catch(i){D.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot",{errorCode:M,errorType:P,context:{timestamp:Date.now()}})}this.stateManager=Q({api_key:i.api_key,user_id:i.user_id,user_token:i.user_token,user_profile:i.user_profile}),this.eventEmitter=q({api_key:i.api_key,user_profile:i.user_profile,onEvent:i.onEvent,chatbotConfig:null}),window.RobylonShouldShowProactive=y,window.RobylonHideProactive=g,this.initialize()}return i.prototype.initialize=function(){return s(this,void 0,void 0,(function(){var i;return d(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.stateManager.initialize()];case 1:return t.sent(),this.stateManager.subscribe(this.handleStateChange),this.handleStateChange(this.stateManager.getState()),[3,3];case 2:return i=t.sent(),D.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot.initialize",{errorCode:z,errorType:P,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},i.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(c.CHATBOT_BUTTON_CLICKED))},i.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(c.CHATBOT_CLOSED))},i.prototype.toggle=function(){this.toggleIframe()},i.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.launcherDelayTimeout&&(clearTimeout(this.launcherDelayTimeout),this.launcherDelayTimeout=null),this.iframe&&(this.iframe.destroy(),this.iframe=null),this.container&&(this.container.destroy(),this.container=null),this.stateManager.unsubscribe(this.handleStateChange)},i.prototype.getState=function(){return this.stateManager.getState().isInitialized?"initialized":"uninitialized"},i}();function $(i){return new X(i)}"undefined"!=typeof window&&function(){if("undefined"!=typeof window){var i=window.RobylonChatbot;if(i&&Array.isArray(i.q)){var t=null;i.q.forEach((function(i){var n=i[0];if("init"===n){var o=i[1]||{};t=$(o)}else t&&"function"==typeof t[n]&&t[n]()})),window.RobylonChatbot=function(i){var n=[].slice.call(arguments,1);return"init"===i?t=$(n[0]||{}):t&&"function"==typeof t[i]?t[i].apply(t,n):void 0},window.RobylonChatbot.getState=function(){return"initialized"}}}}();var ii={create:$,getState:function(){return"initialized"}};i.create=$,i.default=ii,Object.defineProperty(i,"i",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=robylon-chatbot.js.map
|