@meetelise/chat 1.20.90 → 1.20.91
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
|
@@ -2889,7 +2889,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
2889
2889
|
#pubnub-chat-container {
|
|
2890
2890
|
position: fixed;
|
|
2891
2891
|
|
|
2892
|
-
z-index:
|
|
2892
|
+
z-index: 100001;
|
|
2893
2893
|
display: flex;
|
|
2894
2894
|
align-items: center;
|
|
2895
2895
|
|
|
@@ -3012,7 +3012,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
3012
3012
|
}
|
|
3013
3013
|
|
|
3014
3014
|
#loading-message {
|
|
3015
|
-
padding:
|
|
3015
|
+
padding: 12px;
|
|
3016
3016
|
}
|
|
3017
3017
|
.loading-dot {
|
|
3018
3018
|
width: 6px;
|
|
@@ -3063,6 +3063,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
3063
3063
|
box-sizing: border-box;
|
|
3064
3064
|
gap: 16px;
|
|
3065
3065
|
padding: 24px;
|
|
3066
|
+
z-index: 100001;
|
|
3066
3067
|
}
|
|
3067
3068
|
#message-input {
|
|
3068
3069
|
height: 40px;
|
|
@@ -3074,6 +3075,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
3074
3075
|
border: none;
|
|
3075
3076
|
color: white;
|
|
3076
3077
|
background: none;
|
|
3078
|
+
z-index: 100001;
|
|
3077
3079
|
}
|
|
3078
3080
|
#message-input:focus {
|
|
3079
3081
|
outline: none;
|
|
@@ -3178,7 +3180,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
3178
3180
|
</div>
|
|
3179
3181
|
</div>
|
|
3180
3182
|
</a></div> `}))}
|
|
3181
|
-
</div>`:B``}};Fr.styles=[Pr],_r([de({attribute:!0})],Fr.prototype,"message",void 0),_r([de({attribute:!0})],Fr.prototype,"myPubnub",void 0),_r([de({attribute:!0})],Fr.prototype,"onMount",void 0),_r([ce()],Fr.prototype,"loadingPreviews",void 0),_r([ce()],Fr.prototype,"parsedMessage",void 0),_r([ce()],Fr.prototype,"websitePreviewInfo",void 0),Fr=_r([ue("pubnub-message")],Fr);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 ae{constructor(){super(...arguments),this.brandColor=mi,this.onClickExit=()=>({}),this.onMount=()=>({}),this.messages=[],this.isMobile=!1,this.isLoadingMessages=!1,this.websitePreviewMapping={},this.sendMessage=async e=>{var t;this.messageInput.value="",await(null===(t=this.myPubnub)||void 0===t?void 0:t.sendMessage(e))},this.scrollToChatBottom=()=>{this.messageBody.scrollTo({top:this.messageBody.scrollHeight-this.messageBody.clientHeight,behavior:"smooth"})}}firstUpdated(){var e,t;this.messages=(null===(e=this.myPubnub)||void 0===e?void 0:e.messages)||[],null===(t=this.myPubnub)||void 0===t||t.addChatListener((e=>{this.messages=e.messages,this.isLoadingMessages=e.isLoading})),this.onMount()
|
|
3183
|
+
</div>`:B``}};Fr.styles=[Pr],_r([de({attribute:!0})],Fr.prototype,"message",void 0),_r([de({attribute:!0})],Fr.prototype,"myPubnub",void 0),_r([de({attribute:!0})],Fr.prototype,"onMount",void 0),_r([ce()],Fr.prototype,"loadingPreviews",void 0),_r([ce()],Fr.prototype,"parsedMessage",void 0),_r([ce()],Fr.prototype,"websitePreviewInfo",void 0),Fr=_r([ue("pubnub-message")],Fr);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 ae{constructor(){super(...arguments),this.brandColor=mi,this.onClickExit=()=>({}),this.onMount=()=>({}),this.messages=[],this.isMobile=!1,this.isLoadingMessages=!1,this.websitePreviewMapping={},this.sendMessage=async e=>{var t;this.messageInput.value="",await(null===(t=this.myPubnub)||void 0===t?void 0:t.sendMessage(e))},this.scrollToChatBottom=()=>{this.messageBody.scrollTo({top:this.messageBody.scrollHeight-this.messageBody.clientHeight,behavior:"smooth"})}}firstUpdated(){var e,t;this.messages=(null===(e=this.myPubnub)||void 0===e?void 0:e.messages)||[],null===(t=this.myPubnub)||void 0===t||t.addChatListener((e=>{this.messages=e.messages,this.isLoadingMessages=e.isLoading})),this.onMount()}async updated(){this.scrollToChatBottom()}render(){return this.buildingSlug&&this.building?B`
|
|
3182
3184
|
<div
|
|
3183
3185
|
id="pubnub-chat-container"
|
|
3184
3186
|
class=${ge({"pubnub-container__mobile":this.isMobile,"pubnub-container__desktop":!this.isMobile})}
|
|
@@ -3247,7 +3249,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
3247
3249
|
</button>
|
|
3248
3250
|
</div>
|
|
3249
3251
|
</div>
|
|
3250
|
-
`:B``}};Dr.styles=[Pr],Mr([de({attribute:!0})],Dr.prototype,"channel",void 0),Mr([de({attribute:!0})],Dr.prototype,"myPubnub",void 0),Mr([de({attribute:!0})],Dr.prototype,"buildingSlug",void 0),Mr([de({attribute:!0})],Dr.prototype,"building",void 0),Mr([de({attribute:!0})],Dr.prototype,"brandColor",void 0),Mr([de({attribute:!0})],Dr.prototype,"onClickExit",void 0),Mr([de({attribute:!0})],Dr.prototype,"onMount",void 0),Mr([pe("#message-input",!0)],Dr.prototype,"messageInput",void 0),Mr([pe("#conversation-body",!0)],Dr.prototype,"messageBody",void 0),Mr([ce()],Dr.prototype,"messages",void 0),Mr([ce()],Dr.prototype,"isMobile",void 0),Mr([ce()],Dr.prototype,"isLoadingMessages",void 0),Mr([ce()],Dr.prototype,"websitePreviewMapping",void 0),Dr=Mr([ue("pubnub-chat")],Dr);var kr,Ur,qr=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"}(Ur||(Ur={}));let Br=kr=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=bi({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=Ur.TALKJS,this.displayPubnubChat=!1,this.myPubnub=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{kr.session=Ee.ready.then((()=>{const e=new Ee.User({id:"anonymous-"+ui(this.orgSlug,this.buildingSlug),name:"Me",email:null,role:"Default"});return new Ee.Session({appId:"ogKIvCor",me:e})})),await this.setBuildingDerivedInfo(),await this.initializeLaunchJS()&&(this.attachOnClickToLauncher(),this.isLoading=!1)},this.setBuildingDerivedInfo=async()=>{var e,n,i;if(!this.buildingSlug||!this.orgSlug)return;const[r,o,a,s,u,l,d]=await Promise.all([Si(this.orgSlug,this.buildingSlug),Oi(this.buildingSlug),xr(this.buildingSlug),Ci(this.buildingSlug,document.referrer),Bn(this.buildingSlug),Ln(this.buildingSlug),xi(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===Ti.MINIMIZED&&(this.isMobile=!0),d.designConcept===Ti.PILLS&&(this.buildingABTestType=null),d.designConcept===Ti.EMOJI&&(this.buildingABTestType=Ai.ConceptEmoji))),null===this.brandColor&&(this.brandColor=mi);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=ui(this.orgSlug,this.buildingSlug),this.avatarSrc=this.avatarSrc||this.building.avatarSrc,this.theme=bi({themeId:null!==(i=this.themeId)&&void 0!==i?i:this.building.themeId,brandColor:this.brandColor}),this.analytics=new Zn(this.orgSlug,this.buildingSlug,this.chatId,this.currentLeadSource),this.analytics.ping("webchat_heartbeat")},this.initializeLaunchJS=async()=>{var e;if(!this.building||!this.theme)return;if(this.popup&&this.launcher)return;const[t,n,i,r]=await Promise.all([this.building,this.theme,this.avatarSrc,kr.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(wi(n,e,t,i||e.avatarSrc,this.chatId,this.isMobile),{launcher:"never",showCloseInHeader:!0,messageField:{placeholder:"Ask a question..."}});await o.mount({show:!1}),o.on("close",(()=>{this.hideLauncher=!1}));const a=document.querySelector(".__talkjs_popup");if(this.talkjsPopupElement=a,!a)throw new Error("Failed to find chat window");a.classList.add("meetelise-chat","pane"),this.isMobile||a.classList.add("launcher__desktop"),a.style.zIndex="99999999999",this.popup=o,this.shouldAutoOpenChat(e.autoOpenChatWidget)&&(this.popup.show(),this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp(),null===(r=this.analytics)||void 0===r||r.ping("autoOpen"))},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!an(un(t)));return!!e&&!!n&&!r()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.firstUpdated=async()=>{await async function(e){try{return(await t().get(Un(e),{params:{building_slug:e,flag_type:"bool",feature_flag:"use-pubnub-chat-provider",default_str:null,default_bool:!1}})).data}catch(e){return!1}}(this.buildingSlug)?(this.chatProvider=Ur.PUBNUB,this.initializePubnubVariables()):this.initializeInstanceVariables()},this.initializePubnubVariables=async()=>{await this.setBuildingDerivedInfo(),this.building&&(this.myPubnub=new class{constructor(e,t){this.apiHost="https://app.meetelise.com",this.building=null,this.ttlHours=24,this.pubnub=null,this.leadUserId="",this.channel="",this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;this.messages=[...this.messages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}];const n="eliseai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.messages,isLoading:n}),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{this.pubnub&&this.channel&&(this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams))},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&&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_${si()}_${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=()=>{const e=localStorage.getItem("com.eliseai.webchat.slug="+this.buildingSlug);if(e)try{const t=JSON.parse(e),n=t.buildingSlug,i=t.leadId,r=new Date(t.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 this.createChatStorageKey()},this.isChatKeyValid=e=>{if(e.buildingSlug!==this.buildingSlug||!e.leadId||!e.timestamp)return!1;const t=Nr(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}addChatListener(e){this.chatListener=e}async initializePubnub(){const e=this.getChatStorageKey();if(!e.leadId)return void console.error("Error getting chat storage key...");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,Nr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return this.pubnub=new(Cr())({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}async fetchToken(e,n){return(await t().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${n}`)).data}async fetchChannelExists(e){return(await t().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}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){}}}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?t(n):e(i)}))}));if(this.channel&&0!==Object.keys(t.channels).length){const n=t.channels[this.channel],i=[];n.forEach((e=>{e.uuid&&i.push({channel:e.channel,message:e.message,publisher:e.uuid,subscription:e.channel,timetoken:+e.timetoken})})),this.messages=i,null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){}}}(this.buildingSlug,this.building),this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey())&&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===Ur.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Ur.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.chatProvider===Ur.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Ur.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e)},this.handleContactTabClicked=e=>{var t,n;this.chatProvider===Ur.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Ur.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickPhoneOption(e)},this.adjustTopHeaderContactCoords=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById(this.chatProvider===Ur.TALKJS?"chatAdditionalActionsTalkjs":"chatAdditionalActionsPubnub");if(r)if(this.chatProvider===Ur.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===Ur.PUBNUB){const e=null===(i=null===(n=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("pubnub-chat"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.getElementById("pubnub-chat-container"),o=null==e?void 0:e.getBoundingClientRect();if(!o)return;r.style.left=`${o.left}px`,r.style.top=`${o.bottom}px`}},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized},this.renderChatAdditionalActions=(e,t)=>{var n,i,r,o,a,s,u,l;return B` <div
|
|
3252
|
+
`:B``}};Dr.styles=[Pr],Mr([de({attribute:!0})],Dr.prototype,"channel",void 0),Mr([de({attribute:!0})],Dr.prototype,"myPubnub",void 0),Mr([de({attribute:!0})],Dr.prototype,"buildingSlug",void 0),Mr([de({attribute:!0})],Dr.prototype,"building",void 0),Mr([de({attribute:!0})],Dr.prototype,"brandColor",void 0),Mr([de({attribute:!0})],Dr.prototype,"onClickExit",void 0),Mr([de({attribute:!0})],Dr.prototype,"onMount",void 0),Mr([pe("#message-input",!0)],Dr.prototype,"messageInput",void 0),Mr([pe("#conversation-body",!0)],Dr.prototype,"messageBody",void 0),Mr([ce()],Dr.prototype,"messages",void 0),Mr([ce()],Dr.prototype,"isMobile",void 0),Mr([ce()],Dr.prototype,"isLoadingMessages",void 0),Mr([ce()],Dr.prototype,"websitePreviewMapping",void 0),Dr=Mr([ue("pubnub-chat")],Dr);var kr,Ur,qr=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"}(Ur||(Ur={}));let Br=kr=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=bi({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=Ur.TALKJS,this.displayPubnubChat=!1,this.myPubnub=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{kr.session=Ee.ready.then((()=>{const e=new Ee.User({id:"anonymous-"+ui(this.orgSlug,this.buildingSlug),name:"Me",email:null,role:"Default"});return new Ee.Session({appId:"ogKIvCor",me:e})})),await this.setBuildingDerivedInfo(),await this.initializeLaunchJS()&&(this.attachOnClickToLauncher(),this.isLoading=!1)},this.setBuildingDerivedInfo=async()=>{var e,n,i;if(!this.buildingSlug||!this.orgSlug)return;const[r,o,a,s,u,l,d]=await Promise.all([Si(this.orgSlug,this.buildingSlug),Oi(this.buildingSlug),xr(this.buildingSlug),Ci(this.buildingSlug,document.referrer),Bn(this.buildingSlug),Ln(this.buildingSlug),xi(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===Ti.MINIMIZED&&(this.isMobile=!0),d.designConcept===Ti.PILLS&&(this.buildingABTestType=null),d.designConcept===Ti.EMOJI&&(this.buildingABTestType=Ai.ConceptEmoji))),null===this.brandColor&&(this.brandColor=mi);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=ui(this.orgSlug,this.buildingSlug),this.avatarSrc=this.avatarSrc||this.building.avatarSrc,this.theme=bi({themeId:null!==(i=this.themeId)&&void 0!==i?i:this.building.themeId,brandColor:this.brandColor}),this.analytics=new Zn(this.orgSlug,this.buildingSlug,this.chatId,this.currentLeadSource),this.analytics.ping("webchat_heartbeat")},this.initializeLaunchJS=async()=>{var e;if(!this.building||!this.theme)return;if(this.popup&&this.launcher)return;const[t,n,i,r]=await Promise.all([this.building,this.theme,this.avatarSrc,kr.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(wi(n,e,t,i||e.avatarSrc,this.chatId,this.isMobile),{launcher:"never",showCloseInHeader:!0,messageField:{placeholder:"Ask a question..."}});await o.mount({show:!1}),o.on("close",(()=>{this.hideLauncher=!1}));const a=document.querySelector(".__talkjs_popup");if(this.talkjsPopupElement=a,!a)throw new Error("Failed to find chat window");a.classList.add("meetelise-chat","pane"),this.isMobile||a.classList.add("launcher__desktop"),a.style.zIndex="99999999999",this.popup=o,this.shouldAutoOpenChat(e.autoOpenChatWidget)&&(this.popup.show(),this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp(),null===(r=this.analytics)||void 0===r||r.ping("autoOpen"))},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!an(un(t)));return!!e&&!!n&&!r()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.firstUpdated=async()=>{await async function(e){try{return(await t().get(Un(e),{params:{building_slug:e,flag_type:"bool",feature_flag:"use-pubnub-chat-provider",default_str:null,default_bool:!1}})).data}catch(e){return!1}}(this.buildingSlug)?(this.chatProvider=Ur.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){this.apiHost="https://app.meetelise.com",this.building=null,this.ttlHours=24,this.pubnub=null,this.leadUserId="",this.channel="",this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;this.messages=[...this.messages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}];const n="eliseai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.messages,isLoading:n}),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{this.pubnub&&this.channel&&(this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams))},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&&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_${si()}_${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=Nr(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}addChatListener(e){this.chatListener=e}async initializePubnub(){const e=this.getChatStorageKey();if(!e.leadId)return void console.error("Error getting chat storage key...");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,Nr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return this.pubnub=new(Cr())({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}async fetchToken(e,n){return(await t().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${n}`)).data}async fetchChannelExists(e){return(await t().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}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){}}}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?t(n):e(i)}))}));if(this.channel&&0!==Object.keys(t.channels).length){const n=t.channels[this.channel],i=[];n.forEach((e=>{e.uuid&&i.push({channel:e.channel,message:e.message,publisher:e.uuid,subscription:e.channel,timetoken:+e.timetoken})})),this.messages=i,null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){}}}(this.buildingSlug,this.building),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===Ur.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Ur.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.chatProvider===Ur.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Ur.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e)},this.handleContactTabClicked=e=>{var t,n;this.chatProvider===Ur.TALKJS?null===(t=this.popup)||void 0===t||t.hide():this.chatProvider===Ur.PUBNUB&&(this.displayPubnubChat=!1),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickPhoneOption(e)},this.adjustTopHeaderContactCoords=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById(this.chatProvider===Ur.TALKJS?"chatAdditionalActionsTalkjs":"chatAdditionalActionsPubnub");if(r)if(this.chatProvider===Ur.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===Ur.PUBNUB){const e=null===(i=null===(n=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("pubnub-chat"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.getElementById("pubnub-chat-container"),o=null==e?void 0:e.getBoundingClientRect();if(!o)return;r.style.left=`${o.left}px`,r.style.top=`${o.bottom}px`}},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized},this.renderChatAdditionalActions=(e,t)=>{var n,i,r,o,a,s,u,l;return B` <div
|
|
3251
3253
|
id=${e}
|
|
3252
3254
|
class=${ge({showTab:t,hideTab:!t})}
|
|
3253
3255
|
>
|
package/src/MyPubnub.ts
CHANGED
|
@@ -269,7 +269,7 @@ class MyPubnub {
|
|
|
269
269
|
buildingSlug: this.buildingSlug,
|
|
270
270
|
};
|
|
271
271
|
};
|
|
272
|
-
getChatStorageKey = (): ChatInfo => {
|
|
272
|
+
getChatStorageKey = (createNewIfNotExist = true): ChatInfo => {
|
|
273
273
|
const eliseaiLocalStorageValue = localStorage.getItem(
|
|
274
274
|
"com.eliseai.webchat.slug=" + this.buildingSlug
|
|
275
275
|
);
|
|
@@ -300,7 +300,12 @@ class MyPubnub {
|
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
return this.createChatStorageKey();
|
|
303
|
+
if (createNewIfNotExist) return this.createChatStorageKey();
|
|
304
|
+
return {
|
|
305
|
+
leadId: null,
|
|
306
|
+
timestamp: null,
|
|
307
|
+
buildingSlug: null,
|
|
308
|
+
};
|
|
304
309
|
};
|
|
305
310
|
isChatKeyValid = (storageValueDeconstructed: ChatInfo): boolean => {
|
|
306
311
|
if (
|
|
@@ -484,9 +484,16 @@ export class MEChat extends LitElement {
|
|
|
484
484
|
initializePubnubVariables = async (): Promise<void> => {
|
|
485
485
|
await this.setBuildingDerivedInfo();
|
|
486
486
|
if (!this.building) return;
|
|
487
|
+
if (this.building.conversationMaintenanceMode) {
|
|
488
|
+
// eslint-disable-next-line no-console
|
|
489
|
+
console.warn(
|
|
490
|
+
"MeetElise Chat is in maintenance mode. Chat icon will not appear."
|
|
491
|
+
);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
487
494
|
|
|
488
495
|
this.myPubnub = new MyPubnub(this.buildingSlug, this.building);
|
|
489
|
-
if (this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey())) {
|
|
496
|
+
if (this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey(false))) {
|
|
490
497
|
await this.myPubnub.initializePubnub();
|
|
491
498
|
}
|
|
492
499
|
this.attachOnClickToLauncher();
|
|
@@ -4,7 +4,7 @@ export const pubnubChatStyles = css`
|
|
|
4
4
|
#pubnub-chat-container {
|
|
5
5
|
position: fixed;
|
|
6
6
|
|
|
7
|
-
z-index:
|
|
7
|
+
z-index: 100001;
|
|
8
8
|
display: flex;
|
|
9
9
|
align-items: center;
|
|
10
10
|
|
|
@@ -127,7 +127,7 @@ export const pubnubChatStyles = css`
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
#loading-message {
|
|
130
|
-
padding:
|
|
130
|
+
padding: 12px;
|
|
131
131
|
}
|
|
132
132
|
.loading-dot {
|
|
133
133
|
width: 6px;
|
|
@@ -178,6 +178,7 @@ export const pubnubChatStyles = css`
|
|
|
178
178
|
box-sizing: border-box;
|
|
179
179
|
gap: 16px;
|
|
180
180
|
padding: 24px;
|
|
181
|
+
z-index: 100001;
|
|
181
182
|
}
|
|
182
183
|
#message-input {
|
|
183
184
|
height: 40px;
|
|
@@ -189,6 +190,7 @@ export const pubnubChatStyles = css`
|
|
|
189
190
|
border: none;
|
|
190
191
|
color: white;
|
|
191
192
|
background: none;
|
|
193
|
+
z-index: 100001;
|
|
192
194
|
}
|
|
193
195
|
#message-input:focus {
|
|
194
196
|
outline: none;
|
|
@@ -74,11 +74,6 @@ export class PubnubChat extends LitElement {
|
|
|
74
74
|
}
|
|
75
75
|
);
|
|
76
76
|
this.onMount();
|
|
77
|
-
// TODO (erol): scroll to bottom on all children load
|
|
78
|
-
// this is a hacky way to do it
|
|
79
|
-
setTimeout(() => {
|
|
80
|
-
this.scrollToChatBottom();
|
|
81
|
-
}, 1000);
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
scrollToChatBottom = (): void => {
|