@meetelise/chat 1.20.153 → 1.20.154
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
package/public/dist/index.js
CHANGED
|
@@ -3554,7 +3554,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3554
3554
|
>
|
|
3555
3555
|
I agree
|
|
3556
3556
|
</button>
|
|
3557
|
-
</div>`;var Mr=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};let Dr=class extends re{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.chatId="",this.analytics=null,this.launcher=null,this.building=null,this.designConcept=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=zn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.showTourNextToChat=!1,this.displayPubnubChat=!1,this.myPubnub=null,this.enabledChatWidgets={call:!0,chat:!0,email:!0,text:!0,sst:!0},this.webchatConfigHasAutoOpenChat=!1,this.requiresConsent=!1,this.privacyPolicyUrl="http://bit.ly/me_privacy_policy",this.launcherRef=Ae(),this.firstUpdated=async()=>{await this.setBuildingDerivedInfo(),await this.initializeChatVariables(),this.handleChatInitializeAnalytics()},this.setBuildingDerivedInfo=async()=>{var e,n,i,r,o,a,s,u,l,d,c,p,h,f,m,g,v,y;if(!this.buildingSlug||!this.orgSlug)return;const b=await li(this.orgSlug,this.buildingSlug);if(b.conversationMaintenanceMode)return void console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear.");if(1!==b.active)return;b&&this.orgSlug&&Ur(this.orgSlug,this.buildingSlug);const[w,S,T,A,x,O,C]=await Promise.all([hi(this.buildingSlug),ur(this.buildingSlug),fi(this.buildingSlug,document.referrer),Wn(this.buildingSlug),Qn(this.buildingSlug),pi(b.id),Vn(this.buildingSlug)]);b.phoneNumber=Ne(b.phoneNumber),this.building=b,this.designConcept=null!==(e=null==w?void 0:w.abTestType)&&void 0!==e?e:"",this.leadSources=S,this.currentLeadSource=T,this.featureFlagShowDropdown=A;const I=await(async e=>{try{const n="https://app.meetelise.com",i=await t().get(`${n}/platformApi/webchat/${e}/phone-number`);if(i.data)return i.data}catch(t){return ii({logType:ni.error,buildingSlug:e,logTitle:"[ERROR_GETTING_PHONE_NUMBERS]",logData:{error:t}}),null}return null})(this.buildingSlug);var N,E;this.enabledChatWidgets={call:O&&!O.isGlobalDefault?O.config.shouldShowPhone:null===(r=null===(i=null===(n=this.building)||void 0===n?void 0:n.chatWidgets)||void 0===i?void 0:i.includes("CALL"))||void 0===r||r,chat:O&&!O.isGlobalDefault?O.config.shouldShowChat:null===(s=null===(a=null===(o=this.building)||void 0===o?void 0:o.chatWidgets)||void 0===a?void 0:a.includes("CHAT"))||void 0===s||s,email:O&&!O.isGlobalDefault?O.config.shouldShowEmail:null===(d=null===(l=null===(u=this.building)||void 0===u?void 0:u.chatWidgets)||void 0===l?void 0:l.includes("EMAIL"))||void 0===d||d,text:(O&&!O.isGlobalDefault?O.config.shouldShowText:null===(h=null===(p=null===(c=this.building)||void 0===c?void 0:c.chatWidgets)||void 0===p?void 0:p.includes("SMS"))||void 0===h||h)&&!!I,sst:O&&!O.isGlobalDefault?O.config.shouldShowSst:null===(g=null===(m=null===(f=this.building)||void 0===f?void 0:f.chatWidgets)||void 0===m?void 0:m.includes("SST"))||void 0===g||g},this.enabledChatWidgets.sst?(E=this.handleTourClicked,document.querySelectorAll("a").forEach((function(e){const t=e.getAttribute("href");t&&t.startsWith("https://app.meetelise.com/")&&e.addEventListener("click",(e=>{e.preventDefault(),E(e)}))}))):this.currentLeadSource&&(N=this.currentLeadSource,document.querySelectorAll("a").forEach((function(e){const t=e.getAttribute("href");if(t&&t.startsWith("https://app.meetelise.com/")){const n=t.includes("?")?"&":"?";e.setAttribute("href",t+n+`eliseParsedLeadSource=${encodeURIComponent(N)}`)}}))),O&&O.config&&(this.brandColor=null!==(v=O.config.primaryColor)&&void 0!==v?v:null,this.webchatConfigHasAutoOpenChat=O.config.autoOpenChat,this.requiresConsent=O.config.requiresConsent,this.privacyPolicyUrl=null!==(y=O.config.privacyPolicyUrl)&&void 0!==y?y:this.privacyPolicyUrl,O.config.displayStyle===di.MINIMIZED&&(this.isMinimized=!0),O.config.displayStyle===di.PILLS&&(this.designConcept=null),O.config.displayStyle===di.EMOJI&&(this.designConcept=di.EMOJI)),null===this.brandColor&&(this.brandColor=Fe);let R=null;x&&(R=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:Ne(i.data.number),isMatch:i.data.isMatch,isPropertyWebsiteCatchall:i.data.isPropertyWebsiteCatchall}:null}catch(e){return null}}(this.buildingSlug,this.currentLeadSource)),C&&(null==R?void 0:R.number)&&xr(R.number,this.orgSlug,this.buildingSlug);const _=localStorage.getItem("eliseai_phone_number_devtest");_&&(console.info("Using dev test phone number: ",_),xr(_,this.orgSlug,this.buildingSlug)),this.phoneNumberForSource=R||{number:this.building.phoneNumber,isMatch:!1,isPropertyWebsiteCatchall:!0},this.currentLeadSource&&(this.leadSources.includes(this.currentLeadSource)||this.leadSources.push(this.currentLeadSource)),Fn(this.building.id)},this.initializeChatVariables=async()=>{if(!this.building)return;if(this.building.conversationMaintenanceMode)return void console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear.");const n=(e=>{const t=localStorage.getItem("com.elise.webchat.slug="+e);if(t)try{const n=JSON.parse(t),i={leadId:n.leadId,timestamp:new Date(n.timestamp),buildingSlug:n.buildingSlug,initiatedChat:n.initiatedChat};if(Tr(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}})(this.buildingSlug),i=Tr(this.buildingSlug,n)?n:Sr(this.buildingSlug,!1);if(!i.leadId)throw new Error("Lead ID is null");this.myPubnub=new class{constructor(e,t,n,i=null,r){this.apiHost="https://app.meetelise.com",this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==Ar.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){ii({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}},this.handleDisconnect=()=>{this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.removeChatListeners()},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){const e=Sr(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))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..."),ii({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),6e4),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,leadSource:this.leadSource}}))})),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.buildingSlug=e,this.building=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`}addChatListener(e){this.chatListener=e}async initializePubnub(e){if(!e.leadId)return;this.leadUserId=e.leadId;const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(pr())({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){ii({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ni.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?(ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ni.warn,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!==Ar.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ni.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}(this.buildingSlug,this.building,this.orgSlug,this.currentLeadSource,i.leadId),i.initiatedChat&&await this.myPubnub.initializePubnub(n),this.attachOnClickToLauncher(),this.shouldAutoOpenChat(this.webchatConfigHasAutoOpenChat)&&(this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp()),this.isLoading=!1},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!gn(yn(t)));return!!e&&!!n&&!un()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",pn(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.handleContactClicked=e=>{var t;this.displayPubnubChat=!1,this.hideLauncher=!1,this.showTourNextToChat=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.showTourNextToChat?null===(t=this.launcherRef.value)||void 0===t||t.onClickSSTOption(e):(this.hideLauncher?this.showTourNextToChat=!0:this.displayPubnubChat=!1,this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e))},this.handleContactTabClicked=e=>{var t;this.displayPubnubChat=!1,this.showTourNextToChat=!1,this.hideLauncher=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickPhoneOption(e)},this.adjustPositionChatAdditionalActions=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("chatAdditionalActionsPubnub");if(!r)return;const o=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"),a=null==o?void 0:o.getBoundingClientRect();a&&(r.style.left=`${a.left}px`,r.style.top=`${a.bottom}px`)},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized,this.showTourNextToChat=!1},this.attachOnClickToLauncher=()=>{const e=this.launcherRef.value;e&&(e.onChatTapped=async()=>{this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0})},this.renderChatAdditionalActions=(e,t)=>U` <div
|
|
3557
|
+
</div>`;var Mr=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};let Dr=class extends re{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.chatId="",this.analytics=null,this.launcher=null,this.building=null,this.designConcept=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=zn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.showTourNextToChat=!1,this.displayPubnubChat=!1,this.myPubnub=null,this.enabledChatWidgets={call:!0,chat:!0,email:!0,text:!0,sst:!0},this.webchatConfigHasAutoOpenChat=!1,this.requiresConsent=!1,this.privacyPolicyUrl="http://bit.ly/me_privacy_policy",this.launcherRef=Ae(),this.firstUpdated=async()=>{await this.setBuildingDerivedInfo(),await this.initializeChatVariables(),this.handleChatInitializeAnalytics()},this.setBuildingDerivedInfo=async()=>{var e,n,i,r,o,a,s,u,l,d,c,p,h,f,m,g,v,y;if(!this.buildingSlug||!this.orgSlug)return;const b=await li(this.orgSlug,this.buildingSlug);if(b.conversationMaintenanceMode)return void console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear.");if(1!==b.active)return void console.warn("MeetElise has detected this building is NOT active. Chat icon will not appear.");b&&this.orgSlug&&Ur(this.orgSlug,this.buildingSlug);const[w,S,T,A,x,O,C]=await Promise.all([hi(this.buildingSlug),ur(this.buildingSlug),fi(this.buildingSlug,document.referrer),Wn(this.buildingSlug),Qn(this.buildingSlug),pi(b.id),Vn(this.buildingSlug)]);b.phoneNumber=Ne(b.phoneNumber),this.building=b,this.designConcept=null!==(e=null==w?void 0:w.abTestType)&&void 0!==e?e:"",this.leadSources=S,this.currentLeadSource=T,this.featureFlagShowDropdown=A;const I=await(async e=>{try{const n="https://app.meetelise.com",i=await t().get(`${n}/platformApi/webchat/${e}/phone-number`);if(i.data)return i.data}catch(t){return ii({logType:ni.error,buildingSlug:e,logTitle:"[ERROR_GETTING_PHONE_NUMBERS]",logData:{error:t}}),null}return null})(this.buildingSlug);var N,E;this.enabledChatWidgets={call:O&&!O.isGlobalDefault?O.config.shouldShowPhone:null===(r=null===(i=null===(n=this.building)||void 0===n?void 0:n.chatWidgets)||void 0===i?void 0:i.includes("CALL"))||void 0===r||r,chat:O&&!O.isGlobalDefault?O.config.shouldShowChat:null===(s=null===(a=null===(o=this.building)||void 0===o?void 0:o.chatWidgets)||void 0===a?void 0:a.includes("CHAT"))||void 0===s||s,email:O&&!O.isGlobalDefault?O.config.shouldShowEmail:null===(d=null===(l=null===(u=this.building)||void 0===u?void 0:u.chatWidgets)||void 0===l?void 0:l.includes("EMAIL"))||void 0===d||d,text:(O&&!O.isGlobalDefault?O.config.shouldShowText:null===(h=null===(p=null===(c=this.building)||void 0===c?void 0:c.chatWidgets)||void 0===p?void 0:p.includes("SMS"))||void 0===h||h)&&!!I,sst:O&&!O.isGlobalDefault?O.config.shouldShowSst:null===(g=null===(m=null===(f=this.building)||void 0===f?void 0:f.chatWidgets)||void 0===m?void 0:m.includes("SST"))||void 0===g||g},this.enabledChatWidgets.sst?(E=this.handleTourClicked,document.querySelectorAll("a").forEach((function(e){const t=e.getAttribute("href");t&&t.startsWith("https://app.meetelise.com/")&&e.addEventListener("click",(e=>{e.preventDefault(),E(e)}))}))):this.currentLeadSource&&(N=this.currentLeadSource,document.querySelectorAll("a").forEach((function(e){const t=e.getAttribute("href");if(t&&t.startsWith("https://app.meetelise.com/")){const n=t.includes("?")?"&":"?";e.setAttribute("href",t+n+`eliseParsedLeadSource=${encodeURIComponent(N)}`)}}))),O&&O.config&&(this.brandColor=null!==(v=O.config.primaryColor)&&void 0!==v?v:null,this.webchatConfigHasAutoOpenChat=O.config.autoOpenChat,this.requiresConsent=O.config.requiresConsent,this.privacyPolicyUrl=null!==(y=O.config.privacyPolicyUrl)&&void 0!==y?y:this.privacyPolicyUrl,O.config.displayStyle===di.MINIMIZED&&(this.isMinimized=!0),O.config.displayStyle===di.PILLS&&(this.designConcept=null),O.config.displayStyle===di.EMOJI&&(this.designConcept=di.EMOJI)),null===this.brandColor&&(this.brandColor=Fe);let R=null;x&&(R=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:Ne(i.data.number),isMatch:i.data.isMatch,isPropertyWebsiteCatchall:i.data.isPropertyWebsiteCatchall}:null}catch(e){return null}}(this.buildingSlug,this.currentLeadSource)),C&&(null==R?void 0:R.number)&&xr(R.number,this.orgSlug,this.buildingSlug);const _=localStorage.getItem("eliseai_phone_number_devtest");_&&(console.info("Using dev test phone number: ",_),xr(_,this.orgSlug,this.buildingSlug)),this.phoneNumberForSource=R||{number:this.building.phoneNumber,isMatch:!1,isPropertyWebsiteCatchall:!0},this.currentLeadSource&&(this.leadSources.includes(this.currentLeadSource)||this.leadSources.push(this.currentLeadSource)),Fn(this.building.id)},this.initializeChatVariables=async()=>{if(!this.building)return;if(this.building.conversationMaintenanceMode)return void console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear.");const n=(e=>{const t=localStorage.getItem("com.elise.webchat.slug="+e);if(t)try{const n=JSON.parse(t),i={leadId:n.leadId,timestamp:new Date(n.timestamp),buildingSlug:n.buildingSlug,initiatedChat:n.initiatedChat};if(Tr(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}})(this.buildingSlug),i=Tr(this.buildingSlug,n)?n:Sr(this.buildingSlug,!1);if(!i.leadId)throw new Error("Lead ID is null");this.myPubnub=new class{constructor(e,t,n,i=null,r){this.apiHost="https://app.meetelise.com",this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==Ar.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){ii({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}},this.handleDisconnect=()=>{this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.removeChatListeners()},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){const e=Sr(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))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..."),ii({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),6e4),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,leadSource:this.leadSource}}))})),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.buildingSlug=e,this.building=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`}addChatListener(e){this.chatListener=e}async initializePubnub(e){if(!e.leadId)return;this.leadUserId=e.leadId;const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(pr())({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){ii({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ni.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?(ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ni.warn,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!==Ar.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ni.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}(this.buildingSlug,this.building,this.orgSlug,this.currentLeadSource,i.leadId),i.initiatedChat&&await this.myPubnub.initializePubnub(n),this.attachOnClickToLauncher(),this.shouldAutoOpenChat(this.webchatConfigHasAutoOpenChat)&&(this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp()),this.isLoading=!1},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!gn(yn(t)));return!!e&&!!n&&!un()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",pn(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.handleContactClicked=e=>{var t;this.displayPubnubChat=!1,this.hideLauncher=!1,this.showTourNextToChat=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.showTourNextToChat?null===(t=this.launcherRef.value)||void 0===t||t.onClickSSTOption(e):(this.hideLauncher?this.showTourNextToChat=!0:this.displayPubnubChat=!1,this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e))},this.handleContactTabClicked=e=>{var t;this.displayPubnubChat=!1,this.showTourNextToChat=!1,this.hideLauncher=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickPhoneOption(e)},this.adjustPositionChatAdditionalActions=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("chatAdditionalActionsPubnub");if(!r)return;const o=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"),a=null==o?void 0:o.getBoundingClientRect();a&&(r.style.left=`${a.left}px`,r.style.top=`${a.bottom}px`)},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized,this.showTourNextToChat=!1},this.attachOnClickToLauncher=()=>{const e=this.launcherRef.value;e&&(e.onChatTapped=async()=>{this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0})},this.renderChatAdditionalActions=(e,t)=>U` <div
|
|
3558
3558
|
id=${e}
|
|
3559
3559
|
class=${fe({showTab:t,hideTab:!t})}
|
|
3560
3560
|
>
|
|
@@ -200,6 +200,10 @@ export class MEChat extends LitElement {
|
|
|
200
200
|
return;
|
|
201
201
|
}
|
|
202
202
|
if (building.active !== 1) {
|
|
203
|
+
// eslint-disable-next-line no-console
|
|
204
|
+
console.warn(
|
|
205
|
+
"MeetElise has detected this building is NOT active. Chat icon will not appear."
|
|
206
|
+
);
|
|
203
207
|
return;
|
|
204
208
|
}
|
|
205
209
|
if (building && this.orgSlug) {
|