@meetelise/chat 1.20.92 → 1.20.93

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetelise/chat",
3
- "version": "1.20.92",
3
+ "version": "1.20.93",
4
4
  "description": "",
5
5
  "main": "public/dist/index.js",
6
6
  "type": "module",
@@ -3249,7 +3249,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
3249
3249
  </button>
3250
3250
  </div>
3251
3251
  </div>
3252
- `:B``}};Ur.styles=[Fr],kr([de({attribute:!0})],Ur.prototype,"channel",void 0),kr([de({attribute:!0})],Ur.prototype,"myPubnub",void 0),kr([de({attribute:!0})],Ur.prototype,"buildingSlug",void 0),kr([de({attribute:!0})],Ur.prototype,"building",void 0),kr([de({attribute:!0})],Ur.prototype,"brandColor",void 0),kr([de({attribute:!0})],Ur.prototype,"onClickExit",void 0),kr([de({attribute:!0})],Ur.prototype,"onMount",void 0),kr([pe("#message-input",!0)],Ur.prototype,"messageInput",void 0),kr([pe("#conversation-body",!0)],Ur.prototype,"messageBody",void 0),kr([ce()],Ur.prototype,"messages",void 0),kr([ce()],Ur.prototype,"isMobile",void 0),kr([ce()],Ur.prototype,"isLoadingMessages",void 0),kr([ce()],Ur.prototype,"websitePreviewMapping",void 0),Ur=kr([ue("pubnub-chat")],Ur);var qr,Br,Lr=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a};!function(e){e.TALKJS="talkjs",e.PUBNUB="pubnub"}(Br||(Br={}));let Jr=qr=class extends ae{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.themeId="Glass",this.useMiniWidget=!0,this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.popup=null,this.theme=Si({themeId:this.themeId,brandColor:this.brandColor}),this.chatId="",this.analytics=null,this.isMobile=r(),this.launcher=null,this.building=null,this.buildingABTestType=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=qn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.talkjsPopupElement=null,this.chatProvider=Br.TALKJS,this.displayPubnubChat=!1,this.myPubnub=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{qr.session=Ee.ready.then((()=>{const e=new Ee.User({id:"anonymous-"+di(this.orgSlug,this.buildingSlug),name:"Me",email:null,role:"Default"});return new Ee.Session({appId:"ogKIvCor",me:e})})),await this.setBuildingDerivedInfo(),await this.initializeLaunchJS()&&(this.attachOnClickToLauncher(),this.isLoading=!1)},this.setBuildingDerivedInfo=async()=>{var e,n,i;if(!this.buildingSlug||!this.orgSlug)return;const[r,o,a,s,u,l,d]=await Promise.all([Ai(this.orgSlug,this.buildingSlug),Ii(this.buildingSlug),Cr(this.buildingSlug),Ni(this.buildingSlug,document.referrer),Bn(this.buildingSlug),Ln(this.buildingSlug),Ci(this.buildingSlug)]);r.phoneNumber=Pe(r.phoneNumber),this.building=r,this.buildingABTestType=null!==(e=null==o?void 0:o.abTestType)&&void 0!==e?e:"",this.leadSources=a,this.currentLeadSource=s,this.featureFlagShowDropdown=u,d&&(null===this.brandColor&&(this.brandColor=null!==(n=d.primaryColor)&&void 0!==n?n:null),this.isMinimized=!!d.autoMinimize,d.designConcept&&(d.designConcept===xi.MINIMIZED&&(this.isMobile=!0),d.designConcept===xi.PILLS&&(this.buildingABTestType=null),d.designConcept===xi.EMOJI&&(this.buildingABTestType=Oi.ConceptEmoji))),null===this.brandColor&&(this.brandColor=vi);let c=null;l&&(c=await async function(e,n){try{const i=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/phone-number-by-source?source=${n}`);return i.data?{number:Pe(i.data.number),isMatch:i.data.isMatch,isPropertyWebsiteCatchall:i.data.isPropertyWebsiteCatchall}:null}catch(e){return null}}(this.buildingSlug,this.currentLeadSource)),this.phoneNumberForSource=c||{number:this.building.phoneNumber,isMatch:!1,isPropertyWebsiteCatchall:!0},this.currentLeadSource&&(this.leadSources.includes(this.currentLeadSource)||this.leadSources.push(this.currentLeadSource)),An(this.building.id),this.chatId=di(this.orgSlug,this.buildingSlug),this.avatarSrc=this.avatarSrc||this.building.avatarSrc,this.theme=Si({themeId:null!==(i=this.themeId)&&void 0!==i?i:this.building.themeId,brandColor:this.brandColor}),this.analytics=new Zn(this.orgSlug,this.buildingSlug,this.chatId,this.currentLeadSource),this.analytics.ping("webchat_heartbeat")},this.initializeLaunchJS=async()=>{var e;if(!this.building||!this.theme)return;if(this.popup&&this.launcher)return;const[t,n,i,r]=await Promise.all([this.building,this.theme,this.avatarSrc,qr.session]);return t.conversationMaintenanceMode?(console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear."),!1):r?(await this.configureTalkJSPopup(t,n,r,i),this.configureLauncherElement(),null===(e=this.analytics)||void 0===e||e.ping("load"),this.yardiDNIScriptInterval=setInterval((()=>this.pollForYardiCampaignSource()),1e3),setTimeout(clearInterval,15e3,this.yardiDNIScriptInterval),!0):void 0},this.configureLauncherElement=()=>{this.popup&&this.launcherRef.value&&(this.launcher=this.launcherRef.value)},this.configureTalkJSPopup=async(e,t,n,i)=>{var r;const o=n.createPopup(Ti(n,e,t,i||e.avatarSrc,this.chatId,this.isMobile),{launcher:"never",showCloseInHeader:!0,messageField:{placeholder:"Ask a question..."}});await o.mount({show:!1}),o.on("close",(()=>{this.hideLauncher=!1}));const a=document.querySelector(".__talkjs_popup");if(this.talkjsPopupElement=a,!a)throw new Error("Failed to find chat window");a.classList.add("meetelise-chat","pane"),this.isMobile||a.classList.add("launcher__desktop"),a.style.zIndex="99999999999",this.popup=o,this.shouldAutoOpenChat(e.autoOpenChatWidget)&&(this.popup.show(),this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp(),null===(r=this.analytics)||void 0===r||r.ping("autoOpen"))},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!an(un(t)));return!!e&&!!n&&!r()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.firstUpdated=async()=>{await async function(e){try{return(await t().get(Un(e),{params:{building_slug:e,flag_type:"bool",feature_flag:"use-pubnub-chat-provider",default_str:null,default_bool:!1}})).data}catch(e){return!1}}(this.buildingSlug)?(this.chatProvider=Br.PUBNUB,this.initializePubnubVariables()):this.initializeInstanceVariables()},this.initializePubnubVariables=async()=>{await this.setBuildingDerivedInfo(),this.building&&(this.building.conversationMaintenanceMode?console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear."):(this.myPubnub=new class{constructor(e,t,n){this.apiHost="https://app.meetelise.com",this.building=null,this.ttlHours=24,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;this.messages=[...this.messages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}];const n="eliseai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.messages,isLoading:n}),!n&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){ti({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}},this.removeChatListeners=()=>{this.pubnub&&this.channel&&(this.pubnub.unsubscribe({channels:[this.channel]}),this.pubnub.removeListener(this.listenerParams))},this.sendMessage=async e=>{if(e){if(!this.pubnub&&!await this.initializePubnub())return;await this.withAuthToken((async()=>{var t,n;this.pubnub&&this.channel&&(this.eliseResponseTimeout=setTimeout((()=>{console.error("Elise AI did not respond in time..."),ti({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),3e4),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(t=this.building)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,userId:null===(n=this.building)||void 0===n?void 0:n.userId}}))})),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.createChatStorageKey=e=>{const t=tn(new Date),n=null!=e?e:`lead_${li()}_${this.buildingSlug}`;return localStorage.setItem("com.eliseai.webchat.slug="+this.buildingSlug,JSON.stringify({buildingSlug:this.buildingSlug,leadId:n,timestamp:t})),{leadId:n,timestamp:un(t),buildingSlug:this.buildingSlug}},this.getChatStorageKey=(e=!0)=>{const t=localStorage.getItem("com.eliseai.webchat.slug="+this.buildingSlug);if(t)try{const e=JSON.parse(t),n=e.buildingSlug,i=e.leadId,r=new Date(e.timestamp);if(this.isChatKeyValid({leadId:i,timestamp:r,buildingSlug:n}))return{leadId:i,timestamp:r,buildingSlug:n}}catch(e){console.warn("Error getting chat storage key")}return e?this.createChatStorageKey():{leadId:null,timestamp:null,buildingSlug:null}},this.isChatKeyValid=e=>{if(e.buildingSlug!==this.buildingSlug||!e.leadId||!e.timestamp)return!1;const t=Rr(new Date,this.ttlHours);return function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t);return n.getTime()<i.getTime()}(e.timestamp,t)},this.buildingSlug=e,this.building=t,this.orgSlug=n}addChatListener(e){this.chatListener=e}async initializePubnub(){const e=this.getChatStorageKey();if(!e.leadId)return void ti({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:ei.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug});this.leadUserId=e.leadId,this.channel=`webchat_${this.leadUserId}`,e.timestamp&&function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t);return n.getTime()>i.getTime()}(e.timestamp,Rr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(Nr())({publishKey:t.keys.publish_key,subscribeKey:t.keys.subscribe_key,userId:this.leadUserId,authKey:t.auth.result.token}),this.withAuthToken((()=>new Promise((()=>this.handleChatListeners())))),await this.withAuthToken((()=>this.getChannelHistory())),this.pubnub):void 0}async fetchToken(e,n){try{return(await t().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${n}`)).data}catch(e){ti({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return null}async fetchChannelExists(e){try{return(await t().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}catch(e){ti({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return!1}async withAuthToken(t){try{await t()}catch(n){if(n instanceof e.AxiosError&&n&&n.response&&403===n.response.status)try{if(!this.pubnub||!this.leadUserId||!this.channel)return;const e=await this.fetchToken(this.leadUserId,this.channel);if(!e)return;this.pubnub.setAuthKey(e.auth.result.token),await t()}catch(e){ti({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}async getChannelHistory(){var e;try{const t=await new Promise(((e,t)=>{this.pubnub&&this.channel&&this.pubnub.fetchMessages({channels:[this.channel],count:100},((n,i)=>{n.error?(ti({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),t(n)):e(i)}))}));if(this.channel&&0!==Object.keys(t.channels).length){const n=t.channels[this.channel],i=[];n.forEach((e=>{e.uuid&&i.push({channel:e.channel,message:e.message,publisher:e.uuid,subscription:e.channel,timetoken:+e.timetoken})})),this.messages=i,null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ti({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{error:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}(this.buildingSlug,this.building,this.orgSlug),this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey(!1))&&await this.myPubnub.initializePubnub(),this.attachOnClickToLauncher(),this.shouldAutoOpenChat(this.building.autoOpenChatWidget)&&(this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp()),this.isLoading=!1))},this.handleContactClicked=e=>{var t,n;this.chatProvider===Br.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Br.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.chatProvider===Br.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Br.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e)},this.handleContactTabClicked=e=>{var t,n;this.chatProvider===Br.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Br.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickPhoneOption(e)},this.adjustTopHeaderContactCoords=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById(this.chatProvider===Br.TALKJS?"chatAdditionalActionsTalkjs":"chatAdditionalActionsPubnub");if(r)if(this.chatProvider===Br.TALKJS&&this.talkjsPopupElement){const e=this.talkjsPopupElement.getBoundingClientRect();r.style.left=`${e.left+20}px`,r.style.top=e.bottom-24+"px"}else if(this.chatProvider===Br.PUBNUB){const e=null===(i=null===(n=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("pubnub-chat"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.getElementById("pubnub-chat-container"),o=null==e?void 0:e.getBoundingClientRect();if(!o)return;r.style.left=`${o.left}px`,r.style.top=`${o.bottom}px`}},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized},this.renderChatAdditionalActions=(e,t)=>{var n,i,r,o,a,s,u,l;return B` <div
3252
+ `:B``}};Ur.styles=[Fr],kr([de({attribute:!0})],Ur.prototype,"channel",void 0),kr([de({attribute:!0})],Ur.prototype,"myPubnub",void 0),kr([de({attribute:!0})],Ur.prototype,"buildingSlug",void 0),kr([de({attribute:!0})],Ur.prototype,"building",void 0),kr([de({attribute:!0})],Ur.prototype,"brandColor",void 0),kr([de({attribute:!0})],Ur.prototype,"onClickExit",void 0),kr([de({attribute:!0})],Ur.prototype,"onMount",void 0),kr([pe("#message-input",!0)],Ur.prototype,"messageInput",void 0),kr([pe("#conversation-body",!0)],Ur.prototype,"messageBody",void 0),kr([ce()],Ur.prototype,"messages",void 0),kr([ce()],Ur.prototype,"isMobile",void 0),kr([ce()],Ur.prototype,"isLoadingMessages",void 0),kr([ce()],Ur.prototype,"websitePreviewMapping",void 0),Ur=kr([ue("pubnub-chat")],Ur);var qr,Br,Lr=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a};!function(e){e.TALKJS="talkjs",e.PUBNUB="pubnub"}(Br||(Br={}));let Jr=qr=class extends ae{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.themeId="Glass",this.useMiniWidget=!0,this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.popup=null,this.theme=Si({themeId:this.themeId,brandColor:this.brandColor}),this.chatId="",this.analytics=null,this.isMobile=r(),this.launcher=null,this.building=null,this.buildingABTestType=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=qn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.talkjsPopupElement=null,this.chatProvider=Br.TALKJS,this.displayPubnubChat=!1,this.myPubnub=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{qr.session=Ee.ready.then((()=>{const e=new Ee.User({id:"anonymous-"+di(this.orgSlug,this.buildingSlug),name:"Me",email:null,role:"Default"});return new Ee.Session({appId:"ogKIvCor",me:e})})),await this.setBuildingDerivedInfo(),await this.initializeLaunchJS()&&(this.attachOnClickToLauncher(),this.isLoading=!1)},this.setBuildingDerivedInfo=async()=>{var e,n,i;if(!this.buildingSlug||!this.orgSlug)return;const[r,o,a,s,u,l,d]=await Promise.all([Ai(this.orgSlug,this.buildingSlug),Ii(this.buildingSlug),Cr(this.buildingSlug),Ni(this.buildingSlug,document.referrer),Bn(this.buildingSlug),Ln(this.buildingSlug),Ci(this.buildingSlug)]);r.phoneNumber=Pe(r.phoneNumber),this.building=r,this.buildingABTestType=null!==(e=null==o?void 0:o.abTestType)&&void 0!==e?e:"",this.leadSources=a,this.currentLeadSource=s,this.featureFlagShowDropdown=u,d&&(null===this.brandColor&&(this.brandColor=null!==(n=d.primaryColor)&&void 0!==n?n:null),this.isMinimized=!!d.autoMinimize,d.designConcept&&(d.designConcept===xi.MINIMIZED&&(this.isMobile=!0),d.designConcept===xi.PILLS&&(this.buildingABTestType=null),d.designConcept===xi.EMOJI&&(this.buildingABTestType=Oi.ConceptEmoji))),null===this.brandColor&&(this.brandColor=vi);let c=null;l&&(c=await async function(e,n){try{const i=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/phone-number-by-source?source=${n}`);return i.data?{number:Pe(i.data.number),isMatch:i.data.isMatch,isPropertyWebsiteCatchall:i.data.isPropertyWebsiteCatchall}:null}catch(e){return null}}(this.buildingSlug,this.currentLeadSource)),this.phoneNumberForSource=c||{number:this.building.phoneNumber,isMatch:!1,isPropertyWebsiteCatchall:!0},this.currentLeadSource&&(this.leadSources.includes(this.currentLeadSource)||this.leadSources.push(this.currentLeadSource)),An(this.building.id),this.chatId=di(this.orgSlug,this.buildingSlug),this.avatarSrc=this.avatarSrc||this.building.avatarSrc,this.theme=Si({themeId:null!==(i=this.themeId)&&void 0!==i?i:this.building.themeId,brandColor:this.brandColor}),this.analytics=new Zn(this.orgSlug,this.buildingSlug,this.chatId,this.currentLeadSource),this.analytics.ping("webchat_heartbeat")},this.initializeLaunchJS=async()=>{var e;if(!this.building||!this.theme)return;if(this.popup&&this.launcher)return;const[t,n,i,r]=await Promise.all([this.building,this.theme,this.avatarSrc,qr.session]);return t.conversationMaintenanceMode?(console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear."),!1):r?(await this.configureTalkJSPopup(t,n,r,i),this.configureLauncherElement(),null===(e=this.analytics)||void 0===e||e.ping("load"),this.yardiDNIScriptInterval=setInterval((()=>this.pollForYardiCampaignSource()),1e3),setTimeout(clearInterval,15e3,this.yardiDNIScriptInterval),!0):void 0},this.configureLauncherElement=()=>{this.popup&&this.launcherRef.value&&(this.launcher=this.launcherRef.value)},this.configureTalkJSPopup=async(e,t,n,i)=>{var r;const o=n.createPopup(Ti(n,e,t,i||e.avatarSrc,this.chatId,this.isMobile),{launcher:"never",showCloseInHeader:!0,messageField:{placeholder:"Ask a question..."}});await o.mount({show:!1}),o.on("close",(()=>{this.hideLauncher=!1}));const a=document.querySelector(".__talkjs_popup");if(this.talkjsPopupElement=a,!a)throw new Error("Failed to find chat window");a.classList.add("meetelise-chat","pane"),this.isMobile||a.classList.add("launcher__desktop"),a.style.zIndex="99999999999",this.popup=o,this.shouldAutoOpenChat(e.autoOpenChatWidget)&&(this.popup.show(),this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp(),null===(r=this.analytics)||void 0===r||r.ping("autoOpen"))},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!an(un(t)));return!!e&&!!n&&!r()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.firstUpdated=async()=>{await async function(e){try{return(await t().get(Un(e),{params:{building_slug:e,flag_type:"bool",feature_flag:"use-pubnub-chat-provider",default_str:null,default_bool:!1}})).data}catch(e){return!1}}(this.buildingSlug)?(this.chatProvider=Br.PUBNUB,this.initializePubnubVariables()):this.initializeInstanceVariables()},this.initializePubnubVariables=async()=>{await this.setBuildingDerivedInfo(),this.building&&(this.building.conversationMaintenanceMode?console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear."):(this.myPubnub=new class{constructor(e,t,n){this.apiHost="https://app.meetelise.com",this.building=null,this.ttlHours=24,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;this.messages=[...this.messages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}];const n="eliseai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.messages,isLoading:n}),!n&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){ti({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}},this.removeChatListeners=()=>{this.pubnub&&this.channel&&(this.pubnub.unsubscribe({channels:[this.channel]}),this.pubnub.removeListener(this.listenerParams))},this.sendMessage=async e=>{if(e){if(!this.pubnub&&!await this.initializePubnub())return;await this.withAuthToken((async()=>{var t,n;this.pubnub&&this.channel&&(this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.eliseResponseTimeout=setTimeout((()=>{console.error("Elise AI did not respond in time..."),ti({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),45e3),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(t=this.building)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,userId:null===(n=this.building)||void 0===n?void 0:n.userId}}))})),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.createChatStorageKey=e=>{const t=tn(new Date),n=null!=e?e:`lead_${li()}_${this.buildingSlug}`;return localStorage.setItem("com.eliseai.webchat.slug="+this.buildingSlug,JSON.stringify({buildingSlug:this.buildingSlug,leadId:n,timestamp:t})),{leadId:n,timestamp:un(t),buildingSlug:this.buildingSlug}},this.getChatStorageKey=(e=!0)=>{const t=localStorage.getItem("com.eliseai.webchat.slug="+this.buildingSlug);if(t)try{const e=JSON.parse(t),n=e.buildingSlug,i=e.leadId,r=new Date(e.timestamp);if(this.isChatKeyValid({leadId:i,timestamp:r,buildingSlug:n}))return{leadId:i,timestamp:r,buildingSlug:n}}catch(e){console.warn("Error getting chat storage key")}return e?this.createChatStorageKey():{leadId:null,timestamp:null,buildingSlug:null}},this.isChatKeyValid=e=>{if(e.buildingSlug!==this.buildingSlug||!e.leadId||!e.timestamp)return!1;const t=Rr(new Date,this.ttlHours);return function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t);return n.getTime()<i.getTime()}(e.timestamp,t)},this.buildingSlug=e,this.building=t,this.orgSlug=n}addChatListener(e){this.chatListener=e}async initializePubnub(){const e=this.getChatStorageKey();if(!e.leadId)return void ti({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:ei.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug});this.leadUserId=e.leadId,this.channel=`webchat_${this.leadUserId}`,e.timestamp&&function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t);return n.getTime()>i.getTime()}(e.timestamp,Rr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(Nr())({publishKey:t.keys.publish_key,subscribeKey:t.keys.subscribe_key,userId:this.leadUserId,authKey:t.auth.result.token}),this.withAuthToken((()=>new Promise((()=>this.handleChatListeners())))),await this.withAuthToken((()=>this.getChannelHistory())),this.pubnub):void 0}async fetchToken(e,n){try{return(await t().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${n}`)).data}catch(e){ti({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return null}async fetchChannelExists(e){try{return(await t().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}catch(e){ti({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return!1}async withAuthToken(t){try{await t()}catch(n){if(n instanceof e.AxiosError&&n&&n.response&&403===n.response.status)try{if(!this.pubnub||!this.leadUserId||!this.channel)return;const e=await this.fetchToken(this.leadUserId,this.channel);if(!e)return;this.pubnub.setAuthKey(e.auth.result.token),await t()}catch(e){ti({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}async getChannelHistory(){var e;try{const t=await new Promise(((e,t)=>{this.pubnub&&this.channel&&this.pubnub.fetchMessages({channels:[this.channel],count:100},((n,i)=>{n.error?(ti({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),t(n)):e(i)}))}));if(this.channel&&0!==Object.keys(t.channels).length){const n=t.channels[this.channel],i=[];n.forEach((e=>{e.uuid&&i.push({channel:e.channel,message:e.message,publisher:e.uuid,subscription:e.channel,timetoken:+e.timetoken})})),this.messages=i,null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ti({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{error:e},logType:ei.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}(this.buildingSlug,this.building,this.orgSlug),this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey(!1))&&await this.myPubnub.initializePubnub(),this.attachOnClickToLauncher(),this.shouldAutoOpenChat(this.building.autoOpenChatWidget)&&(this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp()),this.isLoading=!1))},this.handleContactClicked=e=>{var t,n;this.chatProvider===Br.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Br.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.chatProvider===Br.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Br.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e)},this.handleContactTabClicked=e=>{var t,n;this.chatProvider===Br.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Br.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickPhoneOption(e)},this.adjustTopHeaderContactCoords=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById(this.chatProvider===Br.TALKJS?"chatAdditionalActionsTalkjs":"chatAdditionalActionsPubnub");if(r)if(this.chatProvider===Br.TALKJS&&this.talkjsPopupElement){const e=this.talkjsPopupElement.getBoundingClientRect();r.style.left=`${e.left+20}px`,r.style.top=e.bottom-24+"px"}else if(this.chatProvider===Br.PUBNUB){const e=null===(i=null===(n=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("pubnub-chat"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.getElementById("pubnub-chat-container"),o=null==e?void 0:e.getBoundingClientRect();if(!o)return;r.style.left=`${o.left}px`,r.style.top=`${o.bottom}px`}},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized},this.renderChatAdditionalActions=(e,t)=>{var n,i,r,o,a,s,u,l;return B` <div
3253
3253
  id=${e}
3254
3254
  class=${ge({showTab:t,hideTab:!t})}
3255
3255
  >
package/src/MyPubnub.ts CHANGED
@@ -323,6 +323,10 @@ class MyPubnub {
323
323
  await this.withAuthToken(async () => {
324
324
  if (!this.pubnub || !this.channel) return;
325
325
 
326
+ if (this.eliseResponseTimeout) {
327
+ clearTimeout(this.eliseResponseTimeout);
328
+ this.eliseResponseTimeout = null;
329
+ }
326
330
  this.eliseResponseTimeout = setTimeout(() => {
327
331
  // eslint-disable-next-line no-console
328
332
  console.error("Elise AI did not respond in time...");
@@ -337,7 +341,7 @@ class MyPubnub {
337
341
  buildingSlug: this.buildingSlug,
338
342
  orgSlug: this.orgSlug,
339
343
  });
340
- }, 30000); // if after 30 seconds, no message - we log error
344
+ }, 45000); // if after 45 seconds, no message - we log error
341
345
 
342
346
  await this.pubnub.publish({
343
347
  channel: this.channel,