@robylon/web-react-sdk 1.1.2 → 1.1.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 +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=function(){return t=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function n(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(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 o(e,t){var n,o,i,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[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]&&(r=0)),r;)try{if(n=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,o=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!(i=r.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){r.label=s[1];break}if(6===s[0]&&r.label<i[1]){r.label=i[1],i=s;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(s);break}i[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e],o=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}"function"==typeof SuppressedError&&SuppressedError;console.log("Raw API_URL:","https://stage-api.robylon.ai");var i={copilotUrl:"http://localhost:3000",environment:"development",apiUrl:"https://stage-api.robylon.ai"};console.log("CONFIG",i);var r=function(){return{copilotUrl:i.copilotUrl,environment:i.environment,apiUrl:i.apiUrl}},a=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):""}}))},s=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"},c=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(){var e=this.config.domain,t=window.location.origin;return console.log("expectedDomain, to current domain",e,t,e===t),e===t},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="×",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:s(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;console.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),console.log("iframe.src====>",t.src),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 i=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},i),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}},i)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var i="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,r={cookies:a(i),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(r,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;console.log("screenWidth",e),this.iframe.style.width=e<832?"".concat(e-64,"px"):"800px"}},e.prototype.loadSvgInline=function(e){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");e.innerHTML="",n&&e.appendChild(n)},e.prototype.toggleIcon=function(e,t){"block"===t.style.display?this.loadSvgInline(e):this.loadImage(e)},e.prototype.toggleIframe=function(){var e;if(console.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;console.log("toggleIframe"),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"),console.log("this.bubblePromptContainer",this.bubblePromptContainer)}},e.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},e.prototype.init=function(){this.createIframe(),this.createFloatingButton()},e}(),l=function(e,t,n){if(e.chatbotId&&e.userId&&e.token)try{new c(e);t(!0),console.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},d=function(t){var n=t.config,o=t.toggleIframe,i=t.isIframeVisible,a=r().copilotUrl;return console.log("config chabotfloatingbutton",n),e.createElement("div",{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:s(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:o},i?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(a,"/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,i=t.onClose,a=e.useRef(null),s=e.useRef(!1),c=e.useRef(!1);return e.useEffect((function(){var e=a.current;if(e&&!s.current){var t=r().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(n.chatbotId),s.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=a.current;if(e&&s.current){var t=r().copilotUrl;if(e.style.display=o?"block":"none",e.contentWindow&&o){var i=new URL(e.src).origin||t;e.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},i),c.current||(e.contentWindow.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:n.userId,token:n.token,userProfile:n.userProfile}},i),c.current=!0)}}}),[o,n.userId,n.token,n.userProfile]),e.useEffect((function(){if(a.current&&s.current){var e=r().copilotUrl,t=function(t){if(t.origin===e&&"closeChatbot"===t.data)i()};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[i]),e.createElement("iframe",{ref:a,id:"chat-iframe-rbyln",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:2e7,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"}})},f=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]};exports.Chatbot=function(i){var a=i.api_key,s=i.user_id,c=i.user_token,h=i.user_profile,p=e.useState(!1),g=p[0],m=p[1],b=e.useState(null),v=b[0],y=b[1],x=e.useState(!1),w=x[0],I=x[1],C=e.useState(null),_=C[0],M=C[1];e.useEffect((function(){a&&s?n(void 0,void 0,void 0,(function(){var e,i,d,u,p,g,b,v,x,w,I,C,_,E;return o(this,(function(k){switch(k.label){case 0:return k.trys.push([0,2,,3]),[4,(S=a,j=s,T=c,n(void 0,void 0,void 0,(function(){var e,t,n,i,a;return o(this,(function(o){switch(o.label){case 0:e=r().apiUrl,console.log("apiUrl====>",e),t="".concat(e,"/chat/chatbot/get/"),console.log("endpointUrl",t),n={client_user_id:j,org_id:S,token:T||j,extra_info:{}},o.label=1;case 1:return o.trys.push([1,4,,5]),[4,fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})];case 2:if(!(i=o.sent()).ok)throw new Error("Failed to fetch chatbot configuration");return[4,i.json()];case 3:return[2,o.sent()];case 4:throw a=o.sent(),console.error("Error fetching chatbot config:",a),a;case 5:return[2]}}))})))];case 1:return e=k.sent(),console.log("data initializeChatbot",e),i=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],d=function(){return{platform:"web",os:(null===(t=navigator.userAgentData)||void 0===t?void 0:t.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0],browser:f(),sdk_version:"1.1.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,t}(),u=t(t({},d),h?Object.fromEntries(Object.entries(h).filter((function(e){var t=e[0];return i.includes(t)}))):{}),p={chatbotId:a,userId:s,token:c||s,domain:"",brand_colour:(null===(x=null===(v=e.user.org_info.brand_config)||void 0===v?void 0:v.colors)||void 0===x?void 0:x.brand_color)||"",image_url:(null===(I=null===(w=e.user.org_info)||void 0===w?void 0:w.brand_config)||void 0===I?void 0:I.launcher_logo_url)||"",userProfile:u,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(C=e.user.org_info.brand_config)||void 0===C?void 0:C.display_name)||"",welcome_message:(null===(_=e.user.org_info.brand_config)||void 0===_?void 0:_.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(E=e.user.org_info.brand_config)||void 0===E?void 0:E.redirect_url)||""}},M(p),l(p,m,y),[3,3];case 2:return g=k.sent(),b=g instanceof Error?g.message:"Failed to initialize chatbot",console.error("Chatbot initialization error:",b),y(b),[3,3];case 3:return[2]}var S,j,T}))})):console.error("Missing required configuration: api_key or user_id")}),[a,s,c,h]);return a&&s?v?(console.error("Chatbot error:",v),null):_&&g?e.createElement(e.Fragment,null,e.createElement(d,{config:_,toggleIframe:function(){return I(!w)},isIframeVisible:w}),e.createElement(u,{config:_,isVisible:w,onClose:function(){I(!1)}})):null:(console.error("Missing required configuration: api_key or user_id"),null)},exports.useChatbot=function(n){var o=e.useState({isLoading:!0,isInitialized:!1,error:null}),i=o[0],r=o[1],a=function(e){r((function(n){return t(t({},n),{isInitialized:e})}))},s=function(e){r((function(n){return t(t({},n),{error:e})}))};return e.useEffect((function(){!function(){try{l(n,a,s)}catch(e){r((function(n){return t(t({},n),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[n.chatbotId,n.userId]),i};
|
|
1
|
+
"use strict";var e=require("react"),t=function(){return t=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function n(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{c(o.next(e))}catch(e){r(e)}}function s(e){try{c(o.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(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 o(e,t){var n,o,i,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[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]&&(r=0)),r;)try{if(n=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,o=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!(i=r.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){r.label=s[1];break}if(6===s[0]&&r.label<i[1]){r.label=i[1],i=s;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(s);break}i[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e],o=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}"function"==typeof SuppressedError&&SuppressedError;console.log("Raw API_URL:","https://stage-api.robylon.ai");var i={copilotUrl:"http://localhost:3000",environment:"development",apiUrl:"https://stage-api.robylon.ai"};console.log("CONFIG",i);var r=function(){return{copilotUrl:i.copilotUrl,environment:i.environment,apiUrl:i.apiUrl}},a=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):""}}))},s=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"},c=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(){var e=this.config.domain,t=window.location.origin;return console.log("expectedDomain, to current domain",e,t,e===t),e===t},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="×",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:s(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;console.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),console.log("iframe.src====>",t.src),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 i=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},i),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}},i)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var i="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,r={cookies:a(i),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(r,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;console.log("screenWidth",e),this.iframe.style.width=e<832?"".concat(e-64,"px"):"800px"}},e.prototype.loadSvgInline=function(e){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");e.innerHTML="",n&&e.appendChild(n)},e.prototype.toggleIcon=function(e,t){"block"===t.style.display?this.loadSvgInline(e):this.loadImage(e)},e.prototype.toggleIframe=function(){var e;if(console.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;console.log("toggleIframe"),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"),console.log("this.bubblePromptContainer",this.bubblePromptContainer)}},e.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},e.prototype.init=function(){this.createIframe(),this.createFloatingButton()},e}(),l=function(e,t,n){if(e.chatbotId&&e.userId&&e.token)try{new c(e);t(!0),console.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},d=function(t){var n=t.config,o=t.toggleIframe,i=t.isIframeVisible,a=r().copilotUrl;return console.log("config chabotfloatingbutton",n),e.createElement("div",{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:s(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:o},i?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(a,"/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,i=t.onClose,a=e.useRef(null),s=e.useRef(!1),c=e.useRef(!1);return e.useEffect((function(){var e=a.current;if(e&&!s.current){var t=r().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(n.chatbotId),s.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=a.current;if(e&&s.current){var t=r().copilotUrl;if(e.style.display=o?"block":"none",e.contentWindow&&o){var i=new URL(e.src).origin||t;e.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},i),c.current||(e.contentWindow.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:n.userId,token:n.token,userProfile:n.userProfile}},i),c.current=!0)}}}),[o,n.userId,n.token,n.userProfile]),e.useEffect((function(){if(a.current&&s.current){var e=r().copilotUrl,t=function(t){if(t.origin===e&&"closeChatbot"===t.data)i()};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[i]),e.createElement("iframe",{ref:a,id:"chat-iframe-rbyln",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:2e7,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"}})},f=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]};exports.Chatbot=function(i){var a=i.api_key,s=i.user_id,c=i.user_token,h=i.user_profile,p=e.useState(!1),g=p[0],m=p[1],b=e.useState(null),v=b[0],y=b[1],x=e.useState(!1),w=x[0],I=x[1],C=e.useState(null),_=C[0],M=C[1];e.useEffect((function(){a&&s?n(void 0,void 0,void 0,(function(){var e,i,d,u,p,g,b,v,x,w,I,C,_,E;return o(this,(function(k){switch(k.label){case 0:return k.trys.push([0,2,,3]),[4,(S=a,j=s,T=c,n(void 0,void 0,void 0,(function(){var e,t,n,i,a;return o(this,(function(o){switch(o.label){case 0:e=r().apiUrl,console.log("apiUrl====>",e),t="".concat(e,"/chat/chatbot/get/"),console.log("endpointUrl",t),n={client_user_id:j,org_id:S,token:T||j,extra_info:{}},o.label=1;case 1:return o.trys.push([1,4,,5]),[4,fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})];case 2:if(!(i=o.sent()).ok)throw new Error("Failed to fetch chatbot configuration");return[4,i.json()];case 3:return[2,o.sent()];case 4:throw a=o.sent(),console.error("Error fetching chatbot config:",a),a;case 5:return[2]}}))})))];case 1:return e=k.sent(),console.log("data initializeChatbot",e),i=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],d=function(){return{platform:"web",os:(null===(t=navigator.userAgentData)||void 0===t?void 0:t.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0],browser:f(),sdk_version:"1.1.3",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,t}(),u=t(t({},d),h?Object.fromEntries(Object.entries(h).filter((function(e){var t=e[0];return i.includes(t)}))):{}),p={chatbotId:a,userId:s,token:c||s,domain:"",brand_colour:(null===(x=null===(v=e.user.org_info.brand_config)||void 0===v?void 0:v.colors)||void 0===x?void 0:x.brand_color)||"",image_url:(null===(I=null===(w=e.user.org_info)||void 0===w?void 0:w.brand_config)||void 0===I?void 0:I.launcher_logo_url)||"",userProfile:u,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(C=e.user.org_info.brand_config)||void 0===C?void 0:C.display_name)||"",welcome_message:(null===(_=e.user.org_info.brand_config)||void 0===_?void 0:_.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(E=e.user.org_info.brand_config)||void 0===E?void 0:E.redirect_url)||""}},M(p),l(p,m,y),[3,3];case 2:return g=k.sent(),b=g instanceof Error?g.message:"Failed to initialize chatbot",console.error("Chatbot initialization error:",b),y(b),[3,3];case 3:return[2]}var S,j,T}))})):console.error("Missing required configuration: api_key or user_id")}),[a,s,c,h]);return a&&s?v?(console.error("Chatbot error:",v),null):_&&g?e.createElement(e.Fragment,null,e.createElement(d,{config:_,toggleIframe:function(){return I(!w)},isIframeVisible:w}),e.createElement(u,{config:_,isVisible:w,onClose:function(){I(!1)}})):null:(console.error("Missing required configuration: api_key or user_id"),null)},exports.useChatbot=function(n){var o=e.useState({isLoading:!0,isInitialized:!1,error:null}),i=o[0],r=o[1],a=function(e){r((function(n){return t(t({},n),{isInitialized:e})}))},s=function(e){r((function(n){return t(t({},n),{error:e})}))};return e.useEffect((function(){!function(){try{l(n,a,s)}catch(e){r((function(n){return t(t({},n),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[n.chatbotId,n.userId]),i};
|
|
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,useState as o}from"react";var i=function(){return i=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)};function r(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}function a(e,t){var n,o,i,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(r=0)),r;)try{if(n=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,o=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!(i=r.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){r.label=s[1];break}if(6===s[0]&&r.label<i[1]){r.label=i[1],i=s;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(s);break}i[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e],o=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;console.log("Raw API_URL:","https://stage-api.robylon.ai");var s={copilotUrl:"http://localhost:3000",environment:"development",apiUrl:"https://stage-api.robylon.ai"};console.log("CONFIG",s);var l=function(){return{copilotUrl:s.copilotUrl,environment:s.environment,apiUrl:s.apiUrl}},c=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):""}}))},d=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"},u=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(){var e=this.config.domain,t=window.location.origin;return console.log("expectedDomain, to current domain",e,t,e===t),e===t},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="×",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:d(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;console.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),console.log("iframe.src====>",t.src),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 i=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},i),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}},i)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var i="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,r={cookies:c(i),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(r,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;console.log("screenWidth",e),this.iframe.style.width=e<832?"".concat(e-64,"px"):"800px"}},e.prototype.loadSvgInline=function(e){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");e.innerHTML="",n&&e.appendChild(n)},e.prototype.toggleIcon=function(e,t){"block"===t.style.display?this.loadSvgInline(e):this.loadImage(e)},e.prototype.toggleIframe=function(){var e;if(console.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;console.log("toggleIframe"),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"),console.log("this.bubblePromptContainer",this.bubblePromptContainer)}},e.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},e.prototype.init=function(){this.createIframe(),this.createFloatingButton()},e}(),h=function(e,t,n){if(e.chatbotId&&e.userId&&e.token)try{new u(e);t(!0),console.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},f=function(t){var n=t.config,o=t.toggleIframe,i=t.isIframeVisible,r=l().copilotUrl;return console.log("config chabotfloatingbutton",n),e.createElement("div",{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:d(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:o},i?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(r,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))},p=function(o){var i=o.config,r=o.isVisible,a=o.onClose,s=t(null),c=t(!1),d=t(!1);return n((function(){var e=s.current;if(e&&!c.current){var t=l().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(i.chatbotId),c.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=s.current;if(e&&c.current){var t=l().copilotUrl;if(e.style.display=r?"block":"none",e.contentWindow&&r){var n=new URL(e.src).origin||t;e.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},n),d.current||(e.contentWindow.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:i.userId,token:i.token,userProfile:i.userProfile}},n),d.current=!0)}}}),[r,i.userId,i.token,i.userProfile]),n((function(){if(s.current&&c.current){var e=l().copilotUrl,t=function(t){if(t.origin===e&&"closeChatbot"===t.data)a()};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[a]),e.createElement("iframe",{ref:s,id:"chat-iframe-rbyln",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:2e7,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"}})},g=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(t){var s=t.api_key,c=t.user_id,d=t.user_token,u=t.user_profile,m=o(!1),b=m[0],v=m[1],y=o(null),x=y[0],w=y[1],I=o(!1),C=I[0],_=I[1],M=o(null),k=M[0],E=M[1];n((function(){s&&c?r(void 0,void 0,void 0,(function(){var e,t,n,o,f,p,m,b,y,x,I,C,_,M;return a(this,(function(k){switch(k.label){case 0:return k.trys.push([0,2,,3]),[4,(S=s,j=c,T=d,r(void 0,void 0,void 0,(function(){var e,t,n,o,i;return a(this,(function(r){switch(r.label){case 0:e=l().apiUrl,console.log("apiUrl====>",e),t="".concat(e,"/chat/chatbot/get/"),console.log("endpointUrl",t),n={client_user_id:j,org_id:S,token:T||j,extra_info:{}},r.label=1;case 1:return r.trys.push([1,4,,5]),[4,fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})];case 2:if(!(o=r.sent()).ok)throw new Error("Failed to fetch chatbot configuration");return[4,o.json()];case 3:return[2,r.sent()];case 4:throw i=r.sent(),console.error("Error fetching chatbot config:",i),i;case 5:return[2]}}))})))];case 1:return e=k.sent(),console.log("data initializeChatbot",e),t=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],n=function(){return{platform:"web",os:(null===(t=navigator.userAgentData)||void 0===t?void 0:t.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0],browser:g(),sdk_version:"1.1.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,t}(),o=i(i({},n),u?Object.fromEntries(Object.entries(u).filter((function(e){var n=e[0];return t.includes(n)}))):{}),f={chatbotId:s,userId:c,token:d||c,domain:"",brand_colour:(null===(y=null===(b=e.user.org_info.brand_config)||void 0===b?void 0:b.colors)||void 0===y?void 0:y.brand_color)||"",image_url:(null===(I=null===(x=e.user.org_info)||void 0===x?void 0:x.brand_config)||void 0===I?void 0:I.launcher_logo_url)||"",userProfile:o,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(C=e.user.org_info.brand_config)||void 0===C?void 0:C.display_name)||"",welcome_message:(null===(_=e.user.org_info.brand_config)||void 0===_?void 0:_.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(M=e.user.org_info.brand_config)||void 0===M?void 0:M.redirect_url)||""}},E(f),h(f,v,w),[3,3];case 2:return p=k.sent(),m=p instanceof Error?p.message:"Failed to initialize chatbot",console.error("Chatbot initialization error:",m),w(m),[3,3];case 3:return[2]}var S,j,T}))})):console.error("Missing required configuration: api_key or user_id")}),[s,c,d,u]);return s&&c?x?(console.error("Chatbot error:",x),null):k&&b?e.createElement(e.Fragment,null,e.createElement(f,{config:k,toggleIframe:function(){return _(!C)},isIframeVisible:C}),e.createElement(p,{config:k,isVisible:C,onClose:function(){_(!1)}})):null:(console.error("Missing required configuration: api_key or user_id"),null)},b=function(e){var t=o({isLoading:!0,isInitialized:!1,error:null}),r=t[0],a=t[1],s=function(e){a((function(t){return i(i({},t),{isInitialized:e})}))},l=function(e){a((function(t){return i(i({},t),{error:e})}))};return n((function(){!function(){try{h(e,s,l)}catch(e){a((function(t){return i(i({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),r};export{m as Chatbot,b as useChatbot};
|
|
1
|
+
import e,{useRef as t,useEffect as n,useState as o}from"react";var i=function(){return i=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},i.apply(this,arguments)};function r(e,t,n,o){return new(n||(n=Promise))((function(i,r){function a(e){try{l(o.next(e))}catch(e){r(e)}}function s(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))}function a(e,t){var n,o,i,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(r=0)),r;)try{if(n=1,o&&(i=2&s[0]?o.return:s[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,s[1])).done)return i;switch(o=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return r.label++,{value:s[1],done:!1};case 5:r.label++,o=s[1],s=[0];continue;case 7:s=r.ops.pop(),r.trys.pop();continue;default:if(!(i=r.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){r=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){r.label=s[1];break}if(6===s[0]&&r.label<i[1]){r.label=i[1],i=s;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(s);break}i[2]&&r.ops.pop(),r.trys.pop();continue}s=t.call(e,r)}catch(e){s=[6,e],o=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;console.log("Raw API_URL:","https://stage-api.robylon.ai");var s={copilotUrl:"http://localhost:3000",environment:"development",apiUrl:"https://stage-api.robylon.ai"};console.log("CONFIG",s);var l=function(){return{copilotUrl:s.copilotUrl,environment:s.environment,apiUrl:s.apiUrl}},c=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):""}}))},d=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"},u=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(){var e=this.config.domain,t=window.location.origin;return console.log("expectedDomain, to current domain",e,t,e===t),e===t},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="×",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:d(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;console.log("RobylonConfig?.domain====>",this.config.domain);var t=document.createElement("iframe");Object.assign(t.style,{position:"fixed",right:"32px",bottom:"86px",minWidth:"400px",width:"26%",maxWidth:"800px",top:"calc(10vh - 32px)",maxHeight:"45rem",height:"calc(100vh - 3rem - 10vh)",zIndex:"20000000",border:"none",boxShadow:"0px 0px 40px 0px rgba(14, 14, 15, 0.24)",transformOrigin:"bottom right",transition:"transform 0.3s ease-out",borderRadius:"1rem",display:"none"}),t.src="".concat(this.config.domain,"/chatbot-plugin?id=").concat(this.config.chatbotId),console.log("iframe.src====>",t.src),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 i=new URL(e.iframe.src).origin||e.config.domain;null===(n=t.contentWindow)||void 0===n||n.postMessage({domain:window.location.hostname,name:"checkDomain"},i),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}},i)}})),window.addEventListener("message",(function(n){var o;if(n.origin===e.config.domain){if("captureSessionData"===n.data){var i="66b33d16-5b38-4693-8772-1a1bd7dd412d"===e.config.chatbotId,r={cookies:c(i),localStorage:JSON.stringify(localStorage),sessionStorage:JSON.stringify(sessionStorage),action:"capturedSessionData",domain_name:window.location.hostname};null===(o=t.contentWindow)||void 0===o||o.postMessage(r,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;console.log("screenWidth",e),this.iframe.style.width=e<832?"".concat(e-64,"px"):"800px"}},e.prototype.loadSvgInline=function(e){var t=document.createElement("div");t.innerHTML='\n<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <g id="Chevron_Down">\n <path id="Vector" d="M19 9L12 16L5 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n </g>\n</svg>\n';var n=t.querySelector("svg");e.innerHTML="",n&&e.appendChild(n)},e.prototype.toggleIcon=function(e,t){"block"===t.style.display?this.loadSvgInline(e):this.loadImage(e)},e.prototype.toggleIframe=function(){var e;if(console.log("toggleIframe",this.iframe,this.logoContainer,this.chatBtnImage),this.iframe&&this.logoContainer&&this.chatBtnImage){var t=new URL(this.iframe.src).origin||this.config.domain;console.log("toggleIframe"),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"),console.log("this.bubblePromptContainer",this.bubblePromptContainer)}},e.prototype.closeIframe=function(){this.iframe&&this.logoContainer&&this.chatBtnImage&&(this.iframe.style.display="none",this.toggleIcon(this.logoContainer,this.iframe),this.chatBtnImage.style.objectFit="cover")},e.prototype.init=function(){this.createIframe(),this.createFloatingButton()},e}(),h=function(e,t,n){if(e.chatbotId&&e.userId&&e.token)try{new u(e);t(!0),console.log("Robylon SDK initialized successfully.")}catch(e){n(e instanceof Error?e.message:"Failed to initialize SDK")}else n("Incomplete configuration for SDK initialization.")},f=function(t){var n=t.config,o=t.toggleIframe,i=t.isIframeVisible,r=l().copilotUrl;return console.log("config chabotfloatingbutton",n),e.createElement("div",{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:d(n.brand_colour),borderRadius:"50%",alignItems:"center",justifyContent:"center",cursor:"pointer",overflow:"hidden"},onClick:o},i?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(r,"/chatbubble.png"),alt:"Chat",style:{zIndex:1e3,cursor:"pointer",borderRadius:"50%",objectFit:"cover",width:"100%",height:"100%"}}))},p=function(o){var i=o.config,r=o.isVisible,a=o.onClose,s=t(null),c=t(!1),d=t(!1);return n((function(){var e=s.current;if(e&&!c.current){var t=l().copilotUrl;e.src="".concat(t,"/chatbot-plugin?id=").concat(i.chatbotId),c.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=s.current;if(e&&c.current){var t=l().copilotUrl;if(e.style.display=r?"block":"none",e.contentWindow&&r){var n=new URL(e.src).origin||t;e.contentWindow.postMessage({domain:window.location.hostname,name:"openFrame"},n),d.current||(e.contentWindow.postMessage({domain:window.location.hostname,action:"registerUserId",data:{userId:i.userId,token:i.token,userProfile:i.userProfile}},n),d.current=!0)}}}),[r,i.userId,i.token,i.userProfile]),n((function(){if(s.current&&c.current){var e=l().copilotUrl,t=function(t){if(t.origin===e&&"closeChatbot"===t.data)a()};return window.addEventListener("message",t),function(){return window.removeEventListener("message",t)}}}),[a]),e.createElement("iframe",{ref:s,id:"chat-iframe-rbyln",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:2e7,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"}})},g=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(t){var s=t.api_key,c=t.user_id,d=t.user_token,u=t.user_profile,m=o(!1),b=m[0],v=m[1],y=o(null),x=y[0],w=y[1],I=o(!1),C=I[0],_=I[1],M=o(null),k=M[0],E=M[1];n((function(){s&&c?r(void 0,void 0,void 0,(function(){var e,t,n,o,f,p,m,b,y,x,I,C,_,M;return a(this,(function(k){switch(k.label){case 0:return k.trys.push([0,2,,3]),[4,(S=s,j=c,T=d,r(void 0,void 0,void 0,(function(){var e,t,n,o,i;return a(this,(function(r){switch(r.label){case 0:e=l().apiUrl,console.log("apiUrl====>",e),t="".concat(e,"/chat/chatbot/get/"),console.log("endpointUrl",t),n={client_user_id:j,org_id:S,token:T||j,extra_info:{}},r.label=1;case 1:return r.trys.push([1,4,,5]),[4,fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})];case 2:if(!(o=r.sent()).ok)throw new Error("Failed to fetch chatbot configuration");return[4,o.json()];case 3:return[2,r.sent()];case 4:throw i=r.sent(),console.error("Error fetching chatbot config:",i),i;case 5:return[2]}}))})))];case 1:return e=k.sent(),console.log("data initializeChatbot",e),t=["email","name","mobile","platform","OS","browser","sdk_version","device","screen_size"],n=function(){return{platform:"web",os:(null===(t=navigator.userAgentData)||void 0===t?void 0:t.platform)||(/Windows|Mac|Linux|Android|iOS/.exec(navigator.userAgent)||["Unknown"])[0],browser:g(),sdk_version:"1.1.3",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,t}(),o=i(i({},n),u?Object.fromEntries(Object.entries(u).filter((function(e){var n=e[0];return t.includes(n)}))):{}),f={chatbotId:s,userId:c,token:d||c,domain:"",brand_colour:(null===(y=null===(b=e.user.org_info.brand_config)||void 0===b?void 0:b.colors)||void 0===y?void 0:y.brand_color)||"",image_url:(null===(I=null===(x=e.user.org_info)||void 0===x?void 0:x.brand_config)||void 0===I?void 0:I.launcher_logo_url)||"",userProfile:o,chat_interface_config:{chat_bubble_prompts:[],display_name:(null===(C=e.user.org_info.brand_config)||void 0===C?void 0:C.display_name)||"",welcome_message:(null===(_=e.user.org_info.brand_config)||void 0===_?void 0:_.welcome_message)||"Hey! What can we help you with today?",redirect_url:(null===(M=e.user.org_info.brand_config)||void 0===M?void 0:M.redirect_url)||""}},E(f),h(f,v,w),[3,3];case 2:return p=k.sent(),m=p instanceof Error?p.message:"Failed to initialize chatbot",console.error("Chatbot initialization error:",m),w(m),[3,3];case 3:return[2]}var S,j,T}))})):console.error("Missing required configuration: api_key or user_id")}),[s,c,d,u]);return s&&c?x?(console.error("Chatbot error:",x),null):k&&b?e.createElement(e.Fragment,null,e.createElement(f,{config:k,toggleIframe:function(){return _(!C)},isIframeVisible:C}),e.createElement(p,{config:k,isVisible:C,onClose:function(){_(!1)}})):null:(console.error("Missing required configuration: api_key or user_id"),null)},b=function(e){var t=o({isLoading:!0,isInitialized:!1,error:null}),r=t[0],a=t[1],s=function(e){a((function(t){return i(i({},t),{isInitialized:e})}))},l=function(e){a((function(t){return i(i({},t),{error:e})}))};return n((function(){!function(){try{h(e,s,l)}catch(e){a((function(t){return i(i({},t),{error:e instanceof Error?e.message:"Failed to initialize SDK",isLoading:!1})}))}}()}),[e.chatbotId,e.userId]),r};export{m as Chatbot,b as useChatbot};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|