@robylon/web-react-sdk 1.1.34-staging.3 → 1.1.34-staging.4

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 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=function(){return n=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},n.apply(this,arguments)};function i(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 o(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;var r=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"},a={log:function(){},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},info:function(){}};a.log("Raw API_URL:","https://stage-api.robylon.ai");var s={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};a.log("CONFIG",s);var l,c,d=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},u=function(){return{copilotUrl:s.copilotUrl||"https://app.robylon.ai",environment:s.environment||"production",apiUrl:s.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"}(l||(l={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(c||(c={}));var f,p=e.memo((function(t){var n=t.config,i=t.toggleIframe,o=t.isIframeVisible,s=t.onEvent,c=t.onInternalEvent,d=e.useRef(null),f=u().copilotUrl;e.useEffect((function(){d.current&&requestAnimationFrame((function(){null==s||s({type:l.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),c(l.CHATBOT_BUTTON_LOADED)}))}),[s,c]);return a.log("config chabotfloatingbutton",n),e.createElement("div",{ref:d,className:"message-bubble-container",style:{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:1e3,width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:n.brand_colour,color:r(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:i},o?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","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"}))):e.createElement("img",{src:n.image_url||"".concat(f,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))})),m=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]},h=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]},v=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)}},g=function(){return{platform:"web",os:m(),browser:h(),sdk_version:"1.1.34-staging.9",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:v()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(f||(f={}));var b,E=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],w=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&E.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))}))},y=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};w(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)};w(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){d()&&(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(){d()&&(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:g(),event_type:f.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){a.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 i(this,void 0,void 0,(function(){var e,t,i;return o(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];a.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,o.label=1;case 1:return e<t.length?(i=t[e],[4,this.trackError(i.error,i.componentName,n(n({},i.additionalInfo),{preInitError:!0}))]):[3,4];case 2:o.sent(),o.label=3;case 3:return e++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},e.prototype.sendLog=function(e){return i(this,void 0,void 0,(function(){var t,n,i,r,s,l;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),t=u().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=o.sent()).ok?[3,3]:(r=(i=a).error,s=["Failed to send error log:"],[4,n.text()]);case 2:r.apply(i,s.concat([o.sent()])),o.label=3;case 3:return[3,5];case 4:return l=o.sent(),a.error("Error sending log:",l),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,r){return i(this,void 0,void 0,(function(){var i,s,l;return o(this,(function(o){switch(o.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:n(n({},r),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:g(),event_type:f.ERROR,user_id:this.userId},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return o.sent(),[3,4];case 3:return o.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:r}),a.warn("Error tracked before initialization, queuing:",e),[3,4];case 4:return[2];case 5:return s={message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:n(n({},r),{timestamp:Date.now()}),timestamp:Date.now()},l={org_id:this.apiKey||"UNINITALIZED",event_data:s,metadata:g(),event_type:f.ERROR,user_id:this.userId},[4,this.sendLog(l)];case 6:return o.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return i(this,void 0,void 0,(function(){var i,r;return o(this,(function(o){switch(o.label){case 0:return this.apiKey?(i={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},r={org_id:this.apiKey,event_data:i,metadata:g(),event_type:f.INFO,user_id:this.userId},[4,this.sendLog(r)]):(a.error("Error tracking not initialized"),[2]);case 1:return o.sent(),[2]}}))}))},e}(),_=y.getInstance(),I="MISSING_API_KEY",C="INVALID_API_KEY",T="CONFIG_FETCH_FAILED",x="SDK_INIT_FAILED",A="ERROR_TRACKING_INIT_FAILED",O="API_REQUEST_FAILED",k="NETWORK_ERROR",D="INVALID_RESPONSE",S="IFRAME_LOAD_FAILED",R="COOKIE_ACCESS_ERROR",N="COMPONENT_RENDER_ERROR",L="INITIALIZATION_ERROR",M="API_ERROR",H="RUNTIME_ERROR",B="COMPONENT_ERROR",U=((b={})[I]=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[C]=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[T]=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[O]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},b[k]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},b[S]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},b[D]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},b[A]=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[x]=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[R]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},b[N]=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),z=e.memo((function(t){var n=t.config,i=t.isVisible,o=t.onClose,r=t.onEvent,a=t.onInternalEvent,s=e.useRef(null),d=e.useRef(!1),f=e.useRef(!1),p=e.useCallback((function(){var e=s.current;e&&((null===window||void 0===window?void 0:window.innerWidth)<560?(e.style.width="100vw",e.style.minWidth="300px",e.style.right="0",e.style.bottom="0",e.style.height="100vh",e.style.flexDirection="column",e.style.flexGrow="1",e.style.borderRadius="0",e.style.top="0",e.style.maxHeight="100%"):(e.style.width="26%",e.style.minWidth="400px",e.style.right="32px",e.style.bottom="86px",e.style.height="calc(100vh - 3rem - 10vh)",e.style.borderRadius="1rem",e.style.top="calc(10vh - 32px)",e.style.maxHeight="45rem"))}),[a]);return e.useEffect((function(){return null===window||void 0===window||window.addEventListener("resize",p),p(),function(){return null===window||void 0===window?void 0:window.removeEventListener("resize",p)}}),[p]),e.useEffect((function(){var e=s.current;if(e&&!d.current){var t=u().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(n.chatbotId),d.current=!0;var i=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",i),function(){return e.removeEventListener("load",i)}}}),[n.chatbotId]),e.useEffect((function(){var e,t,o,r,a=s.current;if(a&&d.current){var l=u().copilotUrl;if(a.style.display=i?"block":"none",a.contentWindow&&i){var c=new URL(a.src).origin||l;null===(e=null==a?void 0:a.contentWindow)||void 0===e||e.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},c),(null==f?void 0:f.current)||(null===(o=a.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:null==n?void 0:n.userId,token:null==n?void 0:n.token,userProfile:null==n?void 0:n.userProfile,isAnonymous:null==n?void 0:n.isAnonymous}},c),f.current=!0)}}}),[i,n.userId,n.token,n.userProfile]),e.useEffect((function(){if(s.current&&d.current){var e=u().copilotUrl;i&&(null==r||r({type:l.CHATBOT_OPENED,timestamp:Date.now()}),a(l.CHATBOT_OPENED));var t=function(t){var n,i,s,d,u,f,p;if(t.origin===e){if("closeChatbot"===t.data)return void o();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void a(c.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==r||r({type:l.CHATBOT_LOADED,timestamp:Date.now()}),a(l.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(s=t.data)||void 0===s?void 0:s.type)&&(null==r||r({type:l.CHAT_INITIALIZED,timestamp:Date.now()}),a(l.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(d=t.data)||void 0===d?void 0:d.type)&&(null==r||r({type:l.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),a(l.CHAT_INITIALIZATION_FAILED,{error:null===(u=t.data)||void 0===u?void 0:u.error})),"SESSION_REFRESHED"===(null===(f=t.data)||void 0===f?void 0:f.type)&&(null==r||r({type:l.SESSION_REFRESHED,timestamp:Date.now()}),a(l.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(p=t.data)||void 0===p?void 0:p.type)&&a(c.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)}}}),[o,r,a,n.chatbotId,i]),e.useEffect((function(){var e=s.current;if(e&&d.current){var t=function(){_.trackError(new Error(U[S]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:S,errorType:H,context:{config:n,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[n]),e.useEffect((function(){var e;if(s.current&&n&&i){var t=s.current,o=u().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:n.userProfile},o)}}),[n.userProfile,i]),e.createElement("iframe",{ref:s,id:"chat-iframe-rbyln",style:{position:"fixed",zIndex:2e7,border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:i?"block":"none"}})})),j=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){_.trackError(new Error(U[N]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:N,errorType:B,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},n.prototype.render=function(){return this.state.hasError?null:this.props.children},n}(e.Component),F=function(e,t,n){return i(void 0,void 0,void 0,(function(){var i,r,s,l,c,d,f,p;return o(this,(function(o){switch(o.label){case 0:i=u().apiUrl,r="".concat(i,"/chat/chatbot/get/"),a.log("endpointUrl",r),s={client_user_id:t,org_id:e,token:n||void 0,extra_info:{}},o.label=1;case 1:return o.trys.push([1,6,,7]),[4,fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 2:return(l=o.sent()).ok?[3,4]:[4,l.text()];case 3:throw c=o.sent(),new Error(U[O](l.status,c));case 4:return[4,l.json()];case 5:if(d=o.sent(),!(null===(p=null==d?void 0:d.user)||void 0===p?void 0:p.org_info))throw new Error(U[D](["user","org_info"]));return[2,d];case 6:throw f=o.sent(),_.trackError(f instanceof Error?f:new Error(U[k]({error:String(f)})),"fetchChatbotConfig",{errorCode:f instanceof Error&&f.message.includes("API Request Failed")?O:k,errorType:M,context:{chatbotId:e,userId:t,apiUrl:i,statusCode:f instanceof Response?f.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),f;case 7:return[2]}}))}))},P=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)}))},W=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()},V=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=/")},K=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},J=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 a.log("expectedDomain, to current domain",t,n,t===n),t===n},e.prototype.createChatBubblContainer=function(){var e,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var i=document.createElement("div");i.classList.add("close-btn"),i.textContent="✕",Object.assign(i.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var i=t.createMessageBubble(e);n.appendChild(i)})),n.appendChild(i),document.body.appendChild(n)},e.prototype.createMessageBubble=function(e){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=e,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var i=document.createElement("button");return i.innerHTML="&times;",Object.assign(i.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),i.addEventListener("click",(function(){t.remove()})),t.appendChild(i),t.appendChild(n),t},e.prototype.createFloatingButton=function(){var e=document.createElement("div");e.classList.add("message-bubble-container"),Object.assign(e.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:r(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=document.createElement("img");t.src=this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),t.alt="Chat",Object.assign(t.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=t,e.innerHTML="",e.appendChild(t)},e.prototype.createIframe=function(){var e=this;a.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),a.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:K(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;a.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(a.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;a.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"),a.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}(),Z=function(e,t,n){if(e.chatbotId&&e.userId)try{new J(e);t(!0),a.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},Y=function(t){var r=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)]),a=e.useState({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),s=a[0],l=a[1],c=e.useMemo((function(){var e=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"];return r.user_profile?Object.fromEntries(Object.entries(r.user_profile).filter((function(t){var n=t[0];return e.includes(n)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(r.user_profile)]),d=e.useCallback((function(e){l((function(t){return n(n({},t),e)}))}),[]),u=e.useCallback((function(){return i(void 0,void 0,void 0,(function(){var e,t,i,a,s,l,u,f,p,m,h,v,b,E,w;return o(this,(function(o){switch(o.label){case 0:if(!r.api_key)return _.trackError(new Error(U[I](r.api_key)),"useChatbotState",{errorCode:I,errorType:L,context:{timestamp:Date.now()}}),[2];d({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),e=r.user_id||void 0,t=!1,e||(e=W("rblyn_anon")||P(),V("rblyn_anon",e,365),t=!0),[4,F(r.api_key,e,r.user_token)];case 2:return i=o.sent(),a=g(),s=n(n({},a),c),l={chatbotId:r.api_key,userId:e,token:r.user_token,isAnonymous:t,domain:"",brand_colour:(null===(m=null===(p=i.user.org_info.brand_config)||void 0===p?void 0:p.colors)||void 0===m?void 0:m.brand_color)||"",image_url:(null===(v=null===(h=i.user.org_info)||void 0===h?void 0:h.brand_config)||void 0===v?void 0:v.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(b=i.user.org_info.brand_config)||void 0===b?void 0:b.display_name)||"",welcome_message:(null===(E=i.user.org_info.brand_config)||void 0===E?void 0:E.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(w=i.user.org_info.brand_config)||void 0===w?void 0:w.redirect_url)||""}},[4,new Promise((function(e,t){Z(l,(function(){d({isInitialized:!0,chatbotConfig:l}),e()}),(function(e){t(e)}))}))];case 3:return o.sent(),[3,6];case 4:return u=o.sent(),f=u instanceof Error?u.message:"Failed to initialize chatbot",d({error:f}),_.trackError(u instanceof Error?u:new Error(f),"useChatbotState",{errorCode:x,errorType:L,context:{timestamp:Date.now()}}),[3,6];case 5:return d({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[r.api_key,r.user_id,r.user_token]);e.useEffect((function(){r.api_key&&u()}),[u]),e.useEffect((function(){s.chatbotConfig&&l((function(e){return n(n({},e),{chatbotConfig:n(n({},e.chatbotConfig),{userProfile:n(n({},g()),c)})})}))}),[c]);var f=e.useCallback((function(){l((function(e){return n(n({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),p=e.useCallback((function(){d({isIframeVisible:!1})}),[]);return n(n({},s),{toggleIframeVisibility:f,closeIframe:p})},G=function(t){var r=t.api_key,s=t.chatbotConfig,c=t.user_profile,d=t.onEvent,f=e.useMemo((function(){return{isAnonymous:(null==s?void 0:s.isAnonymous)||!1,userId:(null==s?void 0:s.userId)||""}}),[null==s?void 0:s.isAnonymous,null==s?void 0:s.userId]),p=e.useMemo((function(){return c||{}}),[JSON.stringify(c)]),m=e.useCallback((function(e){for(var t=[],s=1;s<arguments.length;s++)t[s-1]=arguments[s];return i(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,s,l,c,d,m,h;return void 0===t&&(t={}),o(this,(function(o){switch(o.label){case 0:if(!r)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),i=u().apiUrl,s=g(),l=n({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:r,client_user_id:f.isAnonymous?"Anonymous":String(f.userId),event_type:e,user_profile:p},t),c={org_id:r,event_data:l,metadata:n({timestamp:Date.now()},s),event_type:"INFO",user_id:f.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)})];case 2:if(!(d=o.sent()).ok)throw new Error("Failed to send internal event: ".concat(d.statusText));return[3,4];case 3:return m=o.sent(),a.error("Failed to send internal event:",m),[3,4];case 4:return[2]}}))}))}),[r,f]);return{emitEvent:e.useCallback((function(e,t){var n=Date.now();e!==l.CHATBOT_BUTTON_CLICKED&&e!==l.CHATBOT_CLOSED&&e!==l.CHATBOT_OPENED||(d&&d({type:e,timestamp:n,data:t}),m(e,{timestamp:n}))}),[d,m]),onInternalEvent:m}},Q=e.memo((function(t){var i=t.api_key,o=t.user_id,r=t.user_token,a=t.user_profile,s=t.onEvent;e.useEffect((function(){}));var c=e.useMemo((function(){return{api_key:i,user_id:o,user_token:r,user_profile:a}}),[i,o,r,a]),d=e.useCallback((function(e){null==s||s(e)}),[s]),u=Y(c),f=u.isInitialized,m=u.error,h=u.chatbotConfig,v=u.isIframeVisible,g=u.toggleIframeVisibility,b=u.closeIframe,E=e.useMemo((function(){return{api_key:i,user_profile:c.user_profile,onEvent:d,chatbotConfig:h?{isAnonymous:h.isAnonymous,userId:h.userId}:null}}),[i,c.user_profile,d,null==h?void 0:h.isAnonymous,null==h?void 0:h.userId]),w=G(n({},E)),y=w.emitEvent,C=w.onInternalEvent;e.useEffect((function(){if(i)try{_.initialize(i,o)}catch(e){_.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:A,errorType:L,context:{timestamp:Date.now()}})}else _.trackError(new Error(U[I](i)),"RobylonChatbot",{errorCode:I,errorType:L,context:{timestamp:Date.now()}})}),[i,o]);var T=e.useCallback((function(){b(),y(l.CHATBOT_CLOSED)}),[b,y]),x=e.useCallback((function(){g(),y(v?l.CHATBOT_CLOSED:l.CHATBOT_BUTTON_CLICKED)}),[g,y,v]),O=e.useMemo((function(){return{config:h,toggleIframe:x,isIframeVisible:v,onEvent:d,onInternalEvent:C}}),[h,x,v,d,C]),k=e.useMemo((function(){return{config:h,isVisible:v,onClose:T,onEvent:d,onInternalEvent:C}}),[h,v,T,d,C]);return i&&!m&&h?e.createElement(j,{componentName:"RobylonChatbot"},f?e.createElement(e.Fragment,null,e.createElement(j,{componentName:"ChatbotFloatingButton"},e.createElement(p,n({},O))),e.createElement(j,{componentName:"ChatbotIframe"},e.createElement(z,n({},k)))):null):null}),(function(e,t){return e.api_key===t.api_key&&e.user_id===t.user_id&&e.user_token===t.user_token&&JSON.stringify(e.user_profile)===JSON.stringify(t.user_profile)&&!0})),q=function(){function e(e){this.config=e,this.buttonElement=document.createElement("div"),this.render(),this.mount()}return e.prototype.render=function(){var e=this,t=u().copilotUrl,n=this.config,i=n.config,o=n.isIframeVisible;if(Object.assign(this.buttonElement.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:i.brand_colour,color:r(i.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),this.buttonElement.className="message-bubble-container",o)this.buttonElement.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 <g id="Chevron_Down">\n <path\n id="Vector"\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </g>\n </svg>\n ';else{var a=document.createElement("img");a.src=i.image_url||"".concat(t,"/chatbubble.png"),a.alt="Chat",Object.assign(a.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}),this.buttonElement.innerHTML="",this.buttonElement.appendChild(a)}this.buttonElement.onclick=function(){e.config.toggleIframe()}},e.prototype.mount=function(){var e=this;document.body.appendChild(this.buttonElement),requestAnimationFrame((function(){var t,n;null===(n=(t=e.config).onEvent)||void 0===n||n.call(t,{type:l.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(l.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config=n(n({},this.config),e),this.render()},e.prototype.destroy=function(){this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},e}(),X=function(){function e(e){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(e){var n,i,o,r,a,s,d,f,p,m,h,v,g,b,E,w=u().copilotUrl;if(e.origin===w){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(c.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:l.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=e.data)||void 0===a?void 0:a.type)&&(null===(d=(s=t.config).onEvent)||void 0===d||d.call(s,{type:l.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(f=e.data)||void 0===f?void 0:f.type)&&(null===(m=(p=t.config).onEvent)||void 0===m||m.call(p,{type:l.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZATION_FAILED,{error:null===(h=e.data)||void 0===h?void 0:h.error})),"SESSION_REFRESHED"===(null===(v=e.data)||void 0===v?void 0:v.type)&&(null===(b=(g=t.config).onEvent)||void 0===b||b.call(g,{type:l.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(l.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(E=e.data)||void 0===E?void 0:E.type)&&t.config.onInternalEvent(c.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.render=function(){Object.assign(this.iframeElement.style,{position:"fixed",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:this.config.isVisible?"block":"none"}),this.applyResponsiveStyles(),document.body.appendChild(this.iframeElement)},e.prototype.applyResponsiveStyles=function(){this.iframeElement&&(window.innerWidth<560?Object.assign(this.iframeElement.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(this.iframeElement.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"}))},e.prototype.initialize=function(){var e=this;if(!this.isInitialized){var t=u().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(){_.trackError(new Error(U[S]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:S,errorType:H,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,c;if(this.config.isVisible=e,this.iframeElement.style.display=e?"block":"none",this.iframeElement.contentWindow&&e){var d=u().copilotUrl,f=new URL(this.iframeElement.src).origin||d;this.iframeElement.contentWindow.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},f),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,action:"registerUserId",data:{userId:null===(i=this.config.config)||void 0===i?void 0:i.userId,token:null===(o=this.config.config)||void 0===o?void 0:o.token,userProfile:null===(r=this.config.config)||void 0===r?void 0:r.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},f),this.hasRegistered=!0),null===(c=(s=this.config).onEvent)||void 0===c||c.call(s,{type:l.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(l.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=n(n({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var i=u().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},i)}},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}(),$=function(e,t,n){return i(void 0,void 0,void 0,(function(){var i,r,s,l,c,d,f,p;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),i=u().apiUrl,r="".concat(i,"/chat/chatbot/get/"),a.log("endpointUrl",r),s={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{}},[4,fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 1:return(l=o.sent()).ok?[3,3]:[4,l.text()];case 2:throw c=o.sent(),new Error(U[O](l.status,c));case 3:return[4,l.json()];case 4:if(d=o.sent(),!(null===(p=null==d?void 0:d.user)||void 0===p?void 0:p.org_info))throw new Error(U[D](["user","org_info"]));return[2,d];case 5:throw f=o.sent(),_.trackError(f instanceof Error?f:new Error(U[k]({error:String(f)})),"fetchChatbotConfig",{errorCode:f instanceof Error&&f.message.includes("API Request Failed")?O:k,errorType:M,context:{apiKey:e,userId:t,timestamp:Date.now()}}),f;case 6:return[2]}}))}))},ee=function(e){return i(void 0,void 0,void 0,(function(){var t,i,r,a,s,l,c,d,u,f,p,m,h,v;return o(this,(function(o){switch(o.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),i=t.user_id||void 0,r=!1,i||(i=W("rblyn_anon")||P(),V("rblyn_anon",i,365),r=!0),[4,$(t.api_key,i,t.user_token)];case 1:return a=o.sent(),s=g(),b=t.user_profile,E=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],l=b?Object.fromEntries(Object.entries(b).filter((function(e){var t=e[0];return E.includes(t)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},c=n(n({},s),l),[2,{chatbotId:t.api_key,userId:i,token:t.user_token,isAnonymous:r,domain:"",brand_colour:(null===(u=null===(d=a.user.org_info.brand_config)||void 0===d?void 0:d.colors)||void 0===u?void 0:u.brand_color)||"",image_url:(null===(p=null===(f=a.user.org_info)||void 0===f?void 0:f.brand_config)||void 0===p?void 0:p.launcher_logo_url)||"",userProfile:c,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(m=a.user.org_info.brand_config)||void 0===m?void 0:m.display_name)||"",welcome_message:(null===(h=a.user.org_info.brand_config)||void 0===h?void 0:h.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(v=a.user.org_info.brand_config)||void 0===v?void 0:v.redirect_url)||""}}]}var b,E}))}))},te=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){}}},ne=function(){function e(e){var t,r,a,s,c=this;if(this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){if(!c.isDestroyed){var t=e.isInitialized,n=e.error,i=e.chatbotConfig,o=e.isIframeVisible;!n&&i&&t&&(c.eventEmitter=te({api_key:c.config.api_key,user_profile:c.config.user_profile,onEvent:c.config.onEvent,chatbotConfig:{isAnonymous:i.isAnonymous,userId:i.userId}}),c.floatingButton?c.floatingButton.update({config:i,isIframeVisible:o}):c.floatingButton=new q({config:i,toggleIframe:c.toggleIframe,isIframeVisible:o,onEvent:c.config.onEvent,onInternalEvent:c.eventEmitter.onInternalEvent}),c.iframe?c.iframe.update({config:i,isVisible:o}):c.iframe=new X({config:i,isVisible:o,onClose:c.handleClose,onEvent:c.config.onEvent,onInternalEvent:c.eventEmitter.onInternalEvent}))}},this.toggleIframe=function(){var e=c.stateManager.getState();c.stateManager.toggleIframeVisibility(),c.eventEmitter.emit(e.isIframeVisible?l.CHATBOT_CLOSED:l.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){c.stateManager.closeIframe(),c.eventEmitter.emit(l.CHATBOT_CLOSED)},this.config=e,!e.api_key)throw _.trackError(new Error(U[I](e.api_key)),"RobylonChatbot",{errorCode:I,errorType:L,context:{timestamp:Date.now()}}),new Error("API key is required");try{_.initialize(e.api_key,e.user_id)}catch(e){_.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:A,errorType:L,context:{timestamp:Date.now()}})}this.stateManager=(t={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},r={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},a=[],{getState:function(){return r},initialize:function(){return i(void 0,void 0,void 0,(function(){var e,n,i;return o(this,(function(o){switch(o.label){case 0:if(!t.api_key)return _.trackError(new Error(U[I](t.api_key)),"ChatbotStateManager",{errorCode:I,errorType:L,context:{timestamp:Date.now()}}),[2];s({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,ee(t)];case 2:return e=o.sent(),[4,new Promise((function(t,n){Z(e,(function(){s({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return o.sent(),[3,6];case 4:return n=o.sent(),i=n instanceof Error?n.message:"Failed to initialize chatbot",s({error:i}),_.trackError(n instanceof Error?n:new Error(i),"ChatbotStateManager",{errorCode:x,errorType:L,context:{timestamp:Date.now()}}),[3,6];case 5:return s({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){s({isIframeVisible:!r.isIframeVisible})},closeIframe:function(){s({isIframeVisible:!1})},updateState:s=function(e){r=n(n({},r),e),a.forEach((function(e){return e(r)}))},subscribe:function(e){return a.push(e),function(){var t=a.indexOf(e);t>-1&&a.splice(t,1)}}}),this.eventEmitter=te({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),this.initialize()}return e.prototype.initialize=function(){return i(this,void 0,void 0,(function(){var e;return o(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(),_.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:x,errorType:L,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(l.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(l.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null)},e}();var ie={create:function(e){var t=new ne(e);return{show:function(){return t.show()},hide:function(){return t.hide()},toggle:function(){return t.toggle()},destroy:function(){return t.destroy()}}}};exports.Chatbot=Q,exports.RobylonChatbot=ie,exports.useChatbot=function(t){var i=e.useState({isLoading:!0,isInitialized:!1,error:null}),o=i[0],r=i[1],a=function(e){r((function(t){return n(n({},t),{isInitialized:e})}))},s=function(e){r((function(t){return n(n({},t),{error:e})}))};return e.useEffect((function(){!function(){try{Z(t,a,s)}catch(e){r((function(t){return n(n({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[t.chatbotId,t.userId]),o};
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=function(){return n=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},n.apply(this,arguments)};function i(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 o(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;var r=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"},a={log:function(){},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},info:function(){}};a.log("Raw API_URL:","https://stage-api.robylon.ai");var s={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};a.log("CONFIG",s);var l,c,d=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},u=function(){return{copilotUrl:s.copilotUrl||"https://app.robylon.ai",environment:s.environment||"production",apiUrl:s.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"}(l||(l={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(c||(c={}));var f,p=e.memo((function(t){var n=t.config,i=t.toggleIframe,o=t.isIframeVisible,s=t.onEvent,c=t.onInternalEvent,d=e.useRef(null),f=u().copilotUrl;e.useEffect((function(){d.current&&requestAnimationFrame((function(){null==s||s({type:l.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),c(l.CHATBOT_BUTTON_LOADED)}))}),[s,c]);return a.log("config chabotfloatingbutton",n),e.createElement("div",{ref:d,className:"message-bubble-container",style:{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:1e3,width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:n.brand_colour,color:r(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:i},o?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","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"}))):e.createElement("img",{src:n.image_url||"".concat(f,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))})),m=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]},h=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]},v=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)}},g=function(){return{platform:"web",os:m(),browser:h(),sdk_version:"1.1.34-staging.4",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:v()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(f||(f={}));var b,E=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],w=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&E.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))}))},y=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};w(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)};w(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){d()&&(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(){d()&&(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:g(),event_type:f.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){a.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 i(this,void 0,void 0,(function(){var e,t,i;return o(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];a.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,o.label=1;case 1:return e<t.length?(i=t[e],[4,this.trackError(i.error,i.componentName,n(n({},i.additionalInfo),{preInitError:!0}))]):[3,4];case 2:o.sent(),o.label=3;case 3:return e++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},e.prototype.sendLog=function(e){return i(this,void 0,void 0,(function(){var t,n,i,r,s,l;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),t=u().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=o.sent()).ok?[3,3]:(r=(i=a).error,s=["Failed to send error log:"],[4,n.text()]);case 2:r.apply(i,s.concat([o.sent()])),o.label=3;case 3:return[3,5];case 4:return l=o.sent(),a.error("Error sending log:",l),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,r){return i(this,void 0,void 0,(function(){var i,s,l;return o(this,(function(o){switch(o.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:n(n({},r),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:g(),event_type:f.ERROR,user_id:this.userId},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return o.sent(),[3,4];case 3:return o.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:r}),a.warn("Error tracked before initialization, queuing:",e),[3,4];case 4:return[2];case 5:return s={message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:n(n({},r),{timestamp:Date.now()}),timestamp:Date.now()},l={org_id:this.apiKey||"UNINITALIZED",event_data:s,metadata:g(),event_type:f.ERROR,user_id:this.userId},[4,this.sendLog(l)];case 6:return o.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return i(this,void 0,void 0,(function(){var i,r;return o(this,(function(o){switch(o.label){case 0:return this.apiKey?(i={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},r={org_id:this.apiKey,event_data:i,metadata:g(),event_type:f.INFO,user_id:this.userId},[4,this.sendLog(r)]):(a.error("Error tracking not initialized"),[2]);case 1:return o.sent(),[2]}}))}))},e}(),_=y.getInstance(),I="MISSING_API_KEY",C="INVALID_API_KEY",T="CONFIG_FETCH_FAILED",x="SDK_INIT_FAILED",A="ERROR_TRACKING_INIT_FAILED",O="API_REQUEST_FAILED",k="NETWORK_ERROR",D="INVALID_RESPONSE",S="IFRAME_LOAD_FAILED",R="COOKIE_ACCESS_ERROR",N="COMPONENT_RENDER_ERROR",L="INITIALIZATION_ERROR",M="API_ERROR",H="RUNTIME_ERROR",B="COMPONENT_ERROR",U=((b={})[I]=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[C]=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[T]=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[O]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},b[k]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},b[S]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},b[D]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},b[A]=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[x]=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[R]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},b[N]=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),z=e.memo((function(t){var n=t.config,i=t.isVisible,o=t.onClose,r=t.onEvent,a=t.onInternalEvent,s=e.useRef(null),d=e.useRef(!1),f=e.useRef(!1),p=e.useCallback((function(){var e=s.current;e&&((null===window||void 0===window?void 0:window.innerWidth)<560?(e.style.width="100vw",e.style.minWidth="300px",e.style.right="0",e.style.bottom="0",e.style.height="100vh",e.style.flexDirection="column",e.style.flexGrow="1",e.style.borderRadius="0",e.style.top="0",e.style.maxHeight="100%"):(e.style.width="26%",e.style.minWidth="400px",e.style.right="32px",e.style.bottom="86px",e.style.height="calc(100vh - 3rem - 10vh)",e.style.borderRadius="1rem",e.style.top="calc(10vh - 32px)",e.style.maxHeight="45rem"))}),[a]);return e.useEffect((function(){return null===window||void 0===window||window.addEventListener("resize",p),p(),function(){return null===window||void 0===window?void 0:window.removeEventListener("resize",p)}}),[p]),e.useEffect((function(){var e=s.current;if(e&&!d.current){var t=u().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(n.chatbotId),d.current=!0;var i=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",i),function(){return e.removeEventListener("load",i)}}}),[n.chatbotId]),e.useEffect((function(){var e,t,o,r,a=s.current;if(a&&d.current){var l=u().copilotUrl;if(a.style.display=i?"block":"none",a.contentWindow&&i){var c=new URL(a.src).origin||l;null===(e=null==a?void 0:a.contentWindow)||void 0===e||e.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},c),(null==f?void 0:f.current)||(null===(o=a.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:null==n?void 0:n.userId,token:null==n?void 0:n.token,userProfile:null==n?void 0:n.userProfile,isAnonymous:null==n?void 0:n.isAnonymous}},c),f.current=!0)}}}),[i,n.userId,n.token,n.userProfile]),e.useEffect((function(){if(s.current&&d.current){var e=u().copilotUrl;i&&(null==r||r({type:l.CHATBOT_OPENED,timestamp:Date.now()}),a(l.CHATBOT_OPENED));var t=function(t){var n,i,s,d,u,f,p;if(t.origin===e){if("closeChatbot"===t.data)return void o();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void a(c.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==r||r({type:l.CHATBOT_LOADED,timestamp:Date.now()}),a(l.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(s=t.data)||void 0===s?void 0:s.type)&&(null==r||r({type:l.CHAT_INITIALIZED,timestamp:Date.now()}),a(l.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(d=t.data)||void 0===d?void 0:d.type)&&(null==r||r({type:l.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),a(l.CHAT_INITIALIZATION_FAILED,{error:null===(u=t.data)||void 0===u?void 0:u.error})),"SESSION_REFRESHED"===(null===(f=t.data)||void 0===f?void 0:f.type)&&(null==r||r({type:l.SESSION_REFRESHED,timestamp:Date.now()}),a(l.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(p=t.data)||void 0===p?void 0:p.type)&&a(c.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)}}}),[o,r,a,n.chatbotId,i]),e.useEffect((function(){var e=s.current;if(e&&d.current){var t=function(){_.trackError(new Error(U[S]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:S,errorType:H,context:{config:n,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[n]),e.useEffect((function(){var e;if(s.current&&n&&i){var t=s.current,o=u().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:n.userProfile},o)}}),[n.userProfile,i]),e.createElement("iframe",{ref:s,id:"chat-iframe-rbyln",style:{position:"fixed",zIndex:2e7,border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:i?"block":"none"}})})),j=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){_.trackError(new Error(U[N]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:N,errorType:B,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},n.prototype.render=function(){return this.state.hasError?null:this.props.children},n}(e.Component),F=function(e,t,n){return i(void 0,void 0,void 0,(function(){var i,r,s,l,c,d,f,p;return o(this,(function(o){switch(o.label){case 0:i=u().apiUrl,r="".concat(i,"/chat/chatbot/get/"),a.log("endpointUrl",r),s={client_user_id:t,org_id:e,token:n||void 0,extra_info:{}},o.label=1;case 1:return o.trys.push([1,6,,7]),[4,fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 2:return(l=o.sent()).ok?[3,4]:[4,l.text()];case 3:throw c=o.sent(),new Error(U[O](l.status,c));case 4:return[4,l.json()];case 5:if(d=o.sent(),!(null===(p=null==d?void 0:d.user)||void 0===p?void 0:p.org_info))throw new Error(U[D](["user","org_info"]));return[2,d];case 6:throw f=o.sent(),_.trackError(f instanceof Error?f:new Error(U[k]({error:String(f)})),"fetchChatbotConfig",{errorCode:f instanceof Error&&f.message.includes("API Request Failed")?O:k,errorType:M,context:{chatbotId:e,userId:t,apiUrl:i,statusCode:f instanceof Response?f.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),f;case 7:return[2]}}))}))},P=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)}))},W=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()},V=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=/")},K=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},J=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 a.log("expectedDomain, to current domain",t,n,t===n),t===n},e.prototype.createChatBubblContainer=function(){var e,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var i=document.createElement("div");i.classList.add("close-btn"),i.textContent="✕",Object.assign(i.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var i=t.createMessageBubble(e);n.appendChild(i)})),n.appendChild(i),document.body.appendChild(n)},e.prototype.createMessageBubble=function(e){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=e,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var i=document.createElement("button");return i.innerHTML="&times;",Object.assign(i.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),i.addEventListener("click",(function(){t.remove()})),t.appendChild(i),t.appendChild(n),t},e.prototype.createFloatingButton=function(){var e=document.createElement("div");e.classList.add("message-bubble-container"),Object.assign(e.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:r(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=document.createElement("img");t.src=this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),t.alt="Chat",Object.assign(t.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=t,e.innerHTML="",e.appendChild(t)},e.prototype.createIframe=function(){var e=this;a.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),a.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:K(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;a.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(a.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;a.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"),a.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}(),Z=function(e,t,n){if(e.chatbotId&&e.userId)try{new J(e);t(!0),a.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},Y=function(t){var r=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)]),a=e.useState({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),s=a[0],l=a[1],c=e.useMemo((function(){var e=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"];return r.user_profile?Object.fromEntries(Object.entries(r.user_profile).filter((function(t){var n=t[0];return e.includes(n)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(r.user_profile)]),d=e.useCallback((function(e){l((function(t){return n(n({},t),e)}))}),[]),u=e.useCallback((function(){return i(void 0,void 0,void 0,(function(){var e,t,i,a,s,l,u,f,p,m,h,v,b,E,w;return o(this,(function(o){switch(o.label){case 0:if(!r.api_key)return _.trackError(new Error(U[I](r.api_key)),"useChatbotState",{errorCode:I,errorType:L,context:{timestamp:Date.now()}}),[2];d({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),e=r.user_id||void 0,t=!1,e||(e=W("rblyn_anon")||P(),V("rblyn_anon",e,365),t=!0),[4,F(r.api_key,e,r.user_token)];case 2:return i=o.sent(),a=g(),s=n(n({},a),c),l={chatbotId:r.api_key,userId:e,token:r.user_token,isAnonymous:t,domain:"",brand_colour:(null===(m=null===(p=i.user.org_info.brand_config)||void 0===p?void 0:p.colors)||void 0===m?void 0:m.brand_color)||"",image_url:(null===(v=null===(h=i.user.org_info)||void 0===h?void 0:h.brand_config)||void 0===v?void 0:v.launcher_logo_url)||"",userProfile:s,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(b=i.user.org_info.brand_config)||void 0===b?void 0:b.display_name)||"",welcome_message:(null===(E=i.user.org_info.brand_config)||void 0===E?void 0:E.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(w=i.user.org_info.brand_config)||void 0===w?void 0:w.redirect_url)||""}},[4,new Promise((function(e,t){Z(l,(function(){d({isInitialized:!0,chatbotConfig:l}),e()}),(function(e){t(e)}))}))];case 3:return o.sent(),[3,6];case 4:return u=o.sent(),f=u instanceof Error?u.message:"Failed to initialize chatbot",d({error:f}),_.trackError(u instanceof Error?u:new Error(f),"useChatbotState",{errorCode:x,errorType:L,context:{timestamp:Date.now()}}),[3,6];case 5:return d({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[r.api_key,r.user_id,r.user_token]);e.useEffect((function(){r.api_key&&u()}),[u]),e.useEffect((function(){s.chatbotConfig&&l((function(e){return n(n({},e),{chatbotConfig:n(n({},e.chatbotConfig),{userProfile:n(n({},g()),c)})})}))}),[c]);var f=e.useCallback((function(){l((function(e){return n(n({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),p=e.useCallback((function(){d({isIframeVisible:!1})}),[]);return n(n({},s),{toggleIframeVisibility:f,closeIframe:p})},G=function(t){var r=t.api_key,s=t.chatbotConfig,c=t.user_profile,d=t.onEvent,f=e.useMemo((function(){return{isAnonymous:(null==s?void 0:s.isAnonymous)||!1,userId:(null==s?void 0:s.userId)||""}}),[null==s?void 0:s.isAnonymous,null==s?void 0:s.userId]),p=e.useMemo((function(){return c||{}}),[JSON.stringify(c)]),m=e.useCallback((function(e){for(var t=[],s=1;s<arguments.length;s++)t[s-1]=arguments[s];return i(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,s,l,c,d,m,h;return void 0===t&&(t={}),o(this,(function(o){switch(o.label){case 0:if(!r)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),i=u().apiUrl,s=g(),l=n({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:r,client_user_id:f.isAnonymous?"Anonymous":String(f.userId),event_type:e,user_profile:p},t),c={org_id:r,event_data:l,metadata:n({timestamp:Date.now()},s),event_type:"INFO",user_id:f.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)})];case 2:if(!(d=o.sent()).ok)throw new Error("Failed to send internal event: ".concat(d.statusText));return[3,4];case 3:return m=o.sent(),a.error("Failed to send internal event:",m),[3,4];case 4:return[2]}}))}))}),[r,f]);return{emitEvent:e.useCallback((function(e,t){var n=Date.now();e!==l.CHATBOT_BUTTON_CLICKED&&e!==l.CHATBOT_CLOSED&&e!==l.CHATBOT_OPENED||(d&&d({type:e,timestamp:n,data:t}),m(e,{timestamp:n}))}),[d,m]),onInternalEvent:m}},Q=e.memo((function(t){var i=t.api_key,o=t.user_id,r=t.user_token,a=t.user_profile,s=t.onEvent;e.useEffect((function(){}));var c=e.useMemo((function(){return{api_key:i,user_id:o,user_token:r,user_profile:a}}),[i,o,r,a]),d=e.useCallback((function(e){null==s||s(e)}),[s]),u=Y(c),f=u.isInitialized,m=u.error,h=u.chatbotConfig,v=u.isIframeVisible,g=u.toggleIframeVisibility,b=u.closeIframe,E=e.useMemo((function(){return{api_key:i,user_profile:c.user_profile,onEvent:d,chatbotConfig:h?{isAnonymous:h.isAnonymous,userId:h.userId}:null}}),[i,c.user_profile,d,null==h?void 0:h.isAnonymous,null==h?void 0:h.userId]),w=G(n({},E)),y=w.emitEvent,C=w.onInternalEvent;e.useEffect((function(){if(i)try{_.initialize(i,o)}catch(e){_.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:A,errorType:L,context:{timestamp:Date.now()}})}else _.trackError(new Error(U[I](i)),"RobylonChatbot",{errorCode:I,errorType:L,context:{timestamp:Date.now()}})}),[i,o]);var T=e.useCallback((function(){b(),y(l.CHATBOT_CLOSED)}),[b,y]),x=e.useCallback((function(){g(),y(v?l.CHATBOT_CLOSED:l.CHATBOT_BUTTON_CLICKED)}),[g,y,v]),O=e.useMemo((function(){return{config:h,toggleIframe:x,isIframeVisible:v,onEvent:d,onInternalEvent:C}}),[h,x,v,d,C]),k=e.useMemo((function(){return{config:h,isVisible:v,onClose:T,onEvent:d,onInternalEvent:C}}),[h,v,T,d,C]);return i&&!m&&h?e.createElement(j,{componentName:"RobylonChatbot"},f?e.createElement(e.Fragment,null,e.createElement(j,{componentName:"ChatbotFloatingButton"},e.createElement(p,n({},O))),e.createElement(j,{componentName:"ChatbotIframe"},e.createElement(z,n({},k)))):null):null}),(function(e,t){return e.api_key===t.api_key&&e.user_id===t.user_id&&e.user_token===t.user_token&&JSON.stringify(e.user_profile)===JSON.stringify(t.user_profile)&&!0})),q=function(){function e(e){this.config=e,this.buttonElement=document.createElement("div"),this.render(),this.mount()}return e.prototype.render=function(){var e=this,t=u().copilotUrl,n=this.config,i=n.config,o=n.isIframeVisible;if(Object.assign(this.buttonElement.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:i.brand_colour,color:r(i.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),this.buttonElement.className="message-bubble-container",o)this.buttonElement.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 <g id="Chevron_Down">\n <path\n id="Vector"\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </g>\n </svg>\n ';else{var a=document.createElement("img");a.src=i.image_url||"".concat(t,"/chatbubble.png"),a.alt="Chat",Object.assign(a.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}),this.buttonElement.innerHTML="",this.buttonElement.appendChild(a)}this.buttonElement.onclick=function(){e.config.toggleIframe()}},e.prototype.mount=function(){var e=this;document.body.appendChild(this.buttonElement),requestAnimationFrame((function(){var t,n;null===(n=(t=e.config).onEvent)||void 0===n||n.call(t,{type:l.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(l.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config=n(n({},this.config),e),this.render()},e.prototype.destroy=function(){this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},e}(),X=function(){function e(e){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(e){var n,i,o,r,a,s,d,f,p,m,h,v,g,b,E,w=u().copilotUrl;if(e.origin===w){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(c.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:l.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=e.data)||void 0===a?void 0:a.type)&&(null===(d=(s=t.config).onEvent)||void 0===d||d.call(s,{type:l.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(f=e.data)||void 0===f?void 0:f.type)&&(null===(m=(p=t.config).onEvent)||void 0===m||m.call(p,{type:l.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(l.CHAT_INITIALIZATION_FAILED,{error:null===(h=e.data)||void 0===h?void 0:h.error})),"SESSION_REFRESHED"===(null===(v=e.data)||void 0===v?void 0:v.type)&&(null===(b=(g=t.config).onEvent)||void 0===b||b.call(g,{type:l.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(l.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(E=e.data)||void 0===E?void 0:E.type)&&t.config.onInternalEvent(c.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.render=function(){Object.assign(this.iframeElement.style,{position:"fixed",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:this.config.isVisible?"block":"none"}),this.applyResponsiveStyles(),document.body.appendChild(this.iframeElement)},e.prototype.applyResponsiveStyles=function(){this.iframeElement&&(window.innerWidth<560?Object.assign(this.iframeElement.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(this.iframeElement.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"}))},e.prototype.initialize=function(){var e=this;if(!this.isInitialized){var t=u().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(){_.trackError(new Error(U[S]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:S,errorType:H,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,c;if(this.config.isVisible=e,this.iframeElement.style.display=e?"block":"none",this.iframeElement.contentWindow&&e){var d=u().copilotUrl,f=new URL(this.iframeElement.src).origin||d;this.iframeElement.contentWindow.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},f),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,action:"registerUserId",data:{userId:null===(i=this.config.config)||void 0===i?void 0:i.userId,token:null===(o=this.config.config)||void 0===o?void 0:o.token,userProfile:null===(r=this.config.config)||void 0===r?void 0:r.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},f),this.hasRegistered=!0),null===(c=(s=this.config).onEvent)||void 0===c||c.call(s,{type:l.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(l.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=n(n({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var i=u().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},i)}},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}(),$=function(e,t,n){return i(void 0,void 0,void 0,(function(){var i,r,s,l,c,d,f,p;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),i=u().apiUrl,r="".concat(i,"/chat/chatbot/get/"),a.log("endpointUrl",r),s={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{}},[4,fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})];case 1:return(l=o.sent()).ok?[3,3]:[4,l.text()];case 2:throw c=o.sent(),new Error(U[O](l.status,c));case 3:return[4,l.json()];case 4:if(d=o.sent(),!(null===(p=null==d?void 0:d.user)||void 0===p?void 0:p.org_info))throw new Error(U[D](["user","org_info"]));return[2,d];case 5:throw f=o.sent(),_.trackError(f instanceof Error?f:new Error(U[k]({error:String(f)})),"fetchChatbotConfig",{errorCode:f instanceof Error&&f.message.includes("API Request Failed")?O:k,errorType:M,context:{apiKey:e,userId:t,timestamp:Date.now()}}),f;case 6:return[2]}}))}))},ee=function(e){return i(void 0,void 0,void 0,(function(){var t,i,r,a,s,l,c,d,u,f,p,m,h,v;return o(this,(function(o){switch(o.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),i=t.user_id||void 0,r=!1,i||(i=W("rblyn_anon")||P(),V("rblyn_anon",i,365),r=!0),[4,$(t.api_key,i,t.user_token)];case 1:return a=o.sent(),s=g(),b=t.user_profile,E=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],l=b?Object.fromEntries(Object.entries(b).filter((function(e){var t=e[0];return E.includes(t)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},c=n(n({},s),l),[2,{chatbotId:t.api_key,userId:i,token:t.user_token,isAnonymous:r,domain:"",brand_colour:(null===(u=null===(d=a.user.org_info.brand_config)||void 0===d?void 0:d.colors)||void 0===u?void 0:u.brand_color)||"",image_url:(null===(p=null===(f=a.user.org_info)||void 0===f?void 0:f.brand_config)||void 0===p?void 0:p.launcher_logo_url)||"",userProfile:c,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(m=a.user.org_info.brand_config)||void 0===m?void 0:m.display_name)||"",welcome_message:(null===(h=a.user.org_info.brand_config)||void 0===h?void 0:h.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(v=a.user.org_info.brand_config)||void 0===v?void 0:v.redirect_url)||""}}]}var b,E}))}))},te=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){}}},ne=function(){function e(e){var t,r,a,s,c=this;if(this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){if(!c.isDestroyed){var t=e.isInitialized,n=e.error,i=e.chatbotConfig,o=e.isIframeVisible;!n&&i&&t&&(c.eventEmitter=te({api_key:c.config.api_key,user_profile:c.config.user_profile,onEvent:c.config.onEvent,chatbotConfig:{isAnonymous:i.isAnonymous,userId:i.userId}}),c.floatingButton?c.floatingButton.update({config:i,isIframeVisible:o}):c.floatingButton=new q({config:i,toggleIframe:c.toggleIframe,isIframeVisible:o,onEvent:c.config.onEvent,onInternalEvent:c.eventEmitter.onInternalEvent}),c.iframe?c.iframe.update({config:i,isVisible:o}):c.iframe=new X({config:i,isVisible:o,onClose:c.handleClose,onEvent:c.config.onEvent,onInternalEvent:c.eventEmitter.onInternalEvent}))}},this.toggleIframe=function(){var e=c.stateManager.getState();c.stateManager.toggleIframeVisibility(),c.eventEmitter.emit(e.isIframeVisible?l.CHATBOT_CLOSED:l.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){c.stateManager.closeIframe(),c.eventEmitter.emit(l.CHATBOT_CLOSED)},this.config=e,!e.api_key)throw _.trackError(new Error(U[I](e.api_key)),"RobylonChatbot",{errorCode:I,errorType:L,context:{timestamp:Date.now()}}),new Error("API key is required");try{_.initialize(e.api_key,e.user_id)}catch(e){_.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:A,errorType:L,context:{timestamp:Date.now()}})}this.stateManager=(t={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},r={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},a=[],{getState:function(){return r},initialize:function(){return i(void 0,void 0,void 0,(function(){var e,n,i;return o(this,(function(o){switch(o.label){case 0:if(!t.api_key)return _.trackError(new Error(U[I](t.api_key)),"ChatbotStateManager",{errorCode:I,errorType:L,context:{timestamp:Date.now()}}),[2];s({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,ee(t)];case 2:return e=o.sent(),[4,new Promise((function(t,n){Z(e,(function(){s({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return o.sent(),[3,6];case 4:return n=o.sent(),i=n instanceof Error?n.message:"Failed to initialize chatbot",s({error:i}),_.trackError(n instanceof Error?n:new Error(i),"ChatbotStateManager",{errorCode:x,errorType:L,context:{timestamp:Date.now()}}),[3,6];case 5:return s({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){s({isIframeVisible:!r.isIframeVisible})},closeIframe:function(){s({isIframeVisible:!1})},updateState:s=function(e){r=n(n({},r),e),a.forEach((function(e){return e(r)}))},subscribe:function(e){return a.push(e),function(){var t=a.indexOf(e);t>-1&&a.splice(t,1)}}}),this.eventEmitter=te({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),this.initialize()}return e.prototype.initialize=function(){return i(this,void 0,void 0,(function(){var e;return o(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(),_.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:x,errorType:L,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(l.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(l.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null)},e}();var ie={create:function(e){var t=new ne(e);return{show:function(){return t.show()},hide:function(){return t.hide()},toggle:function(){return t.toggle()},destroy:function(){return t.destroy()}}}};exports.Chatbot=Q,exports.RobylonChatbot=ie,exports.useChatbot=function(t){var i=e.useState({isLoading:!0,isInitialized:!1,error:null}),o=i[0],r=i[1],a=function(e){r((function(t){return n(n({},t),{isInitialized:e})}))},s=function(e){r((function(t){return n(n({},t),{error:e})}))};return e.useEffect((function(){!function(){try{Z(t,a,s)}catch(e){r((function(t){return n(n({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[t.chatbotId,t.userId]),o};
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,useEffect as i,useCallback as o,Component as r,useMemo as a,useState as s}from"react";var l=function(e,t){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},l(e,t)};var c=function(){return c=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},c.apply(this,arguments)};function d(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 u(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;var f=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"},p={log:function(){},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},info:function(){}};p.log("Raw API_URL:","https://stage-api.robylon.ai");var m={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};p.log("CONFIG",m);var h,v,g=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},b=function(){return{copilotUrl:m.copilotUrl||"https://app.robylon.ai",environment:m.environment||"production",apiUrl:m.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"}(h||(h={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(v||(v={}));var E,w=t((function(t){var o=t.config,r=t.toggleIframe,a=t.isIframeVisible,s=t.onEvent,l=t.onInternalEvent,c=n(null),d=b().copilotUrl;i((function(){c.current&&requestAnimationFrame((function(){null==s||s({type:h.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),l(h.CHATBOT_BUTTON_LOADED)}))}),[s,l]);return p.log("config chabotfloatingbutton",o),e.createElement("div",{ref:c,className:"message-bubble-container",style:{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:1e3,width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:o.brand_colour,color:f(o.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:r},a?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","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"}))):e.createElement("img",{src:o.image_url||"".concat(d,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))})),y=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]},_=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]},I=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)}},T=function(){return{platform:"web",os:y(),browser:_(),sdk_version:"1.1.34-staging.9",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:I()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(E||(E={}));var C,x=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],A=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&x.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))}))},O=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};A(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)};A(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){g()&&(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(){g()&&(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:T(),event_type:E.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){p.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 d(this,void 0,void 0,(function(){var e,t,n;return u(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];p.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,c(c({},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 d(this,void 0,void 0,(function(){var t,n,i,o,r,a;return u(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=b().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=p).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(),p.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return d(this,void 0,void 0,(function(){var i,o,r;return u(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:c(c({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:T(),event_type:E.ERROR,user_id:this.userId},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return a.sent(),[3,4];case 3:return a.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),p.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:c(c({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:T(),event_type:E.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return d(this,void 0,void 0,(function(){var i,o;return u(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:T(),event_type:E.INFO,user_id:this.userId},[4,this.sendLog(o)]):(p.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),D=O.getInstance(),k="MISSING_API_KEY",S="INVALID_API_KEY",N="CONFIG_FETCH_FAILED",R="SDK_INIT_FAILED",L="ERROR_TRACKING_INIT_FAILED",H="API_REQUEST_FAILED",M="NETWORK_ERROR",B="INVALID_RESPONSE",U="IFRAME_LOAD_FAILED",z="COOKIE_ACCESS_ERROR",j="COMPONENT_RENDER_ERROR",F="INITIALIZATION_ERROR",P="API_ERROR",W="RUNTIME_ERROR",V="COMPONENT_ERROR",K=((C={})[k]=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.")},C[S]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},C[N]=function(e){return"Failed to fetch chatbot configuration: ".concat(e.statusCode?"Server responded with status ".concat(e.statusCode):"Could not reach server").concat(e.error?". Error: ".concat(e.error):"")},C[H]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},C[M]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},C[U]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},C[B]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},C[L]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},C[R]=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)):"")},C[z]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},C[j]=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):"")},C),J=t((function(t){var r=t.config,a=t.isVisible,s=t.onClose,l=t.onEvent,c=t.onInternalEvent,d=n(null),u=n(!1),f=n(!1),p=o((function(){var e=d.current;e&&((null===window||void 0===window?void 0:window.innerWidth)<560?(e.style.width="100vw",e.style.minWidth="300px",e.style.right="0",e.style.bottom="0",e.style.height="100vh",e.style.flexDirection="column",e.style.flexGrow="1",e.style.borderRadius="0",e.style.top="0",e.style.maxHeight="100%"):(e.style.width="26%",e.style.minWidth="400px",e.style.right="32px",e.style.bottom="86px",e.style.height="calc(100vh - 3rem - 10vh)",e.style.borderRadius="1rem",e.style.top="calc(10vh - 32px)",e.style.maxHeight="45rem"))}),[c]);return i((function(){return null===window||void 0===window||window.addEventListener("resize",p),p(),function(){return null===window||void 0===window?void 0:window.removeEventListener("resize",p)}}),[p]),i((function(){var e=d.current;if(e&&!u.current){var t=b().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(r.chatbotId),u.current=!0;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)}}}),[r.chatbotId]),i((function(){var e,t,n,i,o=d.current;if(o&&u.current){var s=b().copilotUrl;if(o.style.display=a?"block":"none",o.contentWindow&&a){var l=new URL(o.src).origin||s;null===(e=null==o?void 0:o.contentWindow)||void 0===e||e.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},l),(null==f?void 0:f.current)||(null===(n=o.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,action:"registerUserId",data:{userId:null==r?void 0:r.userId,token:null==r?void 0:r.token,userProfile:null==r?void 0:r.userProfile,isAnonymous:null==r?void 0:r.isAnonymous}},l),f.current=!0)}}}),[a,r.userId,r.token,r.userProfile]),i((function(){if(d.current&&u.current){var e=b().copilotUrl;a&&(null==l||l({type:h.CHATBOT_OPENED,timestamp:Date.now()}),c(h.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,d,u;if(t.origin===e){if("closeChatbot"===t.data)return void s();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void c(v.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==l||l({type:h.CHATBOT_LOADED,timestamp:Date.now()}),c(h.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==l||l({type:h.CHAT_INITIALIZED,timestamp:Date.now()}),c(h.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==l||l({type:h.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),c(h.CHAT_INITIALIZATION_FAILED,{error:null===(a=t.data)||void 0===a?void 0:a.error})),"SESSION_REFRESHED"===(null===(d=t.data)||void 0===d?void 0:d.type)&&(null==l||l({type:h.SESSION_REFRESHED,timestamp:Date.now()}),c(h.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(u=t.data)||void 0===u?void 0:u.type)&&c(v.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)}}}),[s,l,c,r.chatbotId,a]),i((function(){var e=d.current;if(e&&u.current){var t=function(){D.trackError(new Error(K[U]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:W,context:{config:r,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[r]),i((function(){var e;if(d.current&&r&&a){var t=d.current,n=b().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:r.userProfile},n)}}),[r.userProfile,a]),e.createElement("iframe",{ref:d,id:"chat-iframe-rbyln",style:{position:"fixed",zIndex:2e7,border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:a?"block":"none"}})})),Z=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={hasError:!1},t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.getDerivedStateFromError=function(e){return{hasError:!0}},t.prototype.componentDidCatch=function(e,t){D.trackError(new Error(K[j]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:j,errorType:V,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(r),Y=function(e,t,n){return d(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return u(this,(function(u){switch(u.label){case 0:i=b().apiUrl,o="".concat(i,"/chat/chatbot/get/"),p.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{}},u.label=1;case 1:return u.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 2:return(a=u.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=u.sent(),new Error(K[H](a.status,s));case 4:return[4,a.json()];case 5:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(K[B](["user","org_info"]));return[2,l];case 6:throw c=u.sent(),D.trackError(c instanceof Error?c:new Error(K[M]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?H:M,errorType:P,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]}}))}))},G=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)}))},Q=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()},q=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=/")},X=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},$=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 p.log("expectedDomain, to current domain",t,n,t===n),t===n},e.prototype.createChatBubblContainer=function(){var e,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var i=document.createElement("div");i.classList.add("close-btn"),i.textContent="✕",Object.assign(i.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var i=t.createMessageBubble(e);n.appendChild(i)})),n.appendChild(i),document.body.appendChild(n)},e.prototype.createMessageBubble=function(e){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=e,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var i=document.createElement("button");return i.innerHTML="&times;",Object.assign(i.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),i.addEventListener("click",(function(){t.remove()})),t.appendChild(i),t.appendChild(n),t},e.prototype.createFloatingButton=function(){var e=document.createElement("div");e.classList.add("message-bubble-container"),Object.assign(e.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:f(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=document.createElement("img");t.src=this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),t.alt="Chat",Object.assign(t.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=t,e.innerHTML="",e.appendChild(t)},e.prototype.createIframe=function(){var e=this;p.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),p.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:X(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;p.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(p.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;p.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"),p.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}(),ee=function(e,t,n){if(e.chatbotId&&e.userId)try{new $(e);t(!0),p.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},te=function(e){var t=a((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=s({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),r=n[0],l=n[1],f=a((function(){var e=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"];return t.user_profile?Object.fromEntries(Object.entries(t.user_profile).filter((function(t){var n=t[0];return e.includes(n)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(t.user_profile)]),p=o((function(e){l((function(t){return c(c({},t),e)}))}),[]),m=o((function(){return d(void 0,void 0,void 0,(function(){var e,n,i,o,r,a,s,l,d,m,h,v,g,b,E;return u(this,(function(u){switch(u.label){case 0:if(!t.api_key)return D.trackError(new Error(K[k](t.api_key)),"useChatbotState",{errorCode:k,errorType:F,context:{timestamp:Date.now()}}),[2];p({isInitializing:!0}),u.label=1;case 1:return u.trys.push([1,4,5,6]),e=t.user_id||void 0,n=!1,e||(e=Q("rblyn_anon")||G(),q("rblyn_anon",e,365),n=!0),[4,Y(t.api_key,e,t.user_token)];case 2:return i=u.sent(),o=T(),r=c(c({},o),f),a={chatbotId:t.api_key,userId:e,token:t.user_token,isAnonymous:n,domain:"",brand_colour:(null===(m=null===(d=i.user.org_info.brand_config)||void 0===d?void 0:d.colors)||void 0===m?void 0:m.brand_color)||"",image_url:(null===(v=null===(h=i.user.org_info)||void 0===h?void 0:h.brand_config)||void 0===v?void 0:v.launcher_logo_url)||"",userProfile:r,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(g=i.user.org_info.brand_config)||void 0===g?void 0:g.display_name)||"",welcome_message:(null===(b=i.user.org_info.brand_config)||void 0===b?void 0:b.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)||""}},[4,new Promise((function(e,t){ee(a,(function(){p({isInitialized:!0,chatbotConfig:a}),e()}),(function(e){t(e)}))}))];case 3:return u.sent(),[3,6];case 4:return s=u.sent(),l=s instanceof Error?s.message:"Failed to initialize chatbot",p({error:l}),D.trackError(s instanceof Error?s:new Error(l),"useChatbotState",{errorCode:R,errorType:F,context:{timestamp:Date.now()}}),[3,6];case 5:return p({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[t.api_key,t.user_id,t.user_token]);i((function(){t.api_key&&m()}),[m]),i((function(){r.chatbotConfig&&l((function(e){return c(c({},e),{chatbotConfig:c(c({},e.chatbotConfig),{userProfile:c(c({},T()),f)})})}))}),[f]);var h=o((function(){l((function(e){return c(c({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),v=o((function(){p({isIframeVisible:!1})}),[]);return c(c({},r),{toggleIframeVisibility:h,closeIframe:v})},ne=function(e){var t=e.api_key,n=e.chatbotConfig,i=e.user_profile,r=e.onEvent,s=a((function(){return{isAnonymous:(null==n?void 0:n.isAnonymous)||!1,userId:(null==n?void 0:n.userId)||""}}),[null==n?void 0:n.isAnonymous,null==n?void 0:n.userId]),l=a((function(){return i||{}}),[JSON.stringify(i)]),f=o((function(e){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return d(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,a,d,f,m;return void 0===n&&(n={}),u(this,(function(u){switch(u.label){case 0:if(!t)return[2];u.label=1;case 1:return u.trys.push([1,3,,4]),i=b().apiUrl,o=T(),r=c({trigger_time:Date.now(),channel:"CHATBOT",launch_url:(null===(m=null===window||void 0===window?void 0:window.location)||void 0===m?void 0:m.href)||"",org_id:t,client_user_id:s.isAnonymous?"Anonymous":String(s.userId),event_type:e,user_profile:l},n),a={org_id:t,event_data:r,metadata:c({timestamp:Date.now()},o),event_type:"INFO",user_id:s.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})];case 2:if(!(d=u.sent()).ok)throw new Error("Failed to send internal event: ".concat(d.statusText));return[3,4];case 3:return f=u.sent(),p.error("Failed to send internal event:",f),[3,4];case 4:return[2]}}))}))}),[t,s]);return{emitEvent:o((function(e,t){var n=Date.now();e!==h.CHATBOT_BUTTON_CLICKED&&e!==h.CHATBOT_CLOSED&&e!==h.CHATBOT_OPENED||(r&&r({type:e,timestamp:n,data:t}),f(e,{timestamp:n}))}),[r,f]),onInternalEvent:f}},ie=t((function(t){var n=t.api_key,r=t.user_id,s=t.user_token,l=t.user_profile,d=t.onEvent;i((function(){}));var u=a((function(){return{api_key:n,user_id:r,user_token:s,user_profile:l}}),[n,r,s,l]),f=o((function(e){null==d||d(e)}),[d]),p=te(u),m=p.isInitialized,v=p.error,g=p.chatbotConfig,b=p.isIframeVisible,E=p.toggleIframeVisibility,y=p.closeIframe,_=a((function(){return{api_key:n,user_profile:u.user_profile,onEvent:f,chatbotConfig:g?{isAnonymous:g.isAnonymous,userId:g.userId}:null}}),[n,u.user_profile,f,null==g?void 0:g.isAnonymous,null==g?void 0:g.userId]),I=ne(c({},_)),T=I.emitEvent,C=I.onInternalEvent;i((function(){if(n)try{D.initialize(n,r)}catch(e){D.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:L,errorType:F,context:{timestamp:Date.now()}})}else D.trackError(new Error(K[k](n)),"RobylonChatbot",{errorCode:k,errorType:F,context:{timestamp:Date.now()}})}),[n,r]);var x=o((function(){y(),T(h.CHATBOT_CLOSED)}),[y,T]),A=o((function(){E(),T(b?h.CHATBOT_CLOSED:h.CHATBOT_BUTTON_CLICKED)}),[E,T,b]),O=a((function(){return{config:g,toggleIframe:A,isIframeVisible:b,onEvent:f,onInternalEvent:C}}),[g,A,b,f,C]),S=a((function(){return{config:g,isVisible:b,onClose:x,onEvent:f,onInternalEvent:C}}),[g,b,x,f,C]);return n&&!v&&g?e.createElement(Z,{componentName:"RobylonChatbot"},m?e.createElement(e.Fragment,null,e.createElement(Z,{componentName:"ChatbotFloatingButton"},e.createElement(w,c({},O))),e.createElement(Z,{componentName:"ChatbotIframe"},e.createElement(J,c({},S)))):null):null}),(function(e,t){return e.api_key===t.api_key&&e.user_id===t.user_id&&e.user_token===t.user_token&&JSON.stringify(e.user_profile)===JSON.stringify(t.user_profile)&&!0})),oe=function(e){var t=s({isLoading:!0,isInitialized:!1,error:null}),n=t[0],o=t[1],r=function(e){o((function(t){return c(c({},t),{isInitialized:e})}))},a=function(e){o((function(t){return c(c({},t),{error:e})}))};return i((function(){!function(){try{ee(e,r,a)}catch(e){o((function(t){return c(c({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),n},re=function(){function e(e){this.config=e,this.buttonElement=document.createElement("div"),this.render(),this.mount()}return e.prototype.render=function(){var e=this,t=b().copilotUrl,n=this.config,i=n.config,o=n.isIframeVisible;if(Object.assign(this.buttonElement.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:i.brand_colour,color:f(i.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),this.buttonElement.className="message-bubble-container",o)this.buttonElement.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 <g id="Chevron_Down">\n <path\n id="Vector"\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </g>\n </svg>\n ';else{var r=document.createElement("img");r.src=i.image_url||"".concat(t,"/chatbubble.png"),r.alt="Chat",Object.assign(r.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}),this.buttonElement.innerHTML="",this.buttonElement.appendChild(r)}this.buttonElement.onclick=function(){e.config.toggleIframe()}},e.prototype.mount=function(){var e=this;document.body.appendChild(this.buttonElement),requestAnimationFrame((function(){var t,n;null===(n=(t=e.config).onEvent)||void 0===n||n.call(t,{type:h.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(h.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config=c(c({},this.config),e),this.render()},e.prototype.destroy=function(){this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},e}(),ae=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,f,p,m,g,E,w=b().copilotUrl;if(e.origin===w){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(v.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:h.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(h.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:h.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(h.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:h.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(h.CHAT_INITIALIZATION_FAILED,{error:null===(f=e.data)||void 0===f?void 0:f.error})),"SESSION_REFRESHED"===(null===(p=e.data)||void 0===p?void 0:p.type)&&(null===(g=(m=t.config).onEvent)||void 0===g||g.call(m,{type:h.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(h.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(E=e.data)||void 0===E?void 0:E.type)&&t.config.onInternalEvent(v.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.render=function(){Object.assign(this.iframeElement.style,{position:"fixed",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:this.config.isVisible?"block":"none"}),this.applyResponsiveStyles(),document.body.appendChild(this.iframeElement)},e.prototype.applyResponsiveStyles=function(){this.iframeElement&&(window.innerWidth<560?Object.assign(this.iframeElement.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(this.iframeElement.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"}))},e.prototype.initialize=function(){var e=this;if(!this.isInitialized){var t=b().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(){D.trackError(new Error(K[U]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:W,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;if(this.config.isVisible=e,this.iframeElement.style.display=e?"block":"none",this.iframeElement.contentWindow&&e){var c=b().copilotUrl,d=new URL(this.iframeElement.src).origin||c;this.iframeElement.contentWindow.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},d),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,action:"registerUserId",data:{userId:null===(i=this.config.config)||void 0===i?void 0:i.userId,token:null===(o=this.config.config)||void 0===o?void 0:o.token,userProfile:null===(r=this.config.config)||void 0===r?void 0:r.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},d),this.hasRegistered=!0),null===(l=(s=this.config).onEvent)||void 0===l||l.call(s,{type:h.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(h.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=c(c({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=b().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}(),se=function(e,t,n){return d(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,5,,6]),i=b().apiUrl,o="".concat(i,"/chat/chatbot/get/"),p.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{}},[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(a=u.sent()).ok?[3,3]:[4,a.text()];case 2:throw s=u.sent(),new Error(K[H](a.status,s));case 3:return[4,a.json()];case 4:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(K[B](["user","org_info"]));return[2,l];case 5:throw c=u.sent(),D.trackError(c instanceof Error?c:new Error(K[M]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?H:M,errorType:P,context:{apiKey:e,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},le=function(e){return d(void 0,void 0,void 0,(function(){var t,n,i,o,r,a,s,l,d,f,p,m,h,v;return u(this,(function(u){switch(u.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=Q("rblyn_anon")||G(),q("rblyn_anon",n,365),i=!0),[4,se(t.api_key,n,t.user_token)];case 1:return o=u.sent(),r=T(),g=t.user_profile,b=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],a=g?Object.fromEntries(Object.entries(g).filter((function(e){var t=e[0];return b.includes(t)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},s=c(c({},r),a),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",brand_colour:(null===(d=null===(l=o.user.org_info.brand_config)||void 0===l?void 0:l.colors)||void 0===d?void 0:d.brand_color)||"",image_url:(null===(p=null===(f=o.user.org_info)||void 0===f?void 0:f.brand_config)||void 0===p?void 0:p.launcher_logo_url)||"",userProfile:s,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===(h=o.user.org_info.brand_config)||void 0===h?void 0:h.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(v=o.user.org_info.brand_config)||void 0===v?void 0:v.redirect_url)||""}}]}var g,b}))}))},ce=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){}}},de=function(){function e(e){var t,n,i,o,r=this;if(this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){if(!r.isDestroyed){var t=e.isInitialized,n=e.error,i=e.chatbotConfig,o=e.isIframeVisible;!n&&i&&t&&(r.eventEmitter=ce({api_key:r.config.api_key,user_profile:r.config.user_profile,onEvent:r.config.onEvent,chatbotConfig:{isAnonymous:i.isAnonymous,userId:i.userId}}),r.floatingButton?r.floatingButton.update({config:i,isIframeVisible:o}):r.floatingButton=new re({config:i,toggleIframe:r.toggleIframe,isIframeVisible:o,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}),r.iframe?r.iframe.update({config:i,isVisible:o}):r.iframe=new ae({config:i,isVisible:o,onClose:r.handleClose,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}))}},this.toggleIframe=function(){var e=r.stateManager.getState();r.stateManager.toggleIframeVisibility(),r.eventEmitter.emit(e.isIframeVisible?h.CHATBOT_CLOSED:h.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){r.stateManager.closeIframe(),r.eventEmitter.emit(h.CHATBOT_CLOSED)},this.config=e,!e.api_key)throw D.trackError(new Error(K[k](e.api_key)),"RobylonChatbot",{errorCode:k,errorType:F,context:{timestamp:Date.now()}}),new Error("API key is required");try{D.initialize(e.api_key,e.user_id)}catch(e){D.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:L,errorType:F,context:{timestamp:Date.now()}})}this.stateManager=(t={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},n={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},i=[],{getState:function(){return n},initialize:function(){return d(void 0,void 0,void 0,(function(){var e,n,i;return u(this,(function(r){switch(r.label){case 0:if(!t.api_key)return D.trackError(new Error(K[k](t.api_key)),"ChatbotStateManager",{errorCode:k,errorType:F,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,le(t)];case 2:return e=r.sent(),[4,new Promise((function(t,n){ee(e,(function(){o({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),i=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:i}),D.trackError(n instanceof Error?n:new Error(i),"ChatbotStateManager",{errorCode:R,errorType:F,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!n.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o=function(e){n=c(c({},n),e),i.forEach((function(e){return e(n)}))},subscribe:function(e){return i.push(e),function(){var t=i.indexOf(e);t>-1&&i.splice(t,1)}}}),this.eventEmitter=ce({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),this.initialize()}return e.prototype.initialize=function(){return d(this,void 0,void 0,(function(){var e;return u(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(),D.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:R,errorType:F,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(h.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(h.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null)},e}();var ue={create:function(e){var t=new de(e);return{show:function(){return t.show()},hide:function(){return t.hide()},toggle:function(){return t.toggle()},destroy:function(){return t.destroy()}}}};export{ie as Chatbot,ue as RobylonChatbot,oe as useChatbot};
1
+ import e,{memo as t,useRef as n,useEffect as i,useCallback as o,Component as r,useMemo as a,useState as s}from"react";var l=function(e,t){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},l(e,t)};var c=function(){return c=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},c.apply(this,arguments)};function d(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 u(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;var f=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"},p={log:function(){},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]},info:function(){}};p.log("Raw API_URL:","https://stage-api.robylon.ai");var m={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};p.log("CONFIG",m);var h,v,g=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},b=function(){return{copilotUrl:m.copilotUrl||"https://app.robylon.ai",environment:m.environment||"production",apiUrl:m.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"}(h||(h={})),function(e){e.CHAT_MOVED="CHAT_MOVED",e.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(v||(v={}));var E,w=t((function(t){var o=t.config,r=t.toggleIframe,a=t.isIframeVisible,s=t.onEvent,l=t.onInternalEvent,c=n(null),d=b().copilotUrl;i((function(){c.current&&requestAnimationFrame((function(){null==s||s({type:h.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),l(h.CHATBOT_BUTTON_LOADED)}))}),[s,l]);return p.log("config chabotfloatingbutton",o),e.createElement("div",{ref:c,className:"message-bubble-container",style:{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:1e3,width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:o.brand_colour,color:f(o.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:r},a?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","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"}))):e.createElement("img",{src:o.image_url||"".concat(d,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))})),y=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]},_=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]},I=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)}},T=function(){return{platform:"web",os:y(),browser:_(),sdk_version:"1.1.34-staging.4",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:I()};var e};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(E||(E={}));var C,x=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],A=function(e){var t=e.filename,n=e.stack,i=e.message;return!!(t||n||i)&&x.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))}))},O=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};A(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)};A(o)&&e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){g()&&(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(){g()&&(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:T(),event_type:E.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){p.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 d(this,void 0,void 0,(function(){var e,t,n;return u(this,(function(i){switch(i.label){case 0:if(!this.preInitQueue.length)return[2];p.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,c(c({},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 d(this,void 0,void 0,(function(){var t,n,i,o,r,a;return u(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=b().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=p).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(),p.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return d(this,void 0,void 0,(function(){var i,o,r;return u(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:c(c({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:T(),event_type:E.ERROR,user_id:this.userId},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.sendLog(i)];case 2:return a.sent(),[3,4];case 3:return a.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),p.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:c(c({},n),{timestamp:Date.now()}),timestamp:Date.now()},r={org_id:this.apiKey||"UNINITALIZED",event_data:o,metadata:T(),event_type:E.ERROR,user_id:this.userId},[4,this.sendLog(r)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return d(this,void 0,void 0,(function(){var i,o;return u(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:T(),event_type:E.INFO,user_id:this.userId},[4,this.sendLog(o)]):(p.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),D=O.getInstance(),k="MISSING_API_KEY",S="INVALID_API_KEY",N="CONFIG_FETCH_FAILED",R="SDK_INIT_FAILED",L="ERROR_TRACKING_INIT_FAILED",H="API_REQUEST_FAILED",M="NETWORK_ERROR",B="INVALID_RESPONSE",U="IFRAME_LOAD_FAILED",z="COOKIE_ACCESS_ERROR",j="COMPONENT_RENDER_ERROR",F="INITIALIZATION_ERROR",P="API_ERROR",W="RUNTIME_ERROR",V="COMPONENT_ERROR",K=((C={})[k]=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.")},C[S]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},C[N]=function(e){return"Failed to fetch chatbot configuration: ".concat(e.statusCode?"Server responded with status ".concat(e.statusCode):"Could not reach server").concat(e.error?". Error: ".concat(e.error):"")},C[H]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},C[M]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},C[U]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},C[B]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},C[L]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},C[R]=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)):"")},C[z]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},C[j]=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):"")},C),J=t((function(t){var r=t.config,a=t.isVisible,s=t.onClose,l=t.onEvent,c=t.onInternalEvent,d=n(null),u=n(!1),f=n(!1),p=o((function(){var e=d.current;e&&((null===window||void 0===window?void 0:window.innerWidth)<560?(e.style.width="100vw",e.style.minWidth="300px",e.style.right="0",e.style.bottom="0",e.style.height="100vh",e.style.flexDirection="column",e.style.flexGrow="1",e.style.borderRadius="0",e.style.top="0",e.style.maxHeight="100%"):(e.style.width="26%",e.style.minWidth="400px",e.style.right="32px",e.style.bottom="86px",e.style.height="calc(100vh - 3rem - 10vh)",e.style.borderRadius="1rem",e.style.top="calc(10vh - 32px)",e.style.maxHeight="45rem"))}),[c]);return i((function(){return null===window||void 0===window||window.addEventListener("resize",p),p(),function(){return null===window||void 0===window?void 0:window.removeEventListener("resize",p)}}),[p]),i((function(){var e=d.current;if(e&&!u.current){var t=b().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(r.chatbotId),u.current=!0;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)}}}),[r.chatbotId]),i((function(){var e,t,n,i,o=d.current;if(o&&u.current){var s=b().copilotUrl;if(o.style.display=a?"block":"none",o.contentWindow&&a){var l=new URL(o.src).origin||s;null===(e=null==o?void 0:o.contentWindow)||void 0===e||e.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},l),(null==f?void 0:f.current)||(null===(n=o.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,action:"registerUserId",data:{userId:null==r?void 0:r.userId,token:null==r?void 0:r.token,userProfile:null==r?void 0:r.userProfile,isAnonymous:null==r?void 0:r.isAnonymous}},l),f.current=!0)}}}),[a,r.userId,r.token,r.userProfile]),i((function(){if(d.current&&u.current){var e=b().copilotUrl;a&&(null==l||l({type:h.CHATBOT_OPENED,timestamp:Date.now()}),c(h.CHATBOT_OPENED));var t=function(t){var n,i,o,r,a,d,u;if(t.origin===e){if("closeChatbot"===t.data)return void s();if("CHATBOT_TOKEN_EXHAUSTED"===(null===(n=t.data)||void 0===n?void 0:n.type))return void c(v.CHATBOT_TOKEN_EXHAUSTED);"CHATBOT_LOADED"===(null===(i=t.data)||void 0===i?void 0:i.type)&&(null==l||l({type:h.CHATBOT_LOADED,timestamp:Date.now()}),c(h.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==l||l({type:h.CHAT_INITIALIZED,timestamp:Date.now()}),c(h.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==l||l({type:h.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),c(h.CHAT_INITIALIZATION_FAILED,{error:null===(a=t.data)||void 0===a?void 0:a.error})),"SESSION_REFRESHED"===(null===(d=t.data)||void 0===d?void 0:d.type)&&(null==l||l({type:h.SESSION_REFRESHED,timestamp:Date.now()}),c(h.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(u=t.data)||void 0===u?void 0:u.type)&&c(v.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)}}}),[s,l,c,r.chatbotId,a]),i((function(){var e=d.current;if(e&&u.current){var t=function(){D.trackError(new Error(K[U]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:W,context:{config:r,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[r]),i((function(){var e;if(d.current&&r&&a){var t=d.current,n=b().copilotUrl;null===(e=t.contentWindow)||void 0===e||e.postMessage({action:"updateUserProfile",user_profile:r.userProfile},n)}}),[r.userProfile,a]),e.createElement("iframe",{ref:d,id:"chat-iframe-rbyln",style:{position:"fixed",zIndex:2e7,border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:a?"block":"none"}})})),Z=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={hasError:!1},t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.getDerivedStateFromError=function(e){return{hasError:!0}},t.prototype.componentDidCatch=function(e,t){D.trackError(new Error(K[j]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:j,errorType:V,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(r),Y=function(e,t,n){return d(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return u(this,(function(u){switch(u.label){case 0:i=b().apiUrl,o="".concat(i,"/chat/chatbot/get/"),p.log("endpointUrl",o),r={client_user_id:t,org_id:e,token:n||void 0,extra_info:{}},u.label=1;case 1:return u.trys.push([1,6,,7]),[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 2:return(a=u.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=u.sent(),new Error(K[H](a.status,s));case 4:return[4,a.json()];case 5:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(K[B](["user","org_info"]));return[2,l];case 6:throw c=u.sent(),D.trackError(c instanceof Error?c:new Error(K[M]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?H:M,errorType:P,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]}}))}))},G=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)}))},Q=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()},q=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=/")},X=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},$=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 p.log("expectedDomain, to current domain",t,n,t===n),t===n},e.prototype.createChatBubblContainer=function(){var e,t=this,n=document.createElement("div");n.id="chatbase-message-bubbles",Object.assign(n.style,{position:"fixed",bottom:"80px",borderRadius:"10px",fontFamily:"sans-serif",fontSize:"16px",zIndex:"2147483644",cursor:"pointer",flexDirection:"column",gap:"50px",maxWidth:"70vw",display:"block",right:"1rem",left:"unset"});var i=document.createElement("div");i.classList.add("close-btn"),i.textContent="✕",Object.assign(i.style,{position:"absolute",top:"-7px",right:"-7px",fontWeight:"bold",display:"none",justifyContent:"center",alignItems:"center",zIndex:"2147483643",width:"22px",height:"22px",borderRadius:"50%",textAlign:"center",fontSize:"12px",cursor:"pointer",backgroundColor:"rgb(224, 224, 224)",color:"black",boxShadow:"rgba(150, 150, 150, 0.15) 0px 6px 24px 0px, rgba(150, 150, 150, 0.15) 0px 0px 0px 1px"}),((null===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var i=t.createMessageBubble(e);n.appendChild(i)})),n.appendChild(i),document.body.appendChild(n)},e.prototype.createMessageBubble=function(e){var t=document.createElement("div");this.bubblePromptContainer=t,Object.assign(t.style,{display:"flex",position:"relative",justifyContent:"flex-end"});var n=document.createElement("div");n.classList.add("message"),n.textContent=e,Object.assign(n.style,{backgroundColor:"white",color:"black",boxShadow:"rgba(150, 150, 150, 0.2) 0px 10px 30px 0px, rgba(150, 150, 150, 0.2) 0px 0px 0px 1px",borderRadius:"10px",padding:"8px 5px",margin:"8px",fontSize:"14px",opacity:"1",transform:"scale(1)",transition:"opacity 0.5s ease 0s, transform 0.5s ease 0s"});var i=document.createElement("button");return i.innerHTML="&times;",Object.assign(i.style,{position:"absolute",top:"1px",left:"-3px",width:"20px",height:"20px",borderRadius:"50%",backgroundColor:"#fff",color:"#000",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 5px rgba(0,0,0,0.2)",fontSize:"14px",lineHeight:"1",padding:"0",zIndex:"100"}),i.addEventListener("click",(function(){t.remove()})),t.appendChild(i),t.appendChild(n),t},e.prototype.createFloatingButton=function(){var e=document.createElement("div");e.classList.add("message-bubble-container"),Object.assign(e.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:this.config.brand_colour,color:f(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=document.createElement("img");t.src=this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),t.alt="Chat",Object.assign(t.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=t,e.innerHTML="",e.appendChild(t)},e.prototype.createIframe=function(){var e=this;p.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),p.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:X(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;p.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(p.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;p.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"),p.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}(),ee=function(e,t,n){if(e.chatbotId&&e.userId)try{new $(e);t(!0),p.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},te=function(e){var t=a((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=s({isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1}),r=n[0],l=n[1],f=a((function(){var e=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"];return t.user_profile?Object.fromEntries(Object.entries(t.user_profile).filter((function(t){var n=t[0];return e.includes(n)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{}}),[JSON.stringify(t.user_profile)]),p=o((function(e){l((function(t){return c(c({},t),e)}))}),[]),m=o((function(){return d(void 0,void 0,void 0,(function(){var e,n,i,o,r,a,s,l,d,m,h,v,g,b,E;return u(this,(function(u){switch(u.label){case 0:if(!t.api_key)return D.trackError(new Error(K[k](t.api_key)),"useChatbotState",{errorCode:k,errorType:F,context:{timestamp:Date.now()}}),[2];p({isInitializing:!0}),u.label=1;case 1:return u.trys.push([1,4,5,6]),e=t.user_id||void 0,n=!1,e||(e=Q("rblyn_anon")||G(),q("rblyn_anon",e,365),n=!0),[4,Y(t.api_key,e,t.user_token)];case 2:return i=u.sent(),o=T(),r=c(c({},o),f),a={chatbotId:t.api_key,userId:e,token:t.user_token,isAnonymous:n,domain:"",brand_colour:(null===(m=null===(d=i.user.org_info.brand_config)||void 0===d?void 0:d.colors)||void 0===m?void 0:m.brand_color)||"",image_url:(null===(v=null===(h=i.user.org_info)||void 0===h?void 0:h.brand_config)||void 0===v?void 0:v.launcher_logo_url)||"",userProfile:r,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(g=i.user.org_info.brand_config)||void 0===g?void 0:g.display_name)||"",welcome_message:(null===(b=i.user.org_info.brand_config)||void 0===b?void 0:b.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)||""}},[4,new Promise((function(e,t){ee(a,(function(){p({isInitialized:!0,chatbotConfig:a}),e()}),(function(e){t(e)}))}))];case 3:return u.sent(),[3,6];case 4:return s=u.sent(),l=s instanceof Error?s.message:"Failed to initialize chatbot",p({error:l}),D.trackError(s instanceof Error?s:new Error(l),"useChatbotState",{errorCode:R,errorType:F,context:{timestamp:Date.now()}}),[3,6];case 5:return p({isInitializing:!1}),[7];case 6:return[2]}}))}))}),[t.api_key,t.user_id,t.user_token]);i((function(){t.api_key&&m()}),[m]),i((function(){r.chatbotConfig&&l((function(e){return c(c({},e),{chatbotConfig:c(c({},e.chatbotConfig),{userProfile:c(c({},T()),f)})})}))}),[f]);var h=o((function(){l((function(e){return c(c({},e),{isIframeVisible:!e.isIframeVisible})}))}),[]),v=o((function(){p({isIframeVisible:!1})}),[]);return c(c({},r),{toggleIframeVisibility:h,closeIframe:v})},ne=function(e){var t=e.api_key,n=e.chatbotConfig,i=e.user_profile,r=e.onEvent,s=a((function(){return{isAnonymous:(null==n?void 0:n.isAnonymous)||!1,userId:(null==n?void 0:n.userId)||""}}),[null==n?void 0:n.isAnonymous,null==n?void 0:n.userId]),l=a((function(){return i||{}}),[JSON.stringify(i)]),f=o((function(e){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return d(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,a,d,f,m;return void 0===n&&(n={}),u(this,(function(u){switch(u.label){case 0:if(!t)return[2];u.label=1;case 1:return u.trys.push([1,3,,4]),i=b().apiUrl,o=T(),r=c({trigger_time:Date.now(),channel:"CHATBOT",launch_url:(null===(m=null===window||void 0===window?void 0:window.location)||void 0===m?void 0:m.href)||"",org_id:t,client_user_id:s.isAnonymous?"Anonymous":String(s.userId),event_type:e,user_profile:l},n),a={org_id:t,event_data:r,metadata:c({timestamp:Date.now()},o),event_type:"INFO",user_id:s.userId},[4,fetch("".concat(i,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})];case 2:if(!(d=u.sent()).ok)throw new Error("Failed to send internal event: ".concat(d.statusText));return[3,4];case 3:return f=u.sent(),p.error("Failed to send internal event:",f),[3,4];case 4:return[2]}}))}))}),[t,s]);return{emitEvent:o((function(e,t){var n=Date.now();e!==h.CHATBOT_BUTTON_CLICKED&&e!==h.CHATBOT_CLOSED&&e!==h.CHATBOT_OPENED||(r&&r({type:e,timestamp:n,data:t}),f(e,{timestamp:n}))}),[r,f]),onInternalEvent:f}},ie=t((function(t){var n=t.api_key,r=t.user_id,s=t.user_token,l=t.user_profile,d=t.onEvent;i((function(){}));var u=a((function(){return{api_key:n,user_id:r,user_token:s,user_profile:l}}),[n,r,s,l]),f=o((function(e){null==d||d(e)}),[d]),p=te(u),m=p.isInitialized,v=p.error,g=p.chatbotConfig,b=p.isIframeVisible,E=p.toggleIframeVisibility,y=p.closeIframe,_=a((function(){return{api_key:n,user_profile:u.user_profile,onEvent:f,chatbotConfig:g?{isAnonymous:g.isAnonymous,userId:g.userId}:null}}),[n,u.user_profile,f,null==g?void 0:g.isAnonymous,null==g?void 0:g.userId]),I=ne(c({},_)),T=I.emitEvent,C=I.onInternalEvent;i((function(){if(n)try{D.initialize(n,r)}catch(e){D.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:L,errorType:F,context:{timestamp:Date.now()}})}else D.trackError(new Error(K[k](n)),"RobylonChatbot",{errorCode:k,errorType:F,context:{timestamp:Date.now()}})}),[n,r]);var x=o((function(){y(),T(h.CHATBOT_CLOSED)}),[y,T]),A=o((function(){E(),T(b?h.CHATBOT_CLOSED:h.CHATBOT_BUTTON_CLICKED)}),[E,T,b]),O=a((function(){return{config:g,toggleIframe:A,isIframeVisible:b,onEvent:f,onInternalEvent:C}}),[g,A,b,f,C]),S=a((function(){return{config:g,isVisible:b,onClose:x,onEvent:f,onInternalEvent:C}}),[g,b,x,f,C]);return n&&!v&&g?e.createElement(Z,{componentName:"RobylonChatbot"},m?e.createElement(e.Fragment,null,e.createElement(Z,{componentName:"ChatbotFloatingButton"},e.createElement(w,c({},O))),e.createElement(Z,{componentName:"ChatbotIframe"},e.createElement(J,c({},S)))):null):null}),(function(e,t){return e.api_key===t.api_key&&e.user_id===t.user_id&&e.user_token===t.user_token&&JSON.stringify(e.user_profile)===JSON.stringify(t.user_profile)&&!0})),oe=function(e){var t=s({isLoading:!0,isInitialized:!1,error:null}),n=t[0],o=t[1],r=function(e){o((function(t){return c(c({},t),{isInitialized:e})}))},a=function(e){o((function(t){return c(c({},t),{error:e})}))};return i((function(){!function(){try{ee(e,r,a)}catch(e){o((function(t){return c(c({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),n},re=function(){function e(e){this.config=e,this.buttonElement=document.createElement("div"),this.render(),this.mount()}return e.prototype.render=function(){var e=this,t=b().copilotUrl,n=this.config,i=n.config,o=n.isIframeVisible;if(Object.assign(this.buttonElement.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:i.brand_colour,color:f(i.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),this.buttonElement.className="message-bubble-container",o)this.buttonElement.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 <g id="Chevron_Down">\n <path\n id="Vector"\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </g>\n </svg>\n ';else{var r=document.createElement("img");r.src=i.image_url||"".concat(t,"/chatbubble.png"),r.alt="Chat",Object.assign(r.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}),this.buttonElement.innerHTML="",this.buttonElement.appendChild(r)}this.buttonElement.onclick=function(){e.config.toggleIframe()}},e.prototype.mount=function(){var e=this;document.body.appendChild(this.buttonElement),requestAnimationFrame((function(){var t,n;null===(n=(t=e.config).onEvent)||void 0===n||n.call(t,{type:h.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),e.config.onInternalEvent(h.CHATBOT_BUTTON_LOADED)}))},e.prototype.update=function(e){this.config=c(c({},this.config),e),this.render()},e.prototype.destroy=function(){this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},e}(),ae=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,f,p,m,g,E,w=b().copilotUrl;if(e.origin===w){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(v.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:h.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(h.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:h.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(h.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:h.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(h.CHAT_INITIALIZATION_FAILED,{error:null===(f=e.data)||void 0===f?void 0:f.error})),"SESSION_REFRESHED"===(null===(p=e.data)||void 0===p?void 0:p.type)&&(null===(g=(m=t.config).onEvent)||void 0===g||g.call(m,{type:h.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(h.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(E=e.data)||void 0===E?void 0:E.type)&&t.config.onInternalEvent(v.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.render=function(){Object.assign(this.iframeElement.style,{position:"fixed",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:this.config.isVisible?"block":"none"}),this.applyResponsiveStyles(),document.body.appendChild(this.iframeElement)},e.prototype.applyResponsiveStyles=function(){this.iframeElement&&(window.innerWidth<560?Object.assign(this.iframeElement.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(this.iframeElement.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"}))},e.prototype.initialize=function(){var e=this;if(!this.isInitialized){var t=b().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(){D.trackError(new Error(K[U]({src:e.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:U,errorType:W,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;if(this.config.isVisible=e,this.iframeElement.style.display=e?"block":"none",this.iframeElement.contentWindow&&e){var c=b().copilotUrl,d=new URL(this.iframeElement.src).origin||c;this.iframeElement.contentWindow.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},d),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,action:"registerUserId",data:{userId:null===(i=this.config.config)||void 0===i?void 0:i.userId,token:null===(o=this.config.config)||void 0===o?void 0:o.token,userProfile:null===(r=this.config.config)||void 0===r?void 0:r.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},d),this.hasRegistered=!0),null===(l=(s=this.config).onEvent)||void 0===l||l.call(s,{type:h.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(h.CHATBOT_OPENED)}},e.prototype.update=function(e){var t=this.config.isVisible;if(this.config=c(c({},this.config),e),t!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var n=b().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}(),se=function(e,t,n){return d(void 0,void 0,void 0,(function(){var i,o,r,a,s,l,c,d;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,5,,6]),i=b().apiUrl,o="".concat(i,"/chat/chatbot/get/"),p.log("endpointUrl",o),r={client_user_id:t||null,org_id:e,token:n||void 0,extra_info:{}},[4,fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})];case 1:return(a=u.sent()).ok?[3,3]:[4,a.text()];case 2:throw s=u.sent(),new Error(K[H](a.status,s));case 3:return[4,a.json()];case 4:if(l=u.sent(),!(null===(d=null==l?void 0:l.user)||void 0===d?void 0:d.org_info))throw new Error(K[B](["user","org_info"]));return[2,l];case 5:throw c=u.sent(),D.trackError(c instanceof Error?c:new Error(K[M]({error:String(c)})),"fetchChatbotConfig",{errorCode:c instanceof Error&&c.message.includes("API Request Failed")?H:M,errorType:P,context:{apiKey:e,userId:t,timestamp:Date.now()}}),c;case 6:return[2]}}))}))},le=function(e){return d(void 0,void 0,void 0,(function(){var t,n,i,o,r,a,s,l,d,f,p,m,h,v;return u(this,(function(u){switch(u.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=Q("rblyn_anon")||G(),q("rblyn_anon",n,365),i=!0),[4,se(t.api_key,n,t.user_token)];case 1:return o=u.sent(),r=T(),g=t.user_profile,b=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],a=g?Object.fromEntries(Object.entries(g).filter((function(e){var t=e[0];return b.includes(t)})).map((function(e){var t=e[0],n=e[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,String(n)]}))):{},s=c(c({},r),a),[2,{chatbotId:t.api_key,userId:n,token:t.user_token,isAnonymous:i,domain:"",brand_colour:(null===(d=null===(l=o.user.org_info.brand_config)||void 0===l?void 0:l.colors)||void 0===d?void 0:d.brand_color)||"",image_url:(null===(p=null===(f=o.user.org_info)||void 0===f?void 0:f.brand_config)||void 0===p?void 0:p.launcher_logo_url)||"",userProfile:s,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===(h=o.user.org_info.brand_config)||void 0===h?void 0:h.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(v=o.user.org_info.brand_config)||void 0===v?void 0:v.redirect_url)||""}}]}var g,b}))}))},ce=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){}}},de=function(){function e(e){var t,n,i,o,r=this;if(this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(e){if(!r.isDestroyed){var t=e.isInitialized,n=e.error,i=e.chatbotConfig,o=e.isIframeVisible;!n&&i&&t&&(r.eventEmitter=ce({api_key:r.config.api_key,user_profile:r.config.user_profile,onEvent:r.config.onEvent,chatbotConfig:{isAnonymous:i.isAnonymous,userId:i.userId}}),r.floatingButton?r.floatingButton.update({config:i,isIframeVisible:o}):r.floatingButton=new re({config:i,toggleIframe:r.toggleIframe,isIframeVisible:o,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}),r.iframe?r.iframe.update({config:i,isVisible:o}):r.iframe=new ae({config:i,isVisible:o,onClose:r.handleClose,onEvent:r.config.onEvent,onInternalEvent:r.eventEmitter.onInternalEvent}))}},this.toggleIframe=function(){var e=r.stateManager.getState();r.stateManager.toggleIframeVisibility(),r.eventEmitter.emit(e.isIframeVisible?h.CHATBOT_CLOSED:h.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){r.stateManager.closeIframe(),r.eventEmitter.emit(h.CHATBOT_CLOSED)},this.config=e,!e.api_key)throw D.trackError(new Error(K[k](e.api_key)),"RobylonChatbot",{errorCode:k,errorType:F,context:{timestamp:Date.now()}}),new Error("API key is required");try{D.initialize(e.api_key,e.user_id)}catch(e){D.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot",{errorCode:L,errorType:F,context:{timestamp:Date.now()}})}this.stateManager=(t={api_key:e.api_key,user_id:e.user_id,user_token:e.user_token,user_profile:e.user_profile},n={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},i=[],{getState:function(){return n},initialize:function(){return d(void 0,void 0,void 0,(function(){var e,n,i;return u(this,(function(r){switch(r.label){case 0:if(!t.api_key)return D.trackError(new Error(K[k](t.api_key)),"ChatbotStateManager",{errorCode:k,errorType:F,context:{timestamp:Date.now()}}),[2];o({isInitializing:!0}),r.label=1;case 1:return r.trys.push([1,4,5,6]),[4,le(t)];case 2:return e=r.sent(),[4,new Promise((function(t,n){ee(e,(function(){o({isInitialized:!0,chatbotConfig:e}),t()}),(function(e){n(e)}))}))];case 3:return r.sent(),[3,6];case 4:return n=r.sent(),i=n instanceof Error?n.message:"Failed to initialize chatbot",o({error:i}),D.trackError(n instanceof Error?n:new Error(i),"ChatbotStateManager",{errorCode:R,errorType:F,context:{timestamp:Date.now()}}),[3,6];case 5:return o({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){o({isIframeVisible:!n.isIframeVisible})},closeIframe:function(){o({isIframeVisible:!1})},updateState:o=function(e){n=c(c({},n),e),i.forEach((function(e){return e(n)}))},subscribe:function(e){return i.push(e),function(){var t=i.indexOf(e);t>-1&&i.splice(t,1)}}}),this.eventEmitter=ce({api_key:e.api_key,user_profile:e.user_profile,onEvent:e.onEvent,chatbotConfig:null}),this.initialize()}return e.prototype.initialize=function(){return d(this,void 0,void 0,(function(){var e;return u(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(),D.trackError(e instanceof Error?e:new Error(String(e)),"RobylonChatbot.initialize",{errorCode:R,errorType:F,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},e.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(h.CHATBOT_BUTTON_CLICKED))},e.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(h.CHATBOT_CLOSED))},e.prototype.toggle=function(){this.toggleIframe()},e.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null)},e}();var ue={create:function(e){var t=new de(e);return{show:function(){return t.show()},hide:function(){return t.hide()},toggle:function(){return t.toggle()},destroy:function(){return t.destroy()}}}};export{ie as Chatbot,ue as RobylonChatbot,oe 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=function(){return t=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},t.apply(this,arguments)};function n(i,t,n,o){return new(n||(n=Promise))((function(e,r){function a(i){try{d(o.next(i))}catch(i){r(i)}}function s(i){try{d(o.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?e(i.value):(t=i.value,t instanceof n?t:new n((function(i){i(t)}))).then(a,s)}d((o=o.apply(i,t||[])).next())}))}function o(i,t){var n,o,e,r={label:0,sent:function(){if(1&e[0])throw e[1];return e[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(d){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,o&&(e=2&s[0]?o.return:s[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,s[1])).done)return e;switch(o=0,e&&(s=[2&s[0],e.value]),s[0]){case 0:case 1:e=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,o=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!((e=(e=r.trys).length>0&&e[e.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!e||s[1]>e[0]&&s[1]<e[3])){r.label=s[1];break}if(6===s[0]&&r.label<e[1]){r.label=e[1],e=s;break}if(e&&r.label<e[2]){r.label=e[2],r.ops.push(s);break}e[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(i,r)}catch(i){s=[6,i],o=0}finally{n=e=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,d])}}}"function"==typeof SuppressedError&&SuppressedError;var e=function(i,t){void 0===t&&(t=.5);var n,o,e,r,a=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=a.r,o=a.g,e=a.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"},r={log:function(){},error:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t]},warn:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t]},info:function(){}};r.log("Raw API_URL:","https://stage-api.robylon.ai");var a={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};r.log("CONFIG",a);var s,d,u=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},c=function(){return{copilotUrl:a.copilotUrl||"https://app.robylon.ai",environment:a.environment||"production",apiUrl:a.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"}(s||(s={})),function(i){i.CHAT_MOVED="CHAT_MOVED",i.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(d||(d={}));var l,h=function(){function i(i){this.config=i,this.buttonElement=document.createElement("div"),this.render(),this.mount()}return i.prototype.render=function(){var i=this,t=c().copilotUrl,n=this.config,o=n.config,r=n.isIframeVisible;if(Object.assign(this.buttonElement.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:o.brand_colour,color:e(o.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),this.buttonElement.className="message-bubble-container",r)this.buttonElement.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 <g id="Chevron_Down">\n <path\n id="Vector"\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </g>\n </svg>\n ';else{var a=document.createElement("img");a.src=o.image_url||"".concat(t,"/chatbubble.png"),a.alt="Chat",Object.assign(a.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}),this.buttonElement.innerHTML="",this.buttonElement.appendChild(a)}this.buttonElement.onclick=function(){i.config.toggleIframe()}},i.prototype.mount=function(){var i=this;document.body.appendChild(this.buttonElement),requestAnimationFrame((function(){var t,n;null===(n=(t=i.config).onEvent)||void 0===n||n.call(t,{type:s.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),i.config.onInternalEvent(s.CHATBOT_BUTTON_LOADED)}))},i.prototype.update=function(i){this.config=t(t({},this.config),i),this.render()},i.prototype.destroy=function(){this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},i}(),f=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]},v=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]},m=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)}},p=function(){return{platform:"web",os:f(),browser:v(),sdk_version:"1.1.34-staging.9",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:m()};var i};!function(i){i.ERROR="ERROR",i.INFO="INFO"}(l||(l={}));var w,b=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],g=function(i){var t=i.filename,n=i.stack,o=i.message;return!!(t||n||o)&&b.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))}))},x=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};g(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+""};g(e)&&i.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return i.prototype.setupGlobalHandlers=function(){u()&&(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(){u()&&(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:p(),event_type:l.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=i,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){r.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 n(this,void 0,void 0,(function(){var i,n,e;return o(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];r.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),i=0,n=this.preInitQueue,o.label=1;case 1:return i<n.length?(e=n[i],[4,this.trackError(e.error,e.componentName,t(t({},e.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 n(this,void 0,void 0,(function(){var t,n,e,a,s,d;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),t=c().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 1:return(n=o.sent()).ok?[3,3]:(a=(e=r).error,s=["Failed to send error log:"],[4,n.text()]);case 2:a.apply(e,s.concat([o.sent()])),o.label=3;case 3:return[3,5];case 4:return d=o.sent(),r.error("Error sending log:",d),[3,5];case 5:return[2]}}))}))},i.prototype.trackError=function(i,e,a){return n(this,void 0,void 0,(function(){var n,s,d;return o(this,(function(o){switch(o.label){case 0:if(this.isInitialized)return[3,5];n={org_id:"UNINITALIZED",event_data:{message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:e,additionalInfo:t(t({},a),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:p(),event_type:l.ERROR,user_id:this.userId},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.sendLog(n)];case 2:return o.sent(),[3,4];case 3:return o.sent(),this.preInitQueue.push({error:i,componentName:e,additionalInfo:a}),r.warn("Error tracked before initialization, queuing:",i),[3,4];case 4:return[2];case 5:return s={message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:e,additionalInfo:t(t({},a),{timestamp:Date.now()}),timestamp:Date.now()},d={org_id:this.apiKey||"UNINITALIZED",event_data:s,metadata:p(),event_type:l.ERROR,user_id:this.userId},[4,this.sendLog(d)];case 6:return o.sent(),[2]}}))}))},i.prototype.trackInfo=function(i,t,e){return n(this,void 0,void 0,(function(){var n,a;return o(this,(function(o){switch(o.label){case 0:return this.apiKey?(n={message:i,componentName:t,additionalInfo:e,timestamp:Date.now()},a={org_id:this.apiKey,event_data:n,metadata:p(),event_type:l.INFO,user_id:this.userId},[4,this.sendLog(a)]):(r.error("Error tracking not initialized"),[2]);case 1:return o.sent(),[2]}}))}))},i}(),I=x.getInstance(),y="MISSING_API_KEY",E="SDK_INIT_FAILED",_="ERROR_TRACKING_INIT_FAILED",T="API_REQUEST_FAILED",A="NETWORK_ERROR",S="INVALID_RESPONSE",C="IFRAME_LOAD_FAILED",D="INITIALIZATION_ERROR",k=((w={})[y]=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.")},w.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.")},w.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):"")},w[T]=function(i,t,n){return"API Request Failed: Server responded with status ".concat(i," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},w[A]=function(i){return"Network Error: Failed to communicate with server".concat(i.url?" at ".concat(i.url):"").concat(i.error?" - ".concat(i.error):"")},w[C]=function(i){return"Failed to load chatbot interface".concat(i.src?" from ".concat(i.src):"").concat(i.error?". Error: ".concat(i.error):"")},w[S]=function(i){return"Invalid API Response: Missing required fields in response data: ".concat(i.join(", "))},w[_]=function(i){return"Error Tracking Service initialization failed".concat(i.apiKey?" for API key ".concat(i.apiKey):"").concat(i.error?". Error: ".concat(i.error):"")},w[E]=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)):"")},w.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.")},w.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):"")},w),O=function(){function i(i){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(i){var n,o,e,r,a,u,l,h,f,v,m,p,w,b,g,x=c().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(d.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:s.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(s.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=i.data)||void 0===a?void 0:a.type)&&(null===(l=(u=t.config).onEvent)||void 0===l||l.call(u,{type:s.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(s.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(h=i.data)||void 0===h?void 0:h.type)&&(null===(v=(f=t.config).onEvent)||void 0===v||v.call(f,{type:s.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(s.CHAT_INITIALIZATION_FAILED,{error:null===(m=i.data)||void 0===m?void 0:m.error})),"SESSION_REFRESHED"===(null===(p=i.data)||void 0===p?void 0:p.type)&&(null===(b=(w=t.config).onEvent)||void 0===b||b.call(w,{type:s.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(s.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=i.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(d.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.render=function(){Object.assign(this.iframeElement.style,{position:"fixed",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:this.config.isVisible?"block":"none"}),this.applyResponsiveStyles(),document.body.appendChild(this.iframeElement)},i.prototype.applyResponsiveStyles=function(){this.iframeElement&&(560>window.innerWidth?Object.assign(this.iframeElement.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(this.iframeElement.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"}))},i.prototype.initialize=function(){var i=this;if(!this.isInitialized){var t=c().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(){I.trackError(Error(k[C]({src:i.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:C,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,a,d,u;if(this.config.isVisible=i,this.iframeElement.style.display=i?"block":"none",this.iframeElement.contentWindow&&i){var l=c().copilotUrl,h=new URL(this.iframeElement.src).origin||l;this.iframeElement.contentWindow.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},h),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,action:"registerUserId",data:{userId:null===(o=this.config.config)||void 0===o?void 0:o.userId,token:null===(e=this.config.config)||void 0===e?void 0:e.token,userProfile:null===(r=this.config.config)||void 0===r?void 0:r.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},h),this.hasRegistered=!0),null===(u=(d=this.config).onEvent)||void 0===u||u.call(d,{type:s.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(s.CHATBOT_OPENED)}},i.prototype.update=function(i){var n=this.config.isVisible;if(this.config=t(t({},this.config),i),n!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var o=c().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},o)}},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}(),R=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},M=function(i,t,e){return n(void 0,void 0,void 0,(function(){var n,a,s,d,u,l,h;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),n=c().apiUrl,r.log("endpointUrl",a="".concat(n,"/chat/chatbot/get/")),[4,fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_user_id:t||null,org_id:i,token:e||void 0,extra_info:{}})})];case 1:return(s=o.sent()).ok?[3,3]:[4,s.text()];case 2:throw d=o.sent(),Error(k[T](s.status,d));case 3:return[4,s.json()];case 4:if(u=o.sent(),!(null===(h=null==u?void 0:u.user)||void 0===h?void 0:h.org_info))throw Error(k[S](["user","org_info"]));return[2,u];case 5:throw l=o.sent(),I.trackError(l instanceof Error?l:Error(k[A]({error:l+""})),"fetchChatbotConfig",{errorCode:l instanceof Error&&l.message.includes("API Request Failed")?T:A,errorType:"API_ERROR",context:{apiKey:i,userId:t,timestamp:Date.now()}}),l;case 6:return[2]}}))}))},N=function(i){return n(void 0,void 0,void 0,(function(){var n,e,r,a,s,d,u,c,l,h,f,v,m,w;return o(this,(function(o){switch(o.label){case 0:return n=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),e=n.user_id||void 0,r=!1,e||(e=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)})),x=e,(I=new Date).setTime(I.getTime()+31536e6),document.cookie="".concat("rblyn_anon","=").concat(x,";expires=").concat(I.toUTCString(),";path=/"),r=!0),[4,M(n.api_key,e,n.user_token)];case 1:return a=o.sent(),s=p(),b=n.user_profile,g=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],d=b?Object.fromEntries(Object.entries(b).filter((function(i){var t=i[0];return g.includes(t)})).map((function(i){var t=i[0],n=i[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,n+""]}))):{},u=t(t({},s),d),[2,{chatbotId:n.api_key,userId:e,token:n.user_token,isAnonymous:r,domain:"",brand_colour:(null===(l=null===(c=a.user.org_info.brand_config)||void 0===c?void 0:c.colors)||void 0===l?void 0:l.brand_color)||"",image_url:(null===(f=null===(h=a.user.org_info)||void 0===h?void 0:h.brand_config)||void 0===f?void 0:f.launcher_logo_url)||"",userProfile:u,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(v=a.user.org_info.brand_config)||void 0===v?void 0:v.display_name)||"",welcome_message:(null===(m=a.user.org_info.brand_config)||void 0===m?void 0:m.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(w=a.user.org_info.brand_config)||void 0===w?void 0:w.redirect_url)||""}}]}var b,g,x,I}))}))},j=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 r.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="&times;",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:e(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=document.createElement("img");t.src=this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),t.alt="Chat",Object.assign(t.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=t,i.innerHTML="",i.appendChild(t)},i.prototype.createIframe=function(){var i=this;r.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),r.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 a=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"},a),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}},a)}})),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,a={cookies:R(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(a,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;r.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(r.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;r.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"),r.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}(),z=function(i){var e={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},a=[],s=function(i){e=t(t({},e),i),a.forEach((function(i){return i(e)}))};return{getState:function(){return e},initialize:function(){return n(void 0,void 0,void 0,(function(){var t,n,e;return o(this,(function(o){switch(o.label){case 0:if(!i.api_key)return I.trackError(Error(k[y](i.api_key)),"ChatbotStateManager",{errorCode:y,errorType:D,context:{timestamp:Date.now()}}),[2];s({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,N(i)];case 2:return t=o.sent(),[4,new Promise((function(i,n){!function(n,o,e){if(n.chatbotId&&n.userId)try{new j(n),s({isInitialized:!0,chatbotConfig:t}),i(),r.log("Robylon SDK initialized successfully.")}catch(i){e(i instanceof Error?i.message:"Failed to initialize SDK")}else e("Incomplete configuration for SDK initialization.")}(t,0,(function(i){n(i)}))}))];case 3:return o.sent(),[3,6];case 4:return n=o.sent(),e=n instanceof Error?n.message:"Failed to initialize chatbot",s({error:e}),I.trackError(n instanceof Error?n:Error(e),"ChatbotStateManager",{errorCode:E,errorType:D,context:{timestamp:Date.now()}}),[3,6];case 5:return s({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){s({isIframeVisible:!e.isIframeVisible})},closeIframe:function(){s({isIframeVisible:!1})},updateState:s,subscribe:function(i){return a.push(i),function(){var t=a.indexOf(i);t>-1&&a.splice(t,1)}}}},U=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){}}},F=function(){function i(i){var t=this;if(this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(i){if(!t.isDestroyed){var n=i.isInitialized,o=i.error,e=i.chatbotConfig,r=i.isIframeVisible;!o&&e&&n&&(t.eventEmitter=U({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:e.isAnonymous,userId:e.userId}}),t.floatingButton?t.floatingButton.update({config:e,isIframeVisible:r}):t.floatingButton=new h({config:e,toggleIframe:t.toggleIframe,isIframeVisible:r,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}),t.iframe?t.iframe.update({config:e,isVisible:r}):t.iframe=new O({config:e,isVisible:r,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}))}},this.toggleIframe=function(){var i=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(i.isIframeVisible?s.CHATBOT_CLOSED:s.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(s.CHATBOT_CLOSED)},this.config=i,!i.api_key)throw I.trackError(Error(k[y](i.api_key)),"RobylonChatbot",{errorCode:y,errorType:D,context:{timestamp:Date.now()}}),Error("API key is required");try{I.initialize(i.api_key,i.user_id)}catch(i){I.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot",{errorCode:_,errorType:D,context:{timestamp:Date.now()}})}this.stateManager=z({api_key:i.api_key,user_id:i.user_id,user_token:i.user_token,user_profile:i.user_profile}),this.eventEmitter=U({api_key:i.api_key,user_profile:i.user_profile,onEvent:i.onEvent,chatbotConfig:null}),this.initialize()}return i.prototype.initialize=function(){return n(this,void 0,void 0,(function(){var i;return o(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(),I.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot.initialize",{errorCode:E,errorType:D,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},i.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(s.CHATBOT_BUTTON_CLICKED))},i.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(s.CHATBOT_CLOSED))},i.prototype.toggle=function(){this.toggleIframe()},i.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null)},i}();function L(i){var t=new F(i);return{show:function(){return t.show()},hide:function(){return t.hide()},toggle:function(){return t.toggle()},destroy:function(){return t.destroy()}}}var P={create:L};i.RobylonChatbot=P,i.create=L}));
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=function(){return t=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},t.apply(this,arguments)};function n(i,t,n,o){return new(n||(n=Promise))((function(e,r){function a(i){try{d(o.next(i))}catch(i){r(i)}}function s(i){try{d(o.throw(i))}catch(i){r(i)}}function d(i){var t;i.done?e(i.value):(t=i.value,t instanceof n?t:new n((function(i){i(t)}))).then(a,s)}d((o=o.apply(i,t||[])).next())}))}function o(i,t){var n,o,e,r={label:0,sent:function(){if(1&e[0])throw e[1];return e[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(d){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,o&&(e=2&s[0]?o.return:s[0]?o.throw||((e=o.return)&&e.call(o),0):o.next)&&!(e=e.call(o,s[1])).done)return e;switch(o=0,e&&(s=[2&s[0],e.value]),s[0]){case 0:case 1:e=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,o=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!((e=(e=r.trys).length>0&&e[e.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!e||s[1]>e[0]&&s[1]<e[3])){r.label=s[1];break}if(6===s[0]&&r.label<e[1]){r.label=e[1],e=s;break}if(e&&r.label<e[2]){r.label=e[2],r.ops.push(s);break}e[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(i,r)}catch(i){s=[6,i],o=0}finally{n=e=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,d])}}}"function"==typeof SuppressedError&&SuppressedError;var e=function(i,t){void 0===t&&(t=.5);var n,o,e,r,a=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=a.r,o=a.g,e=a.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"},r={log:function(){},error:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t]},warn:function(){for(var i=[],t=0;arguments.length>t;t++)i[t]=arguments[t]},info:function(){}};r.log("Raw API_URL:","https://stage-api.robylon.ai");var a={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"};r.log("CONFIG",a);var s,d,u=function(){return"undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement},c=function(){return{copilotUrl:a.copilotUrl||"https://app.robylon.ai",environment:a.environment||"production",apiUrl:a.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"}(s||(s={})),function(i){i.CHAT_MOVED="CHAT_MOVED",i.CHATBOT_TOKEN_EXHAUSTED="CHATBOT_TOKEN_EXHAUSTED"}(d||(d={}));var l,h=function(){function i(i){this.config=i,this.buttonElement=document.createElement("div"),this.render(),this.mount()}return i.prototype.render=function(){var i=this,t=c().copilotUrl,n=this.config,o=n.config,r=n.isIframeVisible;if(Object.assign(this.buttonElement.style,{position:"fixed",bottom:"1.5rem",right:"1.5rem",zIndex:"1000",width:"48px",height:"48px",display:"flex",flexDirection:"column-reverse",backgroundColor:o.brand_colour,color:e(o.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"}),this.buttonElement.className="message-bubble-container",r)this.buttonElement.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 <g id="Chevron_Down">\n <path\n id="Vector"\n d="M19 9L12 16L5 9"\n stroke="currentColor"\n stroke-width="1.5"\n stroke-linecap="round"\n stroke-linejoin="round"\n />\n </g>\n </svg>\n ';else{var a=document.createElement("img");a.src=o.image_url||"".concat(t,"/chatbubble.png"),a.alt="Chat",Object.assign(a.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}),this.buttonElement.innerHTML="",this.buttonElement.appendChild(a)}this.buttonElement.onclick=function(){i.config.toggleIframe()}},i.prototype.mount=function(){var i=this;document.body.appendChild(this.buttonElement),requestAnimationFrame((function(){var t,n;null===(n=(t=i.config).onEvent)||void 0===n||n.call(t,{type:s.CHATBOT_BUTTON_LOADED,timestamp:Date.now()}),i.config.onInternalEvent(s.CHATBOT_BUTTON_LOADED)}))},i.prototype.update=function(i){this.config=t(t({},this.config),i),this.render()},i.prototype.destroy=function(){this.buttonElement&&this.buttonElement.parentNode&&this.buttonElement.parentNode.removeChild(this.buttonElement)},i}(),f=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]},v=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]},m=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)}},p=function(){return{platform:"web",os:f(),browser:v(),sdk_version:"1.1.34-staging.4",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:m()};var i};!function(i){i.ERROR="ERROR",i.INFO="INFO"}(l||(l={}));var w,b=["@robylon/web-react-sdk","node_modules/@robylon/web-react-sdk/"],g=function(i){var t=i.filename,n=i.stack,o=i.message;return!!(t||n||o)&&b.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))}))},x=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};g(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+""};g(e)&&i.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})},this.setupGlobalHandlers()}return i.prototype.setupGlobalHandlers=function(){u()&&(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(){u()&&(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:p(),event_type:l.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=i,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){r.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 n(this,void 0,void 0,(function(){var i,n,e;return o(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];r.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),i=0,n=this.preInitQueue,o.label=1;case 1:return i<n.length?(e=n[i],[4,this.trackError(e.error,e.componentName,t(t({},e.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 n(this,void 0,void 0,(function(){var t,n,e,a,s,d;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),t=c().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 1:return(n=o.sent()).ok?[3,3]:(a=(e=r).error,s=["Failed to send error log:"],[4,n.text()]);case 2:a.apply(e,s.concat([o.sent()])),o.label=3;case 3:return[3,5];case 4:return d=o.sent(),r.error("Error sending log:",d),[3,5];case 5:return[2]}}))}))},i.prototype.trackError=function(i,e,a){return n(this,void 0,void 0,(function(){var n,s,d;return o(this,(function(o){switch(o.label){case 0:if(this.isInitialized)return[3,5];n={org_id:"UNINITALIZED",event_data:{message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:e,additionalInfo:t(t({},a),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:p(),event_type:l.ERROR,user_id:this.userId},o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.sendLog(n)];case 2:return o.sent(),[3,4];case 3:return o.sent(),this.preInitQueue.push({error:i,componentName:e,additionalInfo:a}),r.warn("Error tracked before initialization, queuing:",i),[3,4];case 4:return[2];case 5:return s={message:i instanceof Error?i.message:i,stack:i instanceof Error?i.stack:void 0,componentName:e,additionalInfo:t(t({},a),{timestamp:Date.now()}),timestamp:Date.now()},d={org_id:this.apiKey||"UNINITALIZED",event_data:s,metadata:p(),event_type:l.ERROR,user_id:this.userId},[4,this.sendLog(d)];case 6:return o.sent(),[2]}}))}))},i.prototype.trackInfo=function(i,t,e){return n(this,void 0,void 0,(function(){var n,a;return o(this,(function(o){switch(o.label){case 0:return this.apiKey?(n={message:i,componentName:t,additionalInfo:e,timestamp:Date.now()},a={org_id:this.apiKey,event_data:n,metadata:p(),event_type:l.INFO,user_id:this.userId},[4,this.sendLog(a)]):(r.error("Error tracking not initialized"),[2]);case 1:return o.sent(),[2]}}))}))},i}(),I=x.getInstance(),y="MISSING_API_KEY",E="SDK_INIT_FAILED",_="ERROR_TRACKING_INIT_FAILED",T="API_REQUEST_FAILED",A="NETWORK_ERROR",S="INVALID_RESPONSE",C="IFRAME_LOAD_FAILED",D="INITIALIZATION_ERROR",k=((w={})[y]=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.")},w.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.")},w.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):"")},w[T]=function(i,t,n){return"API Request Failed: Server responded with status ".concat(i," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},w[A]=function(i){return"Network Error: Failed to communicate with server".concat(i.url?" at ".concat(i.url):"").concat(i.error?" - ".concat(i.error):"")},w[C]=function(i){return"Failed to load chatbot interface".concat(i.src?" from ".concat(i.src):"").concat(i.error?". Error: ".concat(i.error):"")},w[S]=function(i){return"Invalid API Response: Missing required fields in response data: ".concat(i.join(", "))},w[_]=function(i){return"Error Tracking Service initialization failed".concat(i.apiKey?" for API key ".concat(i.apiKey):"").concat(i.error?". Error: ".concat(i.error):"")},w[E]=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)):"")},w.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.")},w.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):"")},w),O=function(){function i(i){var t=this;this.isInitialized=!1,this.hasRegistered=!1,this.handleMessage=function(i){var n,o,e,r,a,u,l,h,f,v,m,p,w,b,g,x=c().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(d.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:s.CHATBOT_LOADED,timestamp:Date.now()}),t.config.onInternalEvent(s.CHATBOT_LOADED)),"CHAT_INITIALIZED"===(null===(a=i.data)||void 0===a?void 0:a.type)&&(null===(l=(u=t.config).onEvent)||void 0===l||l.call(u,{type:s.CHAT_INITIALIZED,timestamp:Date.now()}),t.config.onInternalEvent(s.CHAT_INITIALIZED)),"CHAT_INITIALIZATION_FAILED"===(null===(h=i.data)||void 0===h?void 0:h.type)&&(null===(v=(f=t.config).onEvent)||void 0===v||v.call(f,{type:s.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}),t.config.onInternalEvent(s.CHAT_INITIALIZATION_FAILED,{error:null===(m=i.data)||void 0===m?void 0:m.error})),"SESSION_REFRESHED"===(null===(p=i.data)||void 0===p?void 0:p.type)&&(null===(b=(w=t.config).onEvent)||void 0===b||b.call(w,{type:s.SESSION_REFRESHED,timestamp:Date.now()}),t.config.onInternalEvent(s.SESSION_REFRESHED)),"CHAT_MOVED"===(null===(g=i.data)||void 0===g?void 0:g.type)&&t.config.onInternalEvent(d.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.render=function(){Object.assign(this.iframeElement.style,{position:"fixed",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",display:this.config.isVisible?"block":"none"}),this.applyResponsiveStyles(),document.body.appendChild(this.iframeElement)},i.prototype.applyResponsiveStyles=function(){this.iframeElement&&(560>window.innerWidth?Object.assign(this.iframeElement.style,{width:"100vw",minWidth:"300px",right:"0",bottom:"0",height:"100vh",flexDirection:"column",flexGrow:"1",borderRadius:"0",top:"0",maxHeight:"100%"}):Object.assign(this.iframeElement.style,{width:"26%",minWidth:"400px",right:"32px",bottom:"86px",height:"calc(100vh - 3rem - 10vh)",borderRadius:"1rem",top:"calc(10vh - 32px)",maxHeight:"45rem"}))},i.prototype.initialize=function(){var i=this;if(!this.isInitialized){var t=c().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(){I.trackError(Error(k[C]({src:i.iframeElement.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:C,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,a,d,u;if(this.config.isVisible=i,this.iframeElement.style.display=i?"block":"none",this.iframeElement.contentWindow&&i){var l=c().copilotUrl,h=new URL(this.iframeElement.src).origin||l;this.iframeElement.contentWindow.postMessage({domain:null===(t=null===window||void 0===window?void 0:window.location)||void 0===t?void 0:t.hostname,name:"openFrame"},h),this.hasRegistered||(this.iframeElement.contentWindow.postMessage({domain:null===(n=null===window||void 0===window?void 0:window.location)||void 0===n?void 0:n.hostname,action:"registerUserId",data:{userId:null===(o=this.config.config)||void 0===o?void 0:o.userId,token:null===(e=this.config.config)||void 0===e?void 0:e.token,userProfile:null===(r=this.config.config)||void 0===r?void 0:r.userProfile,isAnonymous:null===(a=this.config.config)||void 0===a?void 0:a.isAnonymous}},h),this.hasRegistered=!0),null===(u=(d=this.config).onEvent)||void 0===u||u.call(d,{type:s.CHATBOT_OPENED,timestamp:Date.now()}),this.config.onInternalEvent(s.CHATBOT_OPENED)}},i.prototype.update=function(i){var n=this.config.isVisible;if(this.config=t(t({},this.config),i),n!==this.config.isVisible&&this.updateVisibility(this.config.isVisible),this.iframeElement.contentWindow&&this.config.isVisible){var o=c().copilotUrl;this.iframeElement.contentWindow.postMessage({action:"updateUserProfile",user_profile:this.config.config.userProfile},o)}},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}(),R=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},M=function(i,t,e){return n(void 0,void 0,void 0,(function(){var n,a,s,d,u,l,h;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,5,,6]),n=c().apiUrl,r.log("endpointUrl",a="".concat(n,"/chat/chatbot/get/")),[4,fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_user_id:t||null,org_id:i,token:e||void 0,extra_info:{}})})];case 1:return(s=o.sent()).ok?[3,3]:[4,s.text()];case 2:throw d=o.sent(),Error(k[T](s.status,d));case 3:return[4,s.json()];case 4:if(u=o.sent(),!(null===(h=null==u?void 0:u.user)||void 0===h?void 0:h.org_info))throw Error(k[S](["user","org_info"]));return[2,u];case 5:throw l=o.sent(),I.trackError(l instanceof Error?l:Error(k[A]({error:l+""})),"fetchChatbotConfig",{errorCode:l instanceof Error&&l.message.includes("API Request Failed")?T:A,errorType:"API_ERROR",context:{apiKey:i,userId:t,timestamp:Date.now()}}),l;case 6:return[2]}}))}))},N=function(i){return n(void 0,void 0,void 0,(function(){var n,e,r,a,s,d,u,c,l,h,f,v,m,w;return o(this,(function(o){switch(o.label){case 0:return n=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),e=n.user_id||void 0,r=!1,e||(e=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)})),x=e,(I=new Date).setTime(I.getTime()+31536e6),document.cookie="".concat("rblyn_anon","=").concat(x,";expires=").concat(I.toUTCString(),";path=/"),r=!0),[4,M(n.api_key,e,n.user_token)];case 1:return a=o.sent(),s=p(),b=n.user_profile,g=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size","is_test_user"],d=b?Object.fromEntries(Object.entries(b).filter((function(i){var t=i[0];return g.includes(t)})).map((function(i){var t=i[0],n=i[1];return"boolean"==typeof n||"number"==typeof n?[t,n]:[t,n+""]}))):{},u=t(t({},s),d),[2,{chatbotId:n.api_key,userId:e,token:n.user_token,isAnonymous:r,domain:"",brand_colour:(null===(l=null===(c=a.user.org_info.brand_config)||void 0===c?void 0:c.colors)||void 0===l?void 0:l.brand_color)||"",image_url:(null===(f=null===(h=a.user.org_info)||void 0===h?void 0:h.brand_config)||void 0===f?void 0:f.launcher_logo_url)||"",userProfile:u,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(v=a.user.org_info.brand_config)||void 0===v?void 0:v.display_name)||"",welcome_message:(null===(m=a.user.org_info.brand_config)||void 0===m?void 0:m.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(w=a.user.org_info.brand_config)||void 0===w?void 0:w.redirect_url)||""}}]}var b,g,x,I}))}))},j=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 r.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="&times;",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:e(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=document.createElement("img");t.src=this.config.image_url||"".concat(this.config.domain,"/chatbubble.png"),t.alt="Chat",Object.assign(t.style,{zIndex:"1000",cursor:"pointer",borderRadius:"50%",objectFit:"cover"}),this.chatBtnImage=t,i.innerHTML="",i.appendChild(t)},i.prototype.createIframe=function(){var i=this;r.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),r.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 a=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"},a),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}},a)}})),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,a={cookies:R(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(a,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;r.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(r.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;r.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"),r.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}(),z=function(i){var e={isInitialized:!1,isInitializing:!1,error:null,chatbotConfig:null,isIframeVisible:!1},a=[],s=function(i){e=t(t({},e),i),a.forEach((function(i){return i(e)}))};return{getState:function(){return e},initialize:function(){return n(void 0,void 0,void 0,(function(){var t,n,e;return o(this,(function(o){switch(o.label){case 0:if(!i.api_key)return I.trackError(Error(k[y](i.api_key)),"ChatbotStateManager",{errorCode:y,errorType:D,context:{timestamp:Date.now()}}),[2];s({isInitializing:!0}),o.label=1;case 1:return o.trys.push([1,4,5,6]),[4,N(i)];case 2:return t=o.sent(),[4,new Promise((function(i,n){!function(n,o,e){if(n.chatbotId&&n.userId)try{new j(n),s({isInitialized:!0,chatbotConfig:t}),i(),r.log("Robylon SDK initialized successfully.")}catch(i){e(i instanceof Error?i.message:"Failed to initialize SDK")}else e("Incomplete configuration for SDK initialization.")}(t,0,(function(i){n(i)}))}))];case 3:return o.sent(),[3,6];case 4:return n=o.sent(),e=n instanceof Error?n.message:"Failed to initialize chatbot",s({error:e}),I.trackError(n instanceof Error?n:Error(e),"ChatbotStateManager",{errorCode:E,errorType:D,context:{timestamp:Date.now()}}),[3,6];case 5:return s({isInitializing:!1}),[7];case 6:return[2]}}))}))},toggleIframeVisibility:function(){s({isIframeVisible:!e.isIframeVisible})},closeIframe:function(){s({isIframeVisible:!1})},updateState:s,subscribe:function(i){return a.push(i),function(){var t=a.indexOf(i);t>-1&&a.splice(t,1)}}}},U=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){}}},F=function(){function i(i){var t=this;if(this.floatingButton=null,this.iframe=null,this.isDestroyed=!1,this.handleStateChange=function(i){if(!t.isDestroyed){var n=i.isInitialized,o=i.error,e=i.chatbotConfig,r=i.isIframeVisible;!o&&e&&n&&(t.eventEmitter=U({api_key:t.config.api_key,user_profile:t.config.user_profile,onEvent:t.config.onEvent,chatbotConfig:{isAnonymous:e.isAnonymous,userId:e.userId}}),t.floatingButton?t.floatingButton.update({config:e,isIframeVisible:r}):t.floatingButton=new h({config:e,toggleIframe:t.toggleIframe,isIframeVisible:r,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}),t.iframe?t.iframe.update({config:e,isVisible:r}):t.iframe=new O({config:e,isVisible:r,onClose:t.handleClose,onEvent:t.config.onEvent,onInternalEvent:t.eventEmitter.onInternalEvent}))}},this.toggleIframe=function(){var i=t.stateManager.getState();t.stateManager.toggleIframeVisibility(),t.eventEmitter.emit(i.isIframeVisible?s.CHATBOT_CLOSED:s.CHATBOT_BUTTON_CLICKED)},this.handleClose=function(){t.stateManager.closeIframe(),t.eventEmitter.emit(s.CHATBOT_CLOSED)},this.config=i,!i.api_key)throw I.trackError(Error(k[y](i.api_key)),"RobylonChatbot",{errorCode:y,errorType:D,context:{timestamp:Date.now()}}),Error("API key is required");try{I.initialize(i.api_key,i.user_id)}catch(i){I.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot",{errorCode:_,errorType:D,context:{timestamp:Date.now()}})}this.stateManager=z({api_key:i.api_key,user_id:i.user_id,user_token:i.user_token,user_profile:i.user_profile}),this.eventEmitter=U({api_key:i.api_key,user_profile:i.user_profile,onEvent:i.onEvent,chatbotConfig:null}),this.initialize()}return i.prototype.initialize=function(){return n(this,void 0,void 0,(function(){var i;return o(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(),I.trackError(i instanceof Error?i:Error(i+""),"RobylonChatbot.initialize",{errorCode:E,errorType:D,context:{timestamp:Date.now()}}),[3,3];case 3:return[2]}}))}))},i.prototype.show=function(){this.stateManager.getState().isIframeVisible||(this.stateManager.toggleIframeVisibility(),this.eventEmitter.emit(s.CHATBOT_BUTTON_CLICKED))},i.prototype.hide=function(){this.stateManager.getState().isIframeVisible&&(this.stateManager.closeIframe(),this.eventEmitter.emit(s.CHATBOT_CLOSED))},i.prototype.toggle=function(){this.toggleIframe()},i.prototype.destroy=function(){this.isDestroyed=!0,this.floatingButton&&(this.floatingButton.destroy(),this.floatingButton=null),this.iframe&&(this.iframe.destroy(),this.iframe=null)},i}();function L(i){var t=new F(i);return{show:function(){return t.show()},hide:function(){return t.hide()},toggle:function(){return t.toggle()},destroy:function(){return t.destroy()}}}var P={create:L};i.RobylonChatbot=P,i.create=L}));
2
2
  //# sourceMappingURL=robylon-chatbot.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robylon/web-react-sdk",
3
- "version": "1.1.34-staging.3",
3
+ "version": "1.1.34-staging.4",
4
4
  "description": "React SDK for Robylon AI Chatbot",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",