@robylon/web-react-sdk 1.1.15-staging.2 → 1.1.15-staging.3

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,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},n.apply(this,arguments)};function o(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((o=o.apply(e,t||[])).next())}))}function r(e,t){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}"function"==typeof SuppressedError&&SuppressedError;var i,a={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"},s=function(){return{copilotUrl:a.copilotUrl,environment:a.environment,apiUrl:a.apiUrl}},c=function(){var e;return(null===(e=navigator.userAgentData)||void 0===e?void 0:e.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},l=function(){var e,t,n;return(null===(n=null===(t=null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands)||void 0===t?void 0:t[0])||void 0===n?void 0:n.brand)||(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},d=function(){return{platform:"web",os:c(),browser:l(),sdk_version:"1.1.15-staging.1",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:{width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}};var e},u={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(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]}};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(i||(i={}));var p,f,h=function(){function e(){this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){var e=this;window.addEventListener("error",(function(t){e.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})})),window.addEventListener("unhandledrejection",(function(t){e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})}))},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:d(),event_type:i.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){u.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 o(this,void 0,void 0,(function(){var e,t,o;return r(this,(function(r){switch(r.label){case 0:if(!this.preInitQueue.length)return[2];u.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,r.label=1;case 1:return e<t.length?(o=t[e],[4,this.trackError(o.error,o.componentName,n(n({},o.additionalInfo),{preInitError:!0}))]):[3,4];case 2:r.sent(),r.label=3;case 3:return e++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},e.prototype.sendLog=function(e){return o(this,void 0,void 0,(function(){var t,n,o,i,a,c;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),t=s().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=r.sent()).ok?[3,3]:(i=(o=u).error,a=["Failed to send error log:"],[4,n.text()]);case 2:i.apply(o,a.concat([r.sent()])),r.label=3;case 3:return[3,5];case 4:return c=r.sent(),u.error("Error sending log:",c),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,a){return o(this,void 0,void 0,(function(){var o,s,c;return r(this,(function(r){switch(r.label){case 0:if(this.isInitialized)return[3,5];o={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({},a),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:d(),event_type:i.ERROR,user_id:this.userId},r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return r.sent(),[3,4];case 3:return r.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:a}),u.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({},a),{timestamp:Date.now()}),timestamp:Date.now()},c={org_id:this.apiKey||"UNINITALIZED",event_data:s,metadata:d(),event_type:i.ERROR,user_id:this.userId},[4,this.sendLog(c)];case 6:return r.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return o(this,void 0,void 0,(function(){var o,a;return r(this,(function(r){switch(r.label){case 0:return this.apiKey?(o={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},a={org_id:this.apiKey,event_data:o,metadata:d(),event_type:i.INFO,user_id:this.userId},[4,this.sendLog(a)]):(u.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),m=h.getInstance(),g="MISSING_API_KEY",v="INVALID_API_KEY",b="CONFIG_FETCH_FAILED",y="SDK_INIT_FAILED",I="ERROR_TRACKING_INIT_FAILED",E="API_REQUEST_FAILED",w="NETWORK_ERROR",x="INVALID_RESPONSE",_="IFRAME_LOAD_FAILED",C="COOKIE_ACCESS_ERROR",T="COMPONENT_RENDER_ERROR",A="INITIALIZATION_ERROR",k="API_ERROR",O="RUNTIME_ERROR",S="COMPONENT_ERROR",D=((p={})[g]=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.")},p[v]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},p[b]=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):"")},p[E]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},p[w]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},p[_]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},p[x]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},p[I]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},p[y]=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)):"")},p[C]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},p[T]=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):"")},p),R=function(e,t,n){return o(void 0,void 0,void 0,(function(){var o,i,a,c,l,d,u,p;return r(this,(function(r){switch(r.label){case 0:o=s().apiUrl,i="".concat(o,"/chat/chatbot/get/"),a={client_user_id:t,org_id:e,token:n||t,extra_info:{}},r.label=1;case 1:return r.trys.push([1,6,,7]),[4,fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})];case 2:return(c=r.sent()).ok?[3,4]:[4,c.text()];case 3:throw l=r.sent(),new Error(D[E](c.status,l));case 4:return[4,c.json()];case 5:if(d=r.sent(),!(null===(p=null==d?void 0:d.user)||void 0===p?void 0:p.org_info))throw new Error(D[x](["user","org_info"]));return[2,d];case 6:throw u=r.sent(),m.trackError(u instanceof Error?u:new Error(D[w]({error:String(u)})),"fetchChatbotConfig",{errorCode:u instanceof Error&&u.message.includes("API Request Failed")?E:w,errorType:k,context:{chatbotId:e,userId:t,apiUrl:o,statusCode:u instanceof Response?u.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),u;case 7:return[2]}}))}))},N=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],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},L=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,o){return t+t+n+n+o+o}));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),o=function(e,t,n){var o=[e,t,n].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*o[0]+.7152*o[1]+.0722*o[2]}(n.r,n.g,n.b);return o>t?"#0E0E0F":"#FFFFFF"},M=function(){function e(e){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=e,this.validateDomain()&&this.init(),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(){return this.config.domain===window.location.origin},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 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===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var o=t.createMessageBubble(e);n.appendChild(o)})),n.appendChild(o),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 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},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:L(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,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),document.body.appendChild(t),this.iframe=t;var n=function(){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(),window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o;if(e.iframe){var r=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},r),null===(o=t.contentWindow)||void 0===o||o.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:e.config.userId,token:e.config.token,userProfile:e.config.userProfile}},r)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,i={cookies:N(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(i,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=window.innerWidth;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(this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;null===(e=this.iframe.contentWindow)||void 0===e||e.postMessage({domain: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")}},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}(),j=function(e,t,n){if(e.chatbotId&&e.userId)try{new M(e);t(!0)}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")};!function(e){e.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",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"}(f||(f={}));var F=function(t){var n=t.config,o=t.toggleIframe,r=t.isIframeVisible,i=t.onEvent,a=e.useRef(null),c=s().copilotUrl;e.useEffect((function(){a.current&&requestAnimationFrame((function(){null==i||i({type:f.CHATBOT_BUTTON_LOADED,timestamp:Date.now()})}))}),[i]);return e.createElement("div",{ref:a,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:L(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:o},r?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(c,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))},U=function(t){var n=t.config,o=t.isVisible,r=t.onClose,i=t.onEvent,a=e.useRef(null),c=e.useRef(!1),l=e.useRef(!1),d=e.useCallback((function(){var e=a.current;e&&(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"))}),[]);return e.useEffect((function(){return window.addEventListener("resize",d),d(),function(){return window.removeEventListener("resize",d)}}),[d]),e.useEffect((function(){var e=a.current;if(e&&!c.current){var t=s().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(n.chatbotId),c.current=!0;var o=function(){var n,o=new URL(e.src).origin||t;null===(n=e.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},o)};return e.addEventListener("load",o),function(){return e.removeEventListener("load",o)}}}),[n.chatbotId]),e.useEffect((function(){var e,t=a.current;if(t&&c.current){var r=s().copilotUrl;if(t.style.display=o?"block":"none",t.contentWindow&&o){var i=new URL(t.src).origin||r;t.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},i),(null==l?void 0:l.current)||(null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:window.location.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}},i),l.current=!0)}}}),[o,n.userId,n.token,n.userProfile]),e.useEffect((function(){if(a.current&&c.current){var e=s().copilotUrl;o&&(null==i||i({type:f.CHATBOT_OPENED,timestamp:Date.now()}));var t=function(t){var n,o,a;if(t.origin===e){if("closeChatbot"===t.data)return void r();"CHATBOT_LOADED"===(null===(n=t.data)||void 0===n?void 0:n.type)&&(null==i||i({type:f.CHATBOT_LOADED,timestamp:Date.now()})),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==i||i({type:f.CHAT_INITIALIZED,timestamp:Date.now()})),"CHAT_INITIALIZATION_FAILED"===(null===(a=t.data)||void 0===a?void 0:a.type)&&(null==i||i({type:f.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}))}};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[r,i,n.chatbotId]),e.useEffect((function(){var e=a.current;if(e&&c.current){var t=function(){m.trackError(new Error(D[_]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:_,errorType:O,context:{config:n,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[n]),e.createElement("iframe",{ref:a,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:o?"block":"none"}})},z=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 o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}(n,e),n.getDerivedStateFromError=function(e){return{hasError:!0}},n.prototype.componentDidCatch=function(e,t){m.trackError(new Error(D[T]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:T,errorType:S,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},n.prototype.render=function(){return this.state.hasError?null:this.props.children},n}(e.Component);exports.Chatbot=function(t){var i=t.api_key,a=t.user_id,s=t.user_token,c=t.user_profile,l=t.onEvent,p=e.useState(!1),h=p[0],v=p[1],b=e.useState(!1),E=b[0],w=b[1],x=e.useState(null),_=x[0],C=x[1],T=e.useState(!1),k=T[0],O=T[1],S=e.useState(null),N=S[0],L=S[1],M=e.useState({});M[0];var P=M[1],B=e.useCallback((function(e,t){null==l||l({type:e,timestamp:Date.now(),data:t})}),[l]);e.useEffect((function(){if(i)try{m.initialize(i,a)}catch(e){m.trackError(e instanceof Error?e:new Error(D[I]({apiKey:i,error:String(e)})),"RobylonChatbot",{errorCode:I,errorType:A,context:{originalError:e,apiKey:i,userId:a,timestamp:Date.now()}})}else m.trackError(new Error(D[g](i)),"RobylonChatbot",{errorCode:g,errorType:A,context:{providedParams:{apiKey:i,hasApiKey:!1,hasUserId:!!a,userId:a,hasUserToken:!!s,userToken:s,hasUserProfile:!!c},timestamp:Date.now()}})}),[i,a,s,c]),e.useEffect((function(){var e={api_key:i,user_id:a,user_token:s,user_profile:c};if(!E){var t=!0;return i&&o(void 0,void 0,void 0,(function(){var o,l,p,f,h,b,I,E,x,_,T,k,O,S,N;return r(this,(function(r){switch(r.label){case 0:if(!i)return m.trackError(new Error(D[g](i)),"RobylonChatbot",{errorCode:g,errorType:A,context:{providedConfig:e,timestamp:Date.now()}}),[2];w(!0),r.label=1;case 1:return r.trys.push([1,3,4,5]),l=!1,(o=a||void 0)?l=!1:(o=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()}("rblyn_anon"),o||(M="rblyn_anon",F=o="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)})),U=365,(z=new Date).setTime(z.getTime()+24*U*60*60*1e3),document.cookie="".concat(M,"=").concat(F,";expires=").concat(z.toUTCString(),";path=/")),l=!0),[4,R(i,o,s)];case 2:return p=r.sent(),u.log("data initializeChatbot",p),f=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],h=d(),b=n(n({},h),c?Object.fromEntries(Object.entries(c).filter((function(e){var t=e[0];return f.includes(t)}))):{}),I={chatbotId:i,userId:o,token:s,isAnonymous:l,domain:"",brand_colour:(null===(_=null===(x=p.user.org_info.brand_config)||void 0===x?void 0:x.colors)||void 0===_?void 0:_.brand_color)||"",image_url:(null===(k=null===(T=p.user.org_info)||void 0===T?void 0:T.brand_config)||void 0===k?void 0:k.launcher_logo_url)||"",userProfile:b,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(O=p.user.org_info.brand_config)||void 0===O?void 0:O.display_name)||"",welcome_message:(null===(S=p.user.org_info.brand_config)||void 0===S?void 0:S.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(N=p.user.org_info.brand_config)||void 0===N?void 0:N.redirect_url)||""}},L(I),P(e),j(I,v,C),[3,5];case 3:return E=r.sent(),t?(m.trackError(E instanceof Error?E:new Error(D[y]({reason:E instanceof Error?E.message:String(E),config:e})),"RobylonChatbot",{errorCode:y,errorType:A,context:{initializationProps:e,originalError:E,timestamp:Date.now()}}),C(E instanceof Error?E.message:"Failed to initialize chatbot"),[3,5]):[2];case 4:return t&&w(!1),[7];case 5:return[2]}var M,F,U,z}))})),function(){t=!1}}}),[i,a,s,c]);return i?_?(u.error("Chatbot error:",_),null):N?e.createElement(z,{componentName:"RobylonChatbot"},h?e.createElement(e.Fragment,null,e.createElement(z,{componentName:"ChatbotFloatingButton"},e.createElement(F,{config:N,toggleIframe:function(){return O(!k)},isIframeVisible:k,onEvent:l})),e.createElement(z,{componentName:"ChatbotIframe"},e.createElement(U,{config:N,isVisible:k,onClose:function(){O(!1),B(f.CHATBOT_CLOSED)},onEvent:l}))):null):null:(u.error("Missing required configuration: api_key or user_id"),null)},exports.useChatbot=function(t){var o=e.useState({isLoading:!0,isInitialized:!1,error:null}),r=o[0],i=o[1],a=function(e){i((function(t){return n(n({},t),{isInitialized:e})}))},s=function(e){i((function(t){return n(n({},t),{error:e})}))};return e.useEffect((function(){!function(){try{j(t,a,s)}catch(e){i((function(t){return n(n({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[t.chatbotId,t.userId]),r};
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,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},n.apply(this,arguments)};function o(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((o=o.apply(e,t||[])).next())}))}function r(e,t){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}"function"==typeof SuppressedError&&SuppressedError;var i,a={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"},s=function(){return{copilotUrl:a.copilotUrl,environment:a.environment,apiUrl:a.apiUrl}},c=function(){var e;return(null===(e=navigator.userAgentData)||void 0===e?void 0:e.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0]},l=function(){var e,t,n;return(null===(n=null===(t=null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands)||void 0===t?void 0:t[0])||void 0===n?void 0:n.brand)||(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},d=function(){return{platform:"web",os:c(),browser:l(),sdk_version:"1.1.15-staging.2",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:{width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}};var e},u={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(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]}};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(i||(i={}));var p,f,h=function(){function e(){this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){var e=this;window.addEventListener("error",(function(t){e.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})})),window.addEventListener("unhandledrejection",(function(t){e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})}))},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:d(),event_type:i.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){u.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 o(this,void 0,void 0,(function(){var e,t,o;return r(this,(function(r){switch(r.label){case 0:if(!this.preInitQueue.length)return[2];u.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,r.label=1;case 1:return e<t.length?(o=t[e],[4,this.trackError(o.error,o.componentName,n(n({},o.additionalInfo),{preInitError:!0}))]):[3,4];case 2:r.sent(),r.label=3;case 3:return e++,[3,1];case 4:return this.preInitQueue=[],[2]}}))}))},e.prototype.sendLog=function(e){return o(this,void 0,void 0,(function(){var t,n,o,i,a,c;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,4,,5]),t=s().apiUrl,[4,fetch("".concat(t,"/users/sdk/record-logs/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:return(n=r.sent()).ok?[3,3]:(i=(o=u).error,a=["Failed to send error log:"],[4,n.text()]);case 2:i.apply(o,a.concat([r.sent()])),r.label=3;case 3:return[3,5];case 4:return c=r.sent(),u.error("Error sending log:",c),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,a){return o(this,void 0,void 0,(function(){var o,s,c;return r(this,(function(r){switch(r.label){case 0:if(this.isInitialized)return[3,5];o={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({},a),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:d(),event_type:i.ERROR,user_id:this.userId},r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return r.sent(),[3,4];case 3:return r.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:a}),u.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({},a),{timestamp:Date.now()}),timestamp:Date.now()},c={org_id:this.apiKey||"UNINITALIZED",event_data:s,metadata:d(),event_type:i.ERROR,user_id:this.userId},[4,this.sendLog(c)];case 6:return r.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return o(this,void 0,void 0,(function(){var o,a;return r(this,(function(r){switch(r.label){case 0:return this.apiKey?(o={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},a={org_id:this.apiKey,event_data:o,metadata:d(),event_type:i.INFO,user_id:this.userId},[4,this.sendLog(a)]):(u.error("Error tracking not initialized"),[2]);case 1:return r.sent(),[2]}}))}))},e}(),m=h.getInstance(),g="MISSING_API_KEY",v="INVALID_API_KEY",b="CONFIG_FETCH_FAILED",y="SDK_INIT_FAILED",I="ERROR_TRACKING_INIT_FAILED",E="API_REQUEST_FAILED",w="NETWORK_ERROR",x="INVALID_RESPONSE",_="IFRAME_LOAD_FAILED",C="COOKIE_ACCESS_ERROR",T="COMPONENT_RENDER_ERROR",A="INITIALIZATION_ERROR",k="API_ERROR",O="RUNTIME_ERROR",S="COMPONENT_ERROR",D=((p={})[g]=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.")},p[v]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},p[b]=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):"")},p[E]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},p[w]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},p[_]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},p[x]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},p[I]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},p[y]=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)):"")},p[C]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},p[T]=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):"")},p),R=function(e,t,n){return o(void 0,void 0,void 0,(function(){var o,i,a,c,l,d,u,p;return r(this,(function(r){switch(r.label){case 0:o=s().apiUrl,i="".concat(o,"/chat/chatbot/get/"),a={client_user_id:t,org_id:e,token:n||t,extra_info:{}},r.label=1;case 1:return r.trys.push([1,6,,7]),[4,fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})];case 2:return(c=r.sent()).ok?[3,4]:[4,c.text()];case 3:throw l=r.sent(),new Error(D[E](c.status,l));case 4:return[4,c.json()];case 5:if(d=r.sent(),!(null===(p=null==d?void 0:d.user)||void 0===p?void 0:p.org_info))throw new Error(D[x](["user","org_info"]));return[2,d];case 6:throw u=r.sent(),m.trackError(u instanceof Error?u:new Error(D[w]({error:String(u)})),"fetchChatbotConfig",{errorCode:u instanceof Error&&u.message.includes("API Request Failed")?E:w,errorType:k,context:{chatbotId:e,userId:t,apiUrl:o,statusCode:u instanceof Response?u.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),u;case 7:return[2]}}))}))},N=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],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},L=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,o){return t+t+n+n+o+o}));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),o=function(e,t,n){var o=[e,t,n].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*o[0]+.7152*o[1]+.0722*o[2]}(n.r,n.g,n.b);return o>t?"#0E0E0F":"#FFFFFF"},M=function(){function e(e){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=e,this.validateDomain()&&this.init(),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(){return this.config.domain===window.location.origin},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 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===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var o=t.createMessageBubble(e);n.appendChild(o)})),n.appendChild(o),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 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},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:L(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,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),document.body.appendChild(t),this.iframe=t;var n=function(){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(),window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o;if(e.iframe){var r=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},r),null===(o=t.contentWindow)||void 0===o||o.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:e.config.userId,token:e.config.token,userProfile:e.config.userProfile}},r)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,i={cookies:N(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(i,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=window.innerWidth;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(this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;null===(e=this.iframe.contentWindow)||void 0===e||e.postMessage({domain: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")}},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}(),j=function(e,t,n){if(e.chatbotId&&e.userId)try{new M(e);t(!0)}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")};!function(e){e.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",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"}(f||(f={}));var F=function(t){var n=t.config,o=t.toggleIframe,r=t.isIframeVisible,i=t.onEvent,a=e.useRef(null),c=s().copilotUrl;e.useEffect((function(){a.current&&requestAnimationFrame((function(){null==i||i({type:f.CHATBOT_BUTTON_LOADED,timestamp:Date.now()})}))}),[i]);return e.createElement("div",{ref:a,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:L(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:o},r?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(c,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))},U=function(t){var n=t.config,o=t.isVisible,r=t.onClose,i=t.onEvent,a=e.useRef(null),c=e.useRef(!1),l=e.useRef(!1),d=e.useCallback((function(){var e=a.current;e&&(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"))}),[]);return e.useEffect((function(){return window.addEventListener("resize",d),d(),function(){return window.removeEventListener("resize",d)}}),[d]),e.useEffect((function(){var e=a.current;if(e&&!c.current){var t=s().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(n.chatbotId),c.current=!0;var o=function(){var n,o=new URL(e.src).origin||t;null===(n=e.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},o)};return e.addEventListener("load",o),function(){return e.removeEventListener("load",o)}}}),[n.chatbotId]),e.useEffect((function(){var e,t=a.current;if(t&&c.current){var r=s().copilotUrl;if(t.style.display=o?"block":"none",t.contentWindow&&o){var i=new URL(t.src).origin||r;t.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},i),(null==l?void 0:l.current)||(null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:window.location.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}},i),l.current=!0)}}}),[o,n.userId,n.token,n.userProfile]),e.useEffect((function(){if(a.current&&c.current){var e=s().copilotUrl;o&&(null==i||i({type:f.CHATBOT_OPENED,timestamp:Date.now()}));var t=function(t){var n,o,a;if(t.origin===e){if("closeChatbot"===t.data)return void r();"CHATBOT_LOADED"===(null===(n=t.data)||void 0===n?void 0:n.type)&&(null==i||i({type:f.CHATBOT_LOADED,timestamp:Date.now()})),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==i||i({type:f.CHAT_INITIALIZED,timestamp:Date.now()})),"CHAT_INITIALIZATION_FAILED"===(null===(a=t.data)||void 0===a?void 0:a.type)&&(null==i||i({type:f.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}))}};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[r,i,n.chatbotId]),e.useEffect((function(){var e=a.current;if(e&&c.current){var t=function(){m.trackError(new Error(D[_]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:_,errorType:O,context:{config:n,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[n]),e.createElement("iframe",{ref:a,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:o?"block":"none"}})},z=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 o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}(n,e),n.getDerivedStateFromError=function(e){return{hasError:!0}},n.prototype.componentDidCatch=function(e,t){m.trackError(new Error(D[T]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:T,errorType:S,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},n.prototype.render=function(){return this.state.hasError?null:this.props.children},n}(e.Component);exports.Chatbot=function(t){var i=t.api_key,a=t.user_id,s=t.user_token,c=t.user_profile,l=t.onEvent,p=e.useState(!1),h=p[0],v=p[1],b=e.useState(!1),E=b[0],w=b[1],x=e.useState(null),_=x[0],C=x[1],T=e.useState(!1),k=T[0],O=T[1],S=e.useState(null),N=S[0],L=S[1],M=e.useState({});M[0];var P=M[1],B=e.useCallback((function(e,t){null==l||l({type:e,timestamp:Date.now(),data:t})}),[l]);e.useEffect((function(){if(i)try{m.initialize(i,a)}catch(e){m.trackError(e instanceof Error?e:new Error(D[I]({apiKey:i,error:String(e)})),"RobylonChatbot",{errorCode:I,errorType:A,context:{originalError:e,apiKey:i,userId:a,timestamp:Date.now()}})}else m.trackError(new Error(D[g](i)),"RobylonChatbot",{errorCode:g,errorType:A,context:{providedParams:{apiKey:i,hasApiKey:!1,hasUserId:!!a,userId:a,hasUserToken:!!s,userToken:s,hasUserProfile:!!c},timestamp:Date.now()}})}),[i,a,s,c]),e.useEffect((function(){var e={api_key:i,user_id:a,user_token:s,user_profile:c};if(!E){var t=!0;return i&&o(void 0,void 0,void 0,(function(){var o,l,p,f,h,b,I,E,x,_,T,k,O,S,N;return r(this,(function(r){switch(r.label){case 0:if(!i)return m.trackError(new Error(D[g](i)),"RobylonChatbot",{errorCode:g,errorType:A,context:{providedConfig:e,timestamp:Date.now()}}),[2];w(!0),r.label=1;case 1:return r.trys.push([1,3,4,5]),l=!1,(o=a||void 0)?l=!1:(o=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()}("rblyn_anon"),o||(M="rblyn_anon",F=o="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)})),U=365,(z=new Date).setTime(z.getTime()+24*U*60*60*1e3),document.cookie="".concat(M,"=").concat(F,";expires=").concat(z.toUTCString(),";path=/")),l=!0),[4,R(i,o,s)];case 2:return p=r.sent(),u.log("data initializeChatbot",p),f=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],h=d(),b=n(n({},h),c?Object.fromEntries(Object.entries(c).filter((function(e){var t=e[0];return f.includes(t)}))):{}),I={chatbotId:i,userId:o,token:s,isAnonymous:l,domain:"",brand_colour:(null===(_=null===(x=p.user.org_info.brand_config)||void 0===x?void 0:x.colors)||void 0===_?void 0:_.brand_color)||"",image_url:(null===(k=null===(T=p.user.org_info)||void 0===T?void 0:T.brand_config)||void 0===k?void 0:k.launcher_logo_url)||"",userProfile:b,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(O=p.user.org_info.brand_config)||void 0===O?void 0:O.display_name)||"",welcome_message:(null===(S=p.user.org_info.brand_config)||void 0===S?void 0:S.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(N=p.user.org_info.brand_config)||void 0===N?void 0:N.redirect_url)||""}},L(I),P(e),j(I,v,C),[3,5];case 3:return E=r.sent(),t?(m.trackError(E instanceof Error?E:new Error(D[y]({reason:E instanceof Error?E.message:String(E),config:e})),"RobylonChatbot",{errorCode:y,errorType:A,context:{initializationProps:e,originalError:E,timestamp:Date.now()}}),C(E instanceof Error?E.message:"Failed to initialize chatbot"),[3,5]):[2];case 4:return t&&w(!1),[7];case 5:return[2]}var M,F,U,z}))})),function(){t=!1}}}),[i,a,s,c]);return i?_?(u.error("Chatbot error:",_),null):N?e.createElement(z,{componentName:"RobylonChatbot"},h?e.createElement(e.Fragment,null,e.createElement(z,{componentName:"ChatbotFloatingButton"},e.createElement(F,{config:N,toggleIframe:function(){return O(!k)},isIframeVisible:k,onEvent:l})),e.createElement(z,{componentName:"ChatbotIframe"},e.createElement(U,{config:N,isVisible:k,onClose:function(){O(!1),B(f.CHATBOT_CLOSED)},onEvent:l}))):null):null:(u.error("Missing required configuration: api_key or user_id"),null)},exports.useChatbot=function(t){var o=e.useState({isLoading:!0,isInitialized:!1,error:null}),r=o[0],i=o[1],a=function(e){i((function(t){return n(n({},t),{isInitialized:e})}))},s=function(e){i((function(t){return n(n({},t),{error:e})}))};return e.useEffect((function(){!function(){try{j(t,a,s)}catch(e){i((function(t){return n(n({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[t.chatbotId,t.userId]),r};
2
2
  //# sourceMappingURL=index.js.map
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import e,{useRef as t,useEffect as n,useCallback as o,Component as r,useState as i}from"react";var a=function(e,t){return a=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])},a(e,t)};var s=function(){return s=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},s.apply(this,arguments)};function c(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((o=o.apply(e,t||[])).next())}))}function l(e,t){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}"function"==typeof SuppressedError&&SuppressedError;var d,u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"},p=function(){return{copilotUrl:u.copilotUrl,environment:u.environment,apiUrl:u.apiUrl}},f=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,t,n;return(null===(n=null===(t=null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands)||void 0===t?void 0:t[0])||void 0===n?void 0:n.brand)||(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},m=function(){return{platform:"web",os:f(),browser:h(),sdk_version:"1.1.15-staging.1",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:{width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}};var e},g={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(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]}};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(d||(d={}));var v,b,y=function(){function e(){this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){var e=this;window.addEventListener("error",(function(t){e.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})})),window.addEventListener("unhandledrejection",(function(t){e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})}))},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:m(),event_type:d.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){g.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 c(this,void 0,void 0,(function(){var e,t,n;return l(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];g.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,o.label=1;case 1:return e<t.length?(n=t[e],[4,this.trackError(n.error,n.componentName,s(s({},n.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 c(this,void 0,void 0,(function(){var t,n,o,r,i,a;return l(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=p().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]:(r=(o=g).error,i=["Failed to send error log:"],[4,n.text()]);case 2:r.apply(o,i.concat([s.sent()])),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),g.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return c(this,void 0,void 0,(function(){var o,r,i;return l(this,(function(a){switch(a.label){case 0:if(this.isInitialized)return[3,5];o={org_id:"UNINITALIZED",event_data:{message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:s(s({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:m(),event_type:d.ERROR,user_id:this.userId},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return a.sent(),[3,4];case 3:return a.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),g.warn("Error tracked before initialization, queuing:",e),[3,4];case 4:return[2];case 5:return r={message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:s(s({},n),{timestamp:Date.now()}),timestamp:Date.now()},i={org_id:this.apiKey||"UNINITALIZED",event_data:r,metadata:m(),event_type:d.ERROR,user_id:this.userId},[4,this.sendLog(i)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return c(this,void 0,void 0,(function(){var o,r;return l(this,(function(i){switch(i.label){case 0:return this.apiKey?(o={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},r={org_id:this.apiKey,event_data:o,metadata:m(),event_type:d.INFO,user_id:this.userId},[4,this.sendLog(r)]):(g.error("Error tracking not initialized"),[2]);case 1:return i.sent(),[2]}}))}))},e}(),I=y.getInstance(),E="MISSING_API_KEY",w="INVALID_API_KEY",x="CONFIG_FETCH_FAILED",_="SDK_INIT_FAILED",C="ERROR_TRACKING_INIT_FAILED",T="API_REQUEST_FAILED",A="NETWORK_ERROR",k="INVALID_RESPONSE",O="IFRAME_LOAD_FAILED",D="COOKIE_ACCESS_ERROR",S="COMPONENT_RENDER_ERROR",R="INITIALIZATION_ERROR",N="API_ERROR",L="RUNTIME_ERROR",M="COMPONENT_ERROR",j=((v={})[E]=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.")},v[w]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},v[x]=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):"")},v[T]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},v[A]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},v[O]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},v[k]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},v[C]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},v[_]=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)):"")},v[D]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},v[S]=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):"")},v),F=function(e,t,n){return c(void 0,void 0,void 0,(function(){var o,r,i,a,s,c,d,u;return l(this,(function(l){switch(l.label){case 0:o=p().apiUrl,r="".concat(o,"/chat/chatbot/get/"),i={client_user_id:t,org_id:e,token:n||t,extra_info:{}},l.label=1;case 1:return l.trys.push([1,6,,7]),[4,fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 2:return(a=l.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=l.sent(),new Error(j[T](a.status,s));case 4:return[4,a.json()];case 5:if(c=l.sent(),!(null===(u=null==c?void 0:c.user)||void 0===u?void 0:u.org_info))throw new Error(j[k](["user","org_info"]));return[2,c];case 6:throw d=l.sent(),I.trackError(d instanceof Error?d:new Error(j[A]({error:String(d)})),"fetchChatbotConfig",{errorCode:d instanceof Error&&d.message.includes("API Request Failed")?T:A,errorType:N,context:{chatbotId:e,userId:t,apiUrl:o,statusCode:d instanceof Response?d.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),d;case 7:return[2]}}))}))},U=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],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},z=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,o){return t+t+n+n+o+o}));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),o=function(e,t,n){var o=[e,t,n].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*o[0]+.7152*o[1]+.0722*o[2]}(n.r,n.g,n.b);return o>t?"#0E0E0F":"#FFFFFF"},P=function(){function e(e){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=e,this.validateDomain()&&this.init(),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(){return this.config.domain===window.location.origin},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 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===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var o=t.createMessageBubble(e);n.appendChild(o)})),n.appendChild(o),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 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},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:z(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,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),document.body.appendChild(t),this.iframe=t;var n=function(){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(),window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o;if(e.iframe){var r=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},r),null===(o=t.contentWindow)||void 0===o||o.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:e.config.userId,token:e.config.token,userProfile:e.config.userProfile}},r)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,i={cookies:U(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(i,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=window.innerWidth;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(this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;null===(e=this.iframe.contentWindow)||void 0===e||e.postMessage({domain: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")}},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}(),B=function(e,t,n){if(e.chatbotId&&e.userId)try{new P(e);t(!0)}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")};!function(e){e.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",e.CHATBOT_OPENED="CHATBOT_OPENED",e.CHATBOT_CLOSED="CHATBOT_CLOSED",e.CHATBOT_APP_READY="CHATBOT_APP_READY",e.CHATBOT_LOADED="CHATBOT_LOADED",e.CHAT_INITIALIZED="CHAT_INITIALIZED",e.SESSION_REFRESHED="SESSION_REFRESHED",e.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED"}(b||(b={}));var H=function(o){var r=o.config,i=o.toggleIframe,a=o.isIframeVisible,s=o.onEvent,c=t(null),l=p().copilotUrl;n((function(){c.current&&requestAnimationFrame((function(){null==s||s({type:b.CHATBOT_BUTTON_LOADED,timestamp:Date.now()})}))}),[s]);return 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:r.brand_colour,color:z(r.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:i},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:r.image_url||"".concat(l,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))},W=function(r){var i=r.config,a=r.isVisible,s=r.onClose,c=r.onEvent,l=t(null),d=t(!1),u=t(!1),f=o((function(){var e=l.current;e&&(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"))}),[]);return n((function(){return window.addEventListener("resize",f),f(),function(){return window.removeEventListener("resize",f)}}),[f]),n((function(){var e=l.current;if(e&&!d.current){var t=p().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(i.chatbotId),d.current=!0;var n=function(){var n,o=new URL(e.src).origin||t;null===(n=e.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},o)};return e.addEventListener("load",n),function(){return e.removeEventListener("load",n)}}}),[i.chatbotId]),n((function(){var e,t=l.current;if(t&&d.current){var n=p().copilotUrl;if(t.style.display=a?"block":"none",t.contentWindow&&a){var o=new URL(t.src).origin||n;t.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},o),(null==u?void 0:u.current)||(null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:null==i?void 0:i.userId,token:null==i?void 0:i.token,userProfile:null==i?void 0:i.userProfile,isAnonymous:null==i?void 0:i.isAnonymous}},o),u.current=!0)}}}),[a,i.userId,i.token,i.userProfile]),n((function(){if(l.current&&d.current){var e=p().copilotUrl;a&&(null==c||c({type:b.CHATBOT_OPENED,timestamp:Date.now()}));var t=function(t){var n,o,r;if(t.origin===e){if("closeChatbot"===t.data)return void s();"CHATBOT_LOADED"===(null===(n=t.data)||void 0===n?void 0:n.type)&&(null==c||c({type:b.CHATBOT_LOADED,timestamp:Date.now()})),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==c||c({type:b.CHAT_INITIALIZED,timestamp:Date.now()})),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==c||c({type:b.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}))}};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[s,c,i.chatbotId]),n((function(){var e=l.current;if(e&&d.current){var t=function(){I.trackError(new Error(j[O]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:O,errorType:L,context:{config:i,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[i]),e.createElement("iframe",{ref:l,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"}})},K=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}a(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){I.trackError(new Error(j[S]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:S,errorType:M,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(r),J=function(t){var r=t.api_key,a=t.user_id,d=t.user_token,u=t.user_profile,p=t.onEvent,f=i(!1),h=f[0],v=f[1],y=i(!1),w=y[0],x=y[1],T=i(null),A=T[0],k=T[1],O=i(!1),D=O[0],S=O[1],N=i(null),L=N[0],M=N[1],U=i({});U[0];var z=U[1],P=o((function(e,t){null==p||p({type:e,timestamp:Date.now(),data:t})}),[p]);n((function(){if(r)try{I.initialize(r,a)}catch(e){I.trackError(e instanceof Error?e:new Error(j[C]({apiKey:r,error:String(e)})),"RobylonChatbot",{errorCode:C,errorType:R,context:{originalError:e,apiKey:r,userId:a,timestamp:Date.now()}})}else I.trackError(new Error(j[E](r)),"RobylonChatbot",{errorCode:E,errorType:R,context:{providedParams:{apiKey:r,hasApiKey:!1,hasUserId:!!a,userId:a,hasUserToken:!!d,userToken:d,hasUserProfile:!!u},timestamp:Date.now()}})}),[r,a,d,u]),n((function(){var e={api_key:r,user_id:a,user_token:d,user_profile:u};if(!w){var t=!0;return r&&c(void 0,void 0,void 0,(function(){var n,o,i,c,p,f,h,b,y,w,C,T,A,O,D;return l(this,(function(l){switch(l.label){case 0:if(!r)return I.trackError(new Error(j[E](r)),"RobylonChatbot",{errorCode:E,errorType:R,context:{providedConfig:e,timestamp:Date.now()}}),[2];x(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),o=!1,(n=a||void 0)?o=!1:(n=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()}("rblyn_anon"),n||(S="rblyn_anon",N=n="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)})),L=365,(U=new Date).setTime(U.getTime()+24*L*60*60*1e3),document.cookie="".concat(S,"=").concat(N,";expires=").concat(U.toUTCString(),";path=/")),o=!0),[4,F(r,n,d)];case 2:return i=l.sent(),g.log("data initializeChatbot",i),c=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],p=m(),f=s(s({},p),u?Object.fromEntries(Object.entries(u).filter((function(e){var t=e[0];return c.includes(t)}))):{}),h={chatbotId:r,userId:n,token:d,isAnonymous:o,domain:"",brand_colour:(null===(w=null===(y=i.user.org_info.brand_config)||void 0===y?void 0:y.colors)||void 0===w?void 0:w.brand_color)||"",image_url:(null===(T=null===(C=i.user.org_info)||void 0===C?void 0:C.brand_config)||void 0===T?void 0:T.launcher_logo_url)||"",userProfile:f,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(A=i.user.org_info.brand_config)||void 0===A?void 0:A.display_name)||"",welcome_message:(null===(O=i.user.org_info.brand_config)||void 0===O?void 0:O.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(D=i.user.org_info.brand_config)||void 0===D?void 0:D.redirect_url)||""}},M(h),z(e),B(h,v,k),[3,5];case 3:return b=l.sent(),t?(I.trackError(b instanceof Error?b:new Error(j[_]({reason:b instanceof Error?b.message:String(b),config:e})),"RobylonChatbot",{errorCode:_,errorType:R,context:{initializationProps:e,originalError:b,timestamp:Date.now()}}),k(b instanceof Error?b.message:"Failed to initialize chatbot"),[3,5]):[2];case 4:return t&&x(!1),[7];case 5:return[2]}var S,N,L,U}))})),function(){t=!1}}}),[r,a,d,u]);return r?A?(g.error("Chatbot error:",A),null):L?e.createElement(K,{componentName:"RobylonChatbot"},h?e.createElement(e.Fragment,null,e.createElement(K,{componentName:"ChatbotFloatingButton"},e.createElement(H,{config:L,toggleIframe:function(){return S(!D)},isIframeVisible:D,onEvent:p})),e.createElement(K,{componentName:"ChatbotIframe"},e.createElement(W,{config:L,isVisible:D,onClose:function(){S(!1),P(b.CHATBOT_CLOSED)},onEvent:p}))):null):null:(g.error("Missing required configuration: api_key or user_id"),null)},Z=function(e){var t=i({isLoading:!0,isInitialized:!1,error:null}),o=t[0],r=t[1],a=function(e){r((function(t){return s(s({},t),{isInitialized:e})}))},c=function(e){r((function(t){return s(s({},t),{error:e})}))};return n((function(){!function(){try{B(e,a,c)}catch(e){r((function(t){return s(s({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),o};export{J as Chatbot,Z as useChatbot};
1
+ import e,{useRef as t,useEffect as n,useCallback as o,Component as r,useState as i}from"react";var a=function(e,t){return a=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])},a(e,t)};var s=function(){return s=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},s.apply(this,arguments)};function c(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((o=o.apply(e,t||[])).next())}))}function l(e,t){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&s[0]?o.return:s[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,s[1])).done)return r;switch(o=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){i.label=s[1];break}if(6===s[0]&&i.label<r[1]){i.label=r[1],r=s;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(s);break}r[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}"function"==typeof SuppressedError&&SuppressedError;var d,u={copilotUrl:"https://staging.d2s3wsqyyond1h.amplifyapp.com",environment:"staging",apiUrl:"https://stage-api.robylon.ai"},p=function(){return{copilotUrl:u.copilotUrl,environment:u.environment,apiUrl:u.apiUrl}},f=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,t,n;return(null===(n=null===(t=null===(e=navigator.userAgentData)||void 0===e?void 0:e.brands)||void 0===t?void 0:t[0])||void 0===n?void 0:n.brand)||(/Chrome|Firefox|Safari|Edge|Opera/.exec(navigator.userAgent)||["Unknown"])[0]},m=function(){return{platform:"web",os:f(),browser:h(),sdk_version:"1.1.15-staging.2",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:{width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}};var e},g={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(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t]}};!function(e){e.ERROR="ERROR",e.INFO="INFO"}(d||(d={}));var v,b,y=function(){function e(){this.apiKey="",this.userId=null,this.preInitQueue=[],this.isInitialized=!1,this.setupGlobalHandlers()}return e.prototype.setupGlobalHandlers=function(){var e=this;window.addEventListener("error",(function(t){e.trackError(t.error||t.message,"GlobalErrorHandler",{filename:t.filename,lineNo:t.lineno,colNo:t.colno})})),window.addEventListener("unhandledrejection",(function(t){e.trackError(t.reason||"Unhandled Promise Rejection","GlobalPromiseHandler",{reason:t.reason})}))},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:m(),event_type:d.ERROR,user_id:t};this.sendLog(n).catch(console.error)}this.apiKey=e,this.userId=t,this.isInitialized=!0,this.processPreInitQueue()}catch(n){g.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 c(this,void 0,void 0,(function(){var e,t,n;return l(this,(function(o){switch(o.label){case 0:if(!this.preInitQueue.length)return[2];g.info("Processing ".concat(this.preInitQueue.length," pre-initialization errors")),e=0,t=this.preInitQueue,o.label=1;case 1:return e<t.length?(n=t[e],[4,this.trackError(n.error,n.componentName,s(s({},n.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 c(this,void 0,void 0,(function(){var t,n,o,r,i,a;return l(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),t=p().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]:(r=(o=g).error,i=["Failed to send error log:"],[4,n.text()]);case 2:r.apply(o,i.concat([s.sent()])),s.label=3;case 3:return[3,5];case 4:return a=s.sent(),g.error("Error sending log:",a),[3,5];case 5:return[2]}}))}))},e.prototype.trackError=function(e,t,n){return c(this,void 0,void 0,(function(){var o,r,i;return l(this,(function(a){switch(a.label){case 0:if(this.isInitialized)return[3,5];o={org_id:"UNINITALIZED",event_data:{message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:s(s({},n),{preInitError:!0,timestamp:Date.now()}),timestamp:Date.now()},metadata:m(),event_type:d.ERROR,user_id:this.userId},a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.sendLog(o)];case 2:return a.sent(),[3,4];case 3:return a.sent(),this.preInitQueue.push({error:e,componentName:t,additionalInfo:n}),g.warn("Error tracked before initialization, queuing:",e),[3,4];case 4:return[2];case 5:return r={message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,componentName:t,additionalInfo:s(s({},n),{timestamp:Date.now()}),timestamp:Date.now()},i={org_id:this.apiKey||"UNINITALIZED",event_data:r,metadata:m(),event_type:d.ERROR,user_id:this.userId},[4,this.sendLog(i)];case 6:return a.sent(),[2]}}))}))},e.prototype.trackInfo=function(e,t,n){return c(this,void 0,void 0,(function(){var o,r;return l(this,(function(i){switch(i.label){case 0:return this.apiKey?(o={message:e,componentName:t,additionalInfo:n,timestamp:Date.now()},r={org_id:this.apiKey,event_data:o,metadata:m(),event_type:d.INFO,user_id:this.userId},[4,this.sendLog(r)]):(g.error("Error tracking not initialized"),[2]);case 1:return i.sent(),[2]}}))}))},e}(),I=y.getInstance(),E="MISSING_API_KEY",w="INVALID_API_KEY",x="CONFIG_FETCH_FAILED",_="SDK_INIT_FAILED",C="ERROR_TRACKING_INIT_FAILED",T="API_REQUEST_FAILED",A="NETWORK_ERROR",k="INVALID_RESPONSE",O="IFRAME_LOAD_FAILED",D="COOKIE_ACCESS_ERROR",S="COMPONENT_RENDER_ERROR",R="INITIALIZATION_ERROR",N="API_ERROR",L="RUNTIME_ERROR",M="COMPONENT_ERROR",j=((v={})[E]=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.")},v[w]=function(e){return"SDK Initialization Failed: Provided API key '".concat(e,"' is invalid. API key must be a non-empty string in UUID format.")},v[x]=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):"")},v[T]=function(e,t,n){return"API Request Failed: Server responded with status ".concat(e," for ").concat(n?"endpoint ".concat(n):"request"," - ").concat(t)},v[A]=function(e){return"Network Error: Failed to communicate with server".concat(e.url?" at ".concat(e.url):"").concat(e.error?" - ".concat(e.error):"")},v[O]=function(e){return"Failed to load chatbot interface".concat(e.src?" from ".concat(e.src):"").concat(e.error?". Error: ".concat(e.error):"")},v[k]=function(e){return"Invalid API Response: Missing required fields in response data: ".concat(e.join(", "))},v[C]=function(e){return"Error Tracking Service initialization failed".concat(e.apiKey?" for API key ".concat(e.apiKey):"").concat(e.error?". Error: ".concat(e.error):"")},v[_]=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)):"")},v[D]=function(e,t){return"Cookie Access Error: Failed to ".concat(e).concat(t?" cookie '".concat(t,"'"):" cookies",". This may affect user session persistence.")},v[S]=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):"")},v),F=function(e,t,n){return c(void 0,void 0,void 0,(function(){var o,r,i,a,s,c,d,u;return l(this,(function(l){switch(l.label){case 0:o=p().apiUrl,r="".concat(o,"/chat/chatbot/get/"),i={client_user_id:t,org_id:e,token:n||t,extra_info:{}},l.label=1;case 1:return l.trys.push([1,6,,7]),[4,fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})];case 2:return(a=l.sent()).ok?[3,4]:[4,a.text()];case 3:throw s=l.sent(),new Error(j[T](a.status,s));case 4:return[4,a.json()];case 5:if(c=l.sent(),!(null===(u=null==c?void 0:c.user)||void 0===u?void 0:u.org_info))throw new Error(j[k](["user","org_info"]));return[2,c];case 6:throw d=l.sent(),I.trackError(d instanceof Error?d:new Error(j[A]({error:String(d)})),"fetchChatbotConfig",{errorCode:d instanceof Error&&d.message.includes("API Request Failed")?T:A,errorType:N,context:{chatbotId:e,userId:t,apiUrl:o,statusCode:d instanceof Response?d.status:void 0,timestamp:Date.now(),requestPayload:{client_user_id:t,org_id:e}}}),d;case 7:return[2]}}))}))},U=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],o=t.slice(1).join("=").trim();return{name:n=n.trim(),value:o?decodeURIComponent(o):""}})),t},z=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,o){return t+t+n+n+o+o}));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),o=function(e,t,n){var o=[e,t,n].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*o[0]+.7152*o[1]+.0722*o[2]}(n.r,n.g,n.b);return o>t?"#0E0E0F":"#FFFFFF"},P=function(){function e(e){this.logoContainer=null,this.iframe=null,this.bubblePromptContainer=null,this.chatBtnImage=null,this.config=e,this.validateDomain()&&this.init(),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(){return this.config.domain===window.location.origin},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 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===(e=this.config.chat_interface_config)||void 0===e?void 0:e.chat_bubble_prompts)||[]).forEach((function(e){var o=t.createMessageBubble(e);n.appendChild(o)})),n.appendChild(o),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 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},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:z(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,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),document.body.appendChild(t),this.iframe=t;var n=function(){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(),window.addEventListener("resize",n),t.addEventListener("load",(function(){var n,o;if(e.iframe){var r=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},r),null===(o=t.contentWindow)||void 0===o||o.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:e.config.userId,token:e.config.token,userProfile:e.config.userProfile}},r)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var r="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,i={cookies:U(r),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(i,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=window.innerWidth;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(this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;null===(e=this.iframe.contentWindow)||void 0===e||e.postMessage({domain: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")}},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}(),B=function(e,t,n){if(e.chatbotId&&e.userId)try{new P(e);t(!0)}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")};!function(e){e.CHATBOT_BUTTON_LOADED="CHATBOT_BUTTON_LOADED",e.CHATBOT_OPENED="CHATBOT_OPENED",e.CHATBOT_CLOSED="CHATBOT_CLOSED",e.CHATBOT_APP_READY="CHATBOT_APP_READY",e.CHATBOT_LOADED="CHATBOT_LOADED",e.CHAT_INITIALIZED="CHAT_INITIALIZED",e.SESSION_REFRESHED="SESSION_REFRESHED",e.CHAT_INITIALIZATION_FAILED="CHAT_INITIALIZATION_FAILED"}(b||(b={}));var H=function(o){var r=o.config,i=o.toggleIframe,a=o.isIframeVisible,s=o.onEvent,c=t(null),l=p().copilotUrl;n((function(){c.current&&requestAnimationFrame((function(){null==s||s({type:b.CHATBOT_BUTTON_LOADED,timestamp:Date.now()})}))}),[s]);return 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:r.brand_colour,color:z(r.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:i},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:r.image_url||"".concat(l,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))},W=function(r){var i=r.config,a=r.isVisible,s=r.onClose,c=r.onEvent,l=t(null),d=t(!1),u=t(!1),f=o((function(){var e=l.current;e&&(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"))}),[]);return n((function(){return window.addEventListener("resize",f),f(),function(){return window.removeEventListener("resize",f)}}),[f]),n((function(){var e=l.current;if(e&&!d.current){var t=p().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(i.chatbotId),d.current=!0;var n=function(){var n,o=new URL(e.src).origin||t;null===(n=e.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},o)};return e.addEventListener("load",n),function(){return e.removeEventListener("load",n)}}}),[i.chatbotId]),n((function(){var e,t=l.current;if(t&&d.current){var n=p().copilotUrl;if(t.style.display=a?"block":"none",t.contentWindow&&a){var o=new URL(t.src).origin||n;t.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},o),(null==u?void 0:u.current)||(null===(e=t.contentWindow)||void 0===e||e.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:null==i?void 0:i.userId,token:null==i?void 0:i.token,userProfile:null==i?void 0:i.userProfile,isAnonymous:null==i?void 0:i.isAnonymous}},o),u.current=!0)}}}),[a,i.userId,i.token,i.userProfile]),n((function(){if(l.current&&d.current){var e=p().copilotUrl;a&&(null==c||c({type:b.CHATBOT_OPENED,timestamp:Date.now()}));var t=function(t){var n,o,r;if(t.origin===e){if("closeChatbot"===t.data)return void s();"CHATBOT_LOADED"===(null===(n=t.data)||void 0===n?void 0:n.type)&&(null==c||c({type:b.CHATBOT_LOADED,timestamp:Date.now()})),"CHAT_INITIALIZED"===(null===(o=t.data)||void 0===o?void 0:o.type)&&(null==c||c({type:b.CHAT_INITIALIZED,timestamp:Date.now()})),"CHAT_INITIALIZATION_FAILED"===(null===(r=t.data)||void 0===r?void 0:r.type)&&(null==c||c({type:b.CHAT_INITIALIZATION_FAILED,timestamp:Date.now()}))}};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[s,c,i.chatbotId]),n((function(){var e=l.current;if(e&&d.current){var t=function(){I.trackError(new Error(j[O]({src:e.src,error:"Failed to load iframe"})),"ChatbotIframe",{errorCode:O,errorType:L,context:{config:i,iframeUrl:e.src,timestamp:Date.now()}})};return e.addEventListener("error",t),function(){return e.removeEventListener("error",t)}}}),[i]),e.createElement("iframe",{ref:l,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"}})},K=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}a(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){I.trackError(new Error(j[S]({component:this.props.componentName||void 0,error:e.message,stack:t.componentStack})),this.props.componentName||void 0,{errorCode:S,errorType:M,context:{originalError:e,componentStack:t.componentStack,timestamp:Date.now()}})},t.prototype.render=function(){return this.state.hasError?null:this.props.children},t}(r),J=function(t){var r=t.api_key,a=t.user_id,d=t.user_token,u=t.user_profile,p=t.onEvent,f=i(!1),h=f[0],v=f[1],y=i(!1),w=y[0],x=y[1],T=i(null),A=T[0],k=T[1],O=i(!1),D=O[0],S=O[1],N=i(null),L=N[0],M=N[1],U=i({});U[0];var z=U[1],P=o((function(e,t){null==p||p({type:e,timestamp:Date.now(),data:t})}),[p]);n((function(){if(r)try{I.initialize(r,a)}catch(e){I.trackError(e instanceof Error?e:new Error(j[C]({apiKey:r,error:String(e)})),"RobylonChatbot",{errorCode:C,errorType:R,context:{originalError:e,apiKey:r,userId:a,timestamp:Date.now()}})}else I.trackError(new Error(j[E](r)),"RobylonChatbot",{errorCode:E,errorType:R,context:{providedParams:{apiKey:r,hasApiKey:!1,hasUserId:!!a,userId:a,hasUserToken:!!d,userToken:d,hasUserProfile:!!u},timestamp:Date.now()}})}),[r,a,d,u]),n((function(){var e={api_key:r,user_id:a,user_token:d,user_profile:u};if(!w){var t=!0;return r&&c(void 0,void 0,void 0,(function(){var n,o,i,c,p,f,h,b,y,w,C,T,A,O,D;return l(this,(function(l){switch(l.label){case 0:if(!r)return I.trackError(new Error(j[E](r)),"RobylonChatbot",{errorCode:E,errorType:R,context:{providedConfig:e,timestamp:Date.now()}}),[2];x(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),o=!1,(n=a||void 0)?o=!1:(n=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()}("rblyn_anon"),n||(S="rblyn_anon",N=n="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)})),L=365,(U=new Date).setTime(U.getTime()+24*L*60*60*1e3),document.cookie="".concat(S,"=").concat(N,";expires=").concat(U.toUTCString(),";path=/")),o=!0),[4,F(r,n,d)];case 2:return i=l.sent(),g.log("data initializeChatbot",i),c=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],p=m(),f=s(s({},p),u?Object.fromEntries(Object.entries(u).filter((function(e){var t=e[0];return c.includes(t)}))):{}),h={chatbotId:r,userId:n,token:d,isAnonymous:o,domain:"",brand_colour:(null===(w=null===(y=i.user.org_info.brand_config)||void 0===y?void 0:y.colors)||void 0===w?void 0:w.brand_color)||"",image_url:(null===(T=null===(C=i.user.org_info)||void 0===C?void 0:C.brand_config)||void 0===T?void 0:T.launcher_logo_url)||"",userProfile:f,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(A=i.user.org_info.brand_config)||void 0===A?void 0:A.display_name)||"",welcome_message:(null===(O=i.user.org_info.brand_config)||void 0===O?void 0:O.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(D=i.user.org_info.brand_config)||void 0===D?void 0:D.redirect_url)||""}},M(h),z(e),B(h,v,k),[3,5];case 3:return b=l.sent(),t?(I.trackError(b instanceof Error?b:new Error(j[_]({reason:b instanceof Error?b.message:String(b),config:e})),"RobylonChatbot",{errorCode:_,errorType:R,context:{initializationProps:e,originalError:b,timestamp:Date.now()}}),k(b instanceof Error?b.message:"Failed to initialize chatbot"),[3,5]):[2];case 4:return t&&x(!1),[7];case 5:return[2]}var S,N,L,U}))})),function(){t=!1}}}),[r,a,d,u]);return r?A?(g.error("Chatbot error:",A),null):L?e.createElement(K,{componentName:"RobylonChatbot"},h?e.createElement(e.Fragment,null,e.createElement(K,{componentName:"ChatbotFloatingButton"},e.createElement(H,{config:L,toggleIframe:function(){return S(!D)},isIframeVisible:D,onEvent:p})),e.createElement(K,{componentName:"ChatbotIframe"},e.createElement(W,{config:L,isVisible:D,onClose:function(){S(!1),P(b.CHATBOT_CLOSED)},onEvent:p}))):null):null:(g.error("Missing required configuration: api_key or user_id"),null)},Z=function(e){var t=i({isLoading:!0,isInitialized:!1,error:null}),o=t[0],r=t[1],a=function(e){r((function(t){return s(s({},t),{isInitialized:e})}))},c=function(e){r((function(t){return s(s({},t),{error:e})}))};return n((function(){!function(){try{B(e,a,c)}catch(e){r((function(t){return s(s({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),o};export{J as Chatbot,Z as useChatbot};
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robylon/web-react-sdk",
3
- "version": "1.1.15-staging.2",
3
+ "version": "1.1.15-staging.3",
4
4
  "description": "React SDK for Robylon AI Chatbot",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",