@meetelise/chat 1.20.119 → 1.20.120
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 +1 -1
- package/public/demo/index.html +5 -2
- package/public/dist/index.js +1 -1
- package/src/MyPubnub.ts +1 -1
package/package.json
CHANGED
package/public/demo/index.html
CHANGED
|
@@ -119,8 +119,11 @@
|
|
|
119
119
|
import MEChat from "/index.js";
|
|
120
120
|
MEChat.start({
|
|
121
121
|
// 123 Main Street
|
|
122
|
-
organization: "test-company",
|
|
123
|
-
building: "3fc93384-91f5-11ed-98a3-43f5a2f42588",
|
|
122
|
+
// organization: "test-company",
|
|
123
|
+
// building: "3fc93384-91f5-11ed-98a3-43f5a2f42588",
|
|
124
|
+
|
|
125
|
+
organization: "TT",
|
|
126
|
+
building: "ffc97070-5c73-11ed-8507-77860136d3bf",
|
|
124
127
|
|
|
125
128
|
// AMLI
|
|
126
129
|
// organization: "amli",
|
package/public/dist/index.js
CHANGED
|
@@ -3414,7 +3414,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3414
3414
|
</button>
|
|
3415
3415
|
</div>
|
|
3416
3416
|
</div>
|
|
3417
|
-
`:k``}};Fr.styles=[Er],_r([ue({attribute:!0})],Fr.prototype,"onMount",void 0),_r([ue({attribute:!0})],Fr.prototype,"channel",void 0),_r([ue({attribute:!0})],Fr.prototype,"myPubnub",void 0),_r([ue({attribute:!0})],Fr.prototype,"buildingSlug",void 0),_r([ue({attribute:!0})],Fr.prototype,"building",void 0),_r([ue({attribute:!0})],Fr.prototype,"brandColor",void 0),_r([ue({attribute:!0})],Fr.prototype,"onClickExit",void 0),_r([ue({attribute:!0})],Fr.prototype,"requiresConsent",void 0),_r([de("#message-input",!0)],Fr.prototype,"messageInput",void 0),_r([de("#conversation-body",!0)],Fr.prototype,"messageBody",void 0),_r([le()],Fr.prototype,"messages",void 0),_r([le()],Fr.prototype,"isMobile",void 0),_r([le()],Fr.prototype,"isLoadingMessages",void 0),_r([le()],Fr.prototype,"hasReceivedConsent",void 0),_r([le()],Fr.prototype,"websitePreviewMapping",void 0),Fr=_r([ae("pubnub-chat")],Fr);const Mr={};var Dr=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 Ur=class extends re{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.chatId="",this.analytics=null,this.isMobile=Un(),this.launcher=null,this.building=null,this.designConcept=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=Vn.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.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;if(!this.buildingSlug||!this.orgSlug)return;const y=await hi(this.orgSlug,this.buildingSlug);if(1!==y.active)return;const[b,w,S,T,A,x,O]=await Promise.all([vi(this.buildingSlug),cr(this.buildingSlug),yi(this.buildingSlug,document.referrer),Kn(this.buildingSlug),Xn(this.buildingSlug),gi(y.id),Yn(this.buildingSlug)]);y.phoneNumber=Ne(y.phoneNumber),this.building=y,this.designConcept=null!==(e=null==b?void 0:b.abTestType)&&void 0!==e?e:"",this.leadSources=w,this.currentLeadSource=S,this.featureFlagShowDropdown=T;const C=await(async e=>{if(Mr[e])return Mr[e];const n=`https://app.meetelise.com/sms_management_numbers/webchat/building/${e}/numbers`,i=await t().get(n);return Mr[e]=i.data,i.data})(y.id);this.enabledChatWidgets={call:x&&!x.isGlobalDefault?x.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:x&&!x.isGlobalDefault?x.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:x&&!x.isGlobalDefault?x.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:(x&&!x.isGlobalDefault?x.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)&&C.length>0,sst:x&&!x.isGlobalDefault?x.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},x&&x.config&&(this.brandColor=null!==(v=x.config.primaryColor)&&void 0!==v?v:null,this.webchatConfigHasAutoOpenChat=x.config.autoOpenChat,this.requiresConsent=x.config.requiresConsent,x.config.displayStyle===fi.MINIMIZED&&(this.isMinimized=!0),x.config.displayStyle===fi.PILLS&&(this.designConcept=null),x.config.displayStyle===fi.EMOJI&&(this.designConcept=fi.EMOJI)),null===this.brandColor&&(this.brandColor=Fe);let I=null;var N;A&&(I=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)),O&&(null==I?void 0:I.number)&&((e=>{const t=document.querySelectorAll('a[data-selenium-id="click_to_call"]');t&&t.forEach((t=>{"A"===t.tagName&&(t.href=`tel:${Cr(e)}`);const n=t.querySelector(".click-to-call");n&&Or(n)&&(n.textContent=e)}))})(N=I.number),(e=>{const t=document.querySelectorAll(".dvPhone");t&&t.forEach((t=>{var n;"A"===t.tagName&&(t.href=`tel:${Cr(e)}`),Or(t)&&(t.textContent=e);const i=t.nextElementSibling;if("BR"!==(null==i?void 0:i.tagName)||"A"!==(null===(n=null==i?void 0:i.nextElementSibling)||void 0===n?void 0:n.tagName))return;const r=null==i?void 0:i.nextElementSibling;r.href=`sms:${Cr(e)}`,Or(r)&&(r.textContent=`Text: ${e}`)}))})(N),(e=>{const t=document.querySelectorAll(".click_to_call_href");t&&2===t.length&&t.forEach((t=>{"A"===t.tagName&&(t.href=`tel:${Cr(e)}`);const n=t.querySelector(".click_to_call")||t.querySelector(".click_to_call_foot");n&&Or(n)&&(n.textContent=e)}))})(N)),this.phoneNumberForSource=I||{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.initializeChatVariables=async()=>{var n;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!==Tr.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){pi({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ci.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&&!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..."),pi({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ci.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}}))})),!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_${Sr()}_${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=xr(e.timestamp,this.ttlHours);return function(e,t){ke(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 pi({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:ci.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug});this.leadUserId=e.leadId,this.channel=`webchat_${this.leadUserId}`,e.timestamp&&function(e,t){ke(2,arguments);var n=qe(e),i=qe(t);return n.getTime()>i.getTime()}(e.timestamp,xr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(fr())({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){pi({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ci.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){pi({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ci.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){pi({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ci.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?(pi({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ci.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!==Tr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){pi({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ci.warn,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(null!==(n=this.building.autoOpenChatWidget)&&void 0!==n?n: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&&!an(un(t)));return!!e&&!!n&&!Un()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){ke(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)=>k` <div
|
|
3417
|
+
`:k``}};Fr.styles=[Er],_r([ue({attribute:!0})],Fr.prototype,"onMount",void 0),_r([ue({attribute:!0})],Fr.prototype,"channel",void 0),_r([ue({attribute:!0})],Fr.prototype,"myPubnub",void 0),_r([ue({attribute:!0})],Fr.prototype,"buildingSlug",void 0),_r([ue({attribute:!0})],Fr.prototype,"building",void 0),_r([ue({attribute:!0})],Fr.prototype,"brandColor",void 0),_r([ue({attribute:!0})],Fr.prototype,"onClickExit",void 0),_r([ue({attribute:!0})],Fr.prototype,"requiresConsent",void 0),_r([de("#message-input",!0)],Fr.prototype,"messageInput",void 0),_r([de("#conversation-body",!0)],Fr.prototype,"messageBody",void 0),_r([le()],Fr.prototype,"messages",void 0),_r([le()],Fr.prototype,"isMobile",void 0),_r([le()],Fr.prototype,"isLoadingMessages",void 0),_r([le()],Fr.prototype,"hasReceivedConsent",void 0),_r([le()],Fr.prototype,"websitePreviewMapping",void 0),Fr=_r([ae("pubnub-chat")],Fr);const Mr={};var Dr=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 Ur=class extends re{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.chatId="",this.analytics=null,this.isMobile=Un(),this.launcher=null,this.building=null,this.designConcept=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=Vn.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.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;if(!this.buildingSlug||!this.orgSlug)return;const y=await hi(this.orgSlug,this.buildingSlug);if(1!==y.active)return;const[b,w,S,T,A,x,O]=await Promise.all([vi(this.buildingSlug),cr(this.buildingSlug),yi(this.buildingSlug,document.referrer),Kn(this.buildingSlug),Xn(this.buildingSlug),gi(y.id),Yn(this.buildingSlug)]);y.phoneNumber=Ne(y.phoneNumber),this.building=y,this.designConcept=null!==(e=null==b?void 0:b.abTestType)&&void 0!==e?e:"",this.leadSources=w,this.currentLeadSource=S,this.featureFlagShowDropdown=T;const C=await(async e=>{if(Mr[e])return Mr[e];const n=`https://app.meetelise.com/sms_management_numbers/webchat/building/${e}/numbers`,i=await t().get(n);return Mr[e]=i.data,i.data})(y.id);this.enabledChatWidgets={call:x&&!x.isGlobalDefault?x.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:x&&!x.isGlobalDefault?x.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:x&&!x.isGlobalDefault?x.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:(x&&!x.isGlobalDefault?x.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)&&C.length>0,sst:x&&!x.isGlobalDefault?x.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},x&&x.config&&(this.brandColor=null!==(v=x.config.primaryColor)&&void 0!==v?v:null,this.webchatConfigHasAutoOpenChat=x.config.autoOpenChat,this.requiresConsent=x.config.requiresConsent,x.config.displayStyle===fi.MINIMIZED&&(this.isMinimized=!0),x.config.displayStyle===fi.PILLS&&(this.designConcept=null),x.config.displayStyle===fi.EMOJI&&(this.designConcept=fi.EMOJI)),null===this.brandColor&&(this.brandColor=Fe);let I=null;var N;A&&(I=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)),O&&(null==I?void 0:I.number)&&((e=>{const t=document.querySelectorAll('a[data-selenium-id="click_to_call"]');t&&t.forEach((t=>{"A"===t.tagName&&(t.href=`tel:${Cr(e)}`);const n=t.querySelector(".click-to-call");n&&Or(n)&&(n.textContent=e)}))})(N=I.number),(e=>{const t=document.querySelectorAll(".dvPhone");t&&t.forEach((t=>{var n;"A"===t.tagName&&(t.href=`tel:${Cr(e)}`),Or(t)&&(t.textContent=e);const i=t.nextElementSibling;if("BR"!==(null==i?void 0:i.tagName)||"A"!==(null===(n=null==i?void 0:i.nextElementSibling)||void 0===n?void 0:n.tagName))return;const r=null==i?void 0:i.nextElementSibling;r.href=`sms:${Cr(e)}`,Or(r)&&(r.textContent=`Text: ${e}`)}))})(N),(e=>{const t=document.querySelectorAll(".click_to_call_href");t&&2===t.length&&t.forEach((t=>{"A"===t.tagName&&(t.href=`tel:${Cr(e)}`);const n=t.querySelector(".click_to_call")||t.querySelector(".click_to_call_foot");n&&Or(n)&&(n.textContent=e)}))})(N)),this.phoneNumberForSource=I||{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.initializeChatVariables=async()=>{var n;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!==Tr.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){pi({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ci.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&&!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..."),pi({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ci.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}}))})),!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_${Sr()}_${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=>!(e.buildingSlug!==this.buildingSlug||!e.leadId||!e.timestamp||function(e,t){ke(2,arguments);var n=qe(e),i=qe(t);return n.getTime()<i.getTime()}(xr(e.timestamp,this.ttlHours),Date.now())),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 pi({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:ci.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug});this.leadUserId=e.leadId,this.channel=`webchat_${this.leadUserId}`,e.timestamp&&function(e,t){ke(2,arguments);var n=qe(e),i=qe(t);return n.getTime()>i.getTime()}(e.timestamp,xr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(fr())({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){pi({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ci.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){pi({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ci.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){pi({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ci.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?(pi({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ci.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!==Tr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){pi({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ci.warn,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(null!==(n=this.building.autoOpenChatWidget)&&void 0!==n?n: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&&!an(un(t)));return!!e&&!!n&&!Un()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){ke(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)=>k` <div
|
|
3418
3418
|
id=${e}
|
|
3419
3419
|
class=${fe({showTab:t,hideTab:!t})}
|
|
3420
3420
|
>
|
package/src/MyPubnub.ts
CHANGED