@meetelise/chat 1.20.100 → 1.20.102

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.100",
3
+ "version": "1.20.102",
4
4
  "description": "",
5
5
  "main": "public/dist/index.js",
6
6
  "type": "module",
@@ -3280,7 +3280,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
3280
3280
  </button>
3281
3281
  </div>
3282
3282
  </div>
3283
- `:B``}};Br.styles=[Dr],qr([de({attribute:!0})],Br.prototype,"channel",void 0),qr([de({attribute:!0})],Br.prototype,"myPubnub",void 0),qr([de({attribute:!0})],Br.prototype,"buildingSlug",void 0),qr([de({attribute:!0})],Br.prototype,"building",void 0),qr([de({attribute:!0})],Br.prototype,"brandColor",void 0),qr([de({attribute:!0})],Br.prototype,"onClickExit",void 0),qr([de({attribute:!0})],Br.prototype,"onMount",void 0),qr([pe("#message-input",!0)],Br.prototype,"messageInput",void 0),qr([pe("#conversation-body",!0)],Br.prototype,"messageBody",void 0),qr([ce()],Br.prototype,"messages",void 0),qr([ce()],Br.prototype,"isMobile",void 0),qr([ce()],Br.prototype,"isLoadingMessages",void 0),qr([ce()],Br.prototype,"websitePreviewMapping",void 0),Br=qr([ue("pubnub-chat")],Br);var Lr,Jr,jr=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"}(Jr||(Jr={}));let Hr=Lr=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=Ti({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=Jr.TALKJS,this.showTourNextToChat=!1,this.displayPubnubChat=!1,this.myPubnub=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{Lr.session=Ee.ready.then((()=>{const e=new Ee.User({id:"anonymous-"+ci(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=await xi(this.orgSlug,this.buildingSlug);if(1!==r.active)return;const[o,a,s,u,l,d]=await Promise.all([Ni(this.buildingSlug),Ir(this.buildingSlug),Ei(this.buildingSlug,document.referrer),Bn(this.buildingSlug),Ln(this.buildingSlug),Ii(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===Oi.MINIMIZED&&(this.isMobile=!0),d.designConcept===Oi.PILLS&&(this.buildingABTestType=null),d.designConcept===Oi.EMOJI&&(this.buildingABTestType=Ci.ConceptEmoji))),null===this.brandColor&&(this.brandColor=yi);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=ci(this.orgSlug,this.buildingSlug),this.avatarSrc=this.avatarSrc||this.building.avatarSrc,this.theme=Ti({themeId:null!==(i=this.themeId)&&void 0!==i?i:this.building.themeId,brandColor:this.brandColor}),this.analytics=new $n(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,Lr.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(Ai(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,this.showTourNextToChat=!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){if(!e)return!1;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=Jr.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;e.message.messageType!==Nr.noReply&&(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){ni({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ti.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..."),ni({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ti.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_${di()}_${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=_r(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 ni({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:ti.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,_r(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(Rr())({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){ni({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ti.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){ni({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ti.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){ni({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ti.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?(ni({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ti.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.filter((e=>e.message.messageType!==Nr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ni({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{error:e},logType:ti.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===Jr.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Jr.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,this.showTourNextToChat=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n,i;this.showTourNextToChat?null===(t=this.launcherRef.value)||void 0===t||t.onClickSSTOption(e):(this.hideLauncher?this.showTourNextToChat=!0:this.chatProvider===Jr.TALKJS?null===(n=this.popup)||void 0===n||n.hide():this.chatProvider===Jr.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(i=this.launcherRef.value)||void 0===i||i.onClickSSTOption(e))},this.handleContactTabClicked=e=>{var t,n;this.chatProvider===Jr.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Jr.PUBNUB&&(this.displayPubnubChat=!1),this.showTourNextToChat=!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===Jr.TALKJS?"chatAdditionalActionsTalkjs":"chatAdditionalActionsPubnub");if(r)if(this.chatProvider===Jr.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===Jr.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.showTourNextToChat=!1},this.renderChatAdditionalActions=(e,t)=>{var n,i,r,o,a,s,u,l;return B` <div
3283
+ `:B``}};Br.styles=[Dr],qr([de({attribute:!0})],Br.prototype,"channel",void 0),qr([de({attribute:!0})],Br.prototype,"myPubnub",void 0),qr([de({attribute:!0})],Br.prototype,"buildingSlug",void 0),qr([de({attribute:!0})],Br.prototype,"building",void 0),qr([de({attribute:!0})],Br.prototype,"brandColor",void 0),qr([de({attribute:!0})],Br.prototype,"onClickExit",void 0),qr([de({attribute:!0})],Br.prototype,"onMount",void 0),qr([pe("#message-input",!0)],Br.prototype,"messageInput",void 0),qr([pe("#conversation-body",!0)],Br.prototype,"messageBody",void 0),qr([ce()],Br.prototype,"messages",void 0),qr([ce()],Br.prototype,"isMobile",void 0),qr([ce()],Br.prototype,"isLoadingMessages",void 0),qr([ce()],Br.prototype,"websitePreviewMapping",void 0),Br=qr([ue("pubnub-chat")],Br);var Lr,Jr,jr=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"}(Jr||(Jr={}));let Hr=Lr=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=Ti({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=Jr.TALKJS,this.showTourNextToChat=!1,this.displayPubnubChat=!1,this.myPubnub=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{Lr.session=Ee.ready.then((()=>{const e=new Ee.User({id:"anonymous-"+ci(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=await xi(this.orgSlug,this.buildingSlug);if(1!==r.active)return;const[o,a,s,u,l,d]=await Promise.all([Ni(this.buildingSlug),Ir(this.buildingSlug),Ei(this.buildingSlug,document.referrer),Bn(this.buildingSlug),Ln(this.buildingSlug),Ii(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===Oi.MINIMIZED&&(this.isMobile=!0),d.designConcept===Oi.PILLS&&(this.buildingABTestType=null),d.designConcept===Oi.EMOJI&&(this.buildingABTestType=Ci.ConceptEmoji))),null===this.brandColor&&(this.brandColor=yi);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=ci(this.orgSlug,this.buildingSlug),this.avatarSrc=this.avatarSrc||this.building.avatarSrc,this.theme=Ti({themeId:null!==(i=this.themeId)&&void 0!==i?i:this.building.themeId,brandColor:this.brandColor}),this.analytics=new $n(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,Lr.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(Ai(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,this.showTourNextToChat=!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){if(!e)return!1;try{return!!e&&(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=Jr.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;e.message.messageType!==Nr.noReply&&(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){ni({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ti.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..."),ni({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ti.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.clearChatStorageKey=()=>localStorage.removeItem("com.eliseai.webchat.slug="+this.buildingSlug),this.createChatStorageKey=e=>{const t=tn(new Date),n=null!=e?e:`lead_${di()}_${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=_r(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 ni({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:ti.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,_r(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(Rr())({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){ni({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ti.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){ni({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ti.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){ni({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ti.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?(ni({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ti.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.filter((e=>e.message.messageType!==Nr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ni({logTitle:"PUBNUB_ERROR_FETCHING_HISTORY",logData:{error:e},logType:ti.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===Jr.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Jr.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,this.showTourNextToChat=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n,i;this.showTourNextToChat?null===(t=this.launcherRef.value)||void 0===t||t.onClickSSTOption(e):(this.hideLauncher?this.showTourNextToChat=!0:this.chatProvider===Jr.TALKJS?null===(n=this.popup)||void 0===n||n.hide():this.chatProvider===Jr.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(i=this.launcherRef.value)||void 0===i||i.onClickSSTOption(e))},this.handleContactTabClicked=e=>{var t,n;this.chatProvider===Jr.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Jr.PUBNUB&&(this.displayPubnubChat=!1),this.showTourNextToChat=!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===Jr.TALKJS?"chatAdditionalActionsTalkjs":"chatAdditionalActionsPubnub");if(r)if(this.chatProvider===Jr.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===Jr.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.showTourNextToChat=!1},this.renderChatAdditionalActions=(e,t)=>{var n,i,r,o,a,s,u,l;return B` <div
3284
3284
  id=${e}
3285
3285
  class=${ge({showTab:t,hideTab:!t})}
3286
3286
  >
@@ -3301,7 +3301,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
3301
3301
  .brandColor=${this.brandColor}
3302
3302
  .onClick=${()=>{var e;this.chatProvider===Jr.PUBNUB?this.displayPubnubChat=!1:this.chatProvider===Jr.TALKJS&&(null===(e=this.popup)||void 0===e||e.hide()),this.showTourNextToChat=!1,this.hideLauncher=!1}}
3303
3303
  ></minimize-expand-button>
3304
- </div>`},this.attachOnClickToLauncher=()=>{const e=this.launcherRef.value;e&&(e.onChatTapped=async()=>{var e;if(this.chatProvider===Jr.PUBNUB)this.displayPubnubChat=!0;else if(this.chatProvider===Jr.TALKJS){if(!this.popup)return;this.popup.show(),null===(e=this.analytics)||void 0===e||e.ping("open")}this.hideLauncher=!0,this.hasMounted=!0})}}pollForYardiCampaignSource(){var e,t,n;(null===(t=null===(e=window.RCTPCampaign)||void 0===e?void 0:e.CampaignDetails)||void 0===t?void 0:t.Source)&&(null===(n=this.analytics)||void 0===n||n.ping("yardi-DNI-init"),this.yardiDNIScriptInterval&&clearInterval(this.yardiDNIScriptInterval))}async restartConversation(){if(!(this.analytics&&this.analytics.chatId&&this.building&&this.popup&&Lr.session))return;this.chatId=pi(this.orgSlug,this.buildingSlug);const e=await Lr.session;this.analytics.chatId=this.chatId,this.popup.select(Ai(e,this.building,this.theme,this.avatarSrc||this.building.avatarSrc,this.chatId,this.isMobile))}remove(){var e;null===(e=this.popup)||void 0===e||e.destroy()}open(){var e;null===(e=this.popup)||void 0===e||e.show()}close(){var e;null===(e=this.popup)||void 0===e||e.hide()}show(){this.launcher&&(this.launcher.style.display="")}hide(){this.launcher&&(this.launcher.style.display="none")}connectedCallback(){super.connectedCallback(),window.addEventListener("resize",this.adjustTopHeaderContactCoords)}disconnectedCallback(){var e;null===(e=this.myPubnub)||void 0===e||e.removeChatListeners(),window.removeEventListener("resize",this.adjustTopHeaderContactCoords),super.disconnectedCallback()}updated(){this.adjustTopHeaderContactCoords()}render(){var e,t,n,i,r,o,a,s,u,l,d,c,p,h,f,m,g,v,y,b,w,S,T,A,x,O,C,I,N,E,R,P,_,F,M,D,k,U;window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",pr);const q=this.hideLauncher&&!this.isLoading&&!this.isMobile;return B`
3304
+ </div>`},this.attachOnClickToLauncher=()=>{const e=this.launcherRef.value;e&&(e.onChatTapped=async()=>{var e;if(this.chatProvider===Jr.PUBNUB)this.displayPubnubChat=!0;else if(this.chatProvider===Jr.TALKJS){if(!this.popup)return;this.popup.show(),null===(e=this.analytics)||void 0===e||e.ping("open")}this.hideLauncher=!0,this.hasMounted=!0})}}pollForYardiCampaignSource(){var e,t,n;(null===(t=null===(e=window.RCTPCampaign)||void 0===e?void 0:e.CampaignDetails)||void 0===t?void 0:t.Source)&&(null===(n=this.analytics)||void 0===n||n.ping("yardi-DNI-init"),this.yardiDNIScriptInterval&&clearInterval(this.yardiDNIScriptInterval))}async restartConversation(){var e,t;if(this.chatProvider===Jr.PUBNUB)return null===(e=this.myPubnub)||void 0===e||e.removeChatListeners(),null===(t=this.myPubnub)||void 0===t||t.clearChatStorageKey(),this.myPubnub=null,this.displayPubnubChat=!1,await this.initializePubnubVariables(),void(this.hideLauncher=!1);if(!(this.analytics&&this.analytics.chatId&&this.building&&this.popup&&Lr.session))return;this.chatId=pi(this.orgSlug,this.buildingSlug);const n=await Lr.session;this.analytics.chatId=this.chatId,this.popup.select(Ai(n,this.building,this.theme,this.avatarSrc||this.building.avatarSrc,this.chatId,this.isMobile))}remove(){var e;null===(e=this.popup)||void 0===e||e.destroy()}open(){var e;null===(e=this.popup)||void 0===e||e.show()}close(){var e;null===(e=this.popup)||void 0===e||e.hide()}show(){this.launcher&&(this.launcher.style.display="")}hide(){this.launcher&&(this.launcher.style.display="none")}connectedCallback(){super.connectedCallback(),window.addEventListener("resize",this.adjustTopHeaderContactCoords)}disconnectedCallback(){var e;null===(e=this.myPubnub)||void 0===e||e.removeChatListeners(),window.removeEventListener("resize",this.adjustTopHeaderContactCoords),super.disconnectedCallback()}updated(){this.adjustTopHeaderContactCoords()}render(){var e,t,n,i,r,o,a,s,u,l,d,c,p,h,f,m,g,v,y,b,w,S,T,A,x,O,C,I,N,E,R,P,_,F,M,D,k,U;window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",pr);const q=this.hideLauncher&&!this.isLoading&&!this.isMobile;return B`
3305
3305
  <meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=1">
3306
3306
  <div id="aria-describe-info" style="display: none;">
3307
3307
  EliseAI widget that allows you to chat with a virtual assistant, book
package/src/MyPubnub.ts CHANGED
@@ -372,6 +372,9 @@ class MyPubnub {
372
372
  message.publisher.includes("lead_") &&
373
373
  message.message.customType === "lead_message";
374
374
 
375
+ clearChatStorageKey = (): void =>
376
+ localStorage.removeItem("com.eliseai.webchat.slug=" + this.buildingSlug);
377
+
375
378
  createChatStorageKey = (existingUserId?: string): ChatInfo => {
376
379
  const storageTimestamp = formatISO(new Date());
377
380
  const leadUserId = existingUserId ?? `lead_${uuid()}_${this.buildingSlug}`;
@@ -340,6 +340,15 @@ export class MEChat extends LitElement {
340
340
  }
341
341
 
342
342
  public async restartConversation(): Promise<void> {
343
+ if (this.chatProvider === ChatProviders.PUBNUB) {
344
+ this.myPubnub?.removeChatListeners();
345
+ this.myPubnub?.clearChatStorageKey();
346
+ this.myPubnub = null;
347
+ this.displayPubnubChat = false;
348
+ await this.initializePubnubVariables();
349
+ this.hideLauncher = false;
350
+ return;
351
+ }
343
352
  if (
344
353
  !this.analytics ||
345
354
  !this.analytics.chatId ||
@@ -92,12 +92,13 @@ export async function fetchFeatureFlagUseOverrideContactUsForm(
92
92
  }
93
93
  }
94
94
  export async function fetchFeatureFlagUsePubnub(
95
- buildingSlug: string
95
+ buildingSlug?: string
96
96
  ): Promise<boolean> {
97
97
  if (!buildingSlug) {
98
98
  return false;
99
99
  }
100
100
  try {
101
+ if (!buildingSlug) return false;
101
102
  const featureFlagResponse = await axios.get(
102
103
  featureFlagEndpoint(buildingSlug),
103
104
  {