@meetelise/chat 1.20.210 → 1.20.211
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 +2 -1
- package/public/dist/index.js +15 -15
- package/src/MyPubnub.ts +156 -53
- package/src/WebComponent/pubnub-chat.ts +9 -9
- package/src/WebComponent/pubnub-message.ts +10 -10
package/package.json
CHANGED
package/public/demo/index.html
CHANGED
|
@@ -132,7 +132,8 @@
|
|
|
132
132
|
|
|
133
133
|
MEChat.start({
|
|
134
134
|
organization: "test-company",
|
|
135
|
-
building: "
|
|
135
|
+
building: "test-yardi-building",
|
|
136
|
+
// building: "3fc93384-91f5-11ed-98a3-43f5a2f42588",
|
|
136
137
|
onWidgetLoaded: onWidgetLoaded,
|
|
137
138
|
// organization: "00f18938-9632-40b9-8d7f-f30e219c94fc",
|
|
138
139
|
// building: "19e21cda-d05b-11ee-b3bd-cf9cc1ace7e5",
|
package/public/dist/index.js
CHANGED
|
@@ -2999,7 +2999,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
2999
2999
|
${bi}
|
|
3000
3000
|
${wi}
|
|
3001
3001
|
${Si}
|
|
3002
|
-
`,Zi([ue({attribute:!0})],$i.prototype,"isMinimized",void 0),Zi([ue()],$i.prototype,"mobileStyles",void 0),Zi([ue({type:Boolean})],$i.prototype,"isFirstMount",void 0),Zi([ue({attribute:!1})],$i.prototype,"autoOpenChatWidget",void 0),Zi([ue()],$i.prototype,"phoneNumber",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingName",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatId",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatCallUsHeader",void 0),Zi([ue({attribute:!1})],$i.prototype,"buildingId",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"orgSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"sgtUrl",void 0),Zi([ue({attribute:!0})],$i.prototype,"designConcept",void 0),Zi([ue({attribute:!0})],$i.prototype,"featureFlagShowDropdown",void 0),Zi([ue({attribute:!1})],$i.prototype,"leadSources",void 0),Zi([ue({attribute:!0})],$i.prototype,"currentLeadSource",void 0),Zi([ue({attribute:!0})],$i.prototype,"escortedToursLink",void 0),Zi([ue({attribute:!0})],$i.prototype,"virtualToursLink",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasCallUsEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasChatEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasEmailEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasSSTEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasTextUsEnabled",void 0),Zi([ue({attribute:!1})],$i.prototype,"layoutOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"unitOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"tourTypeOptions",void 0),Zi([ue({attribute:!0})],$i.prototype,"hasDynamicSchedulingEnabled",void 0),Zi([ue({attribute:!0})],$i.prototype,"onExitChat",void 0),Zi([ue({type:Number})],$i.prototype,"right",void 0),Zi([ue({type:Number})],$i.prototype,"bottom",void 0),Zi([ue({type:Number})],$i.prototype,"top",void 0),Zi([ue({type:Number})],$i.prototype,"left",void 0),Zi([ue({attribute:!0})],$i.prototype,"showTourNextToChat",void 0),Zi([ue({attribute:!1})],$i.prototype,"onChatTapped",void 0),Zi([ue({attribute:!0})],$i.prototype,"onClickMinimize",void 0),Zi([ue({attribute:!1})],$i.prototype,"launcherStyles",void 0),Zi([ue({attribute:!0})],$i.prototype,"brandColor",void 0),Zi([le()],$i.prototype,"isEmailWindowOpen",void 0),Zi([le()],$i.prototype,"isCallUsWindowOpen",void 0),Zi([le()],$i.prototype,"isSSTWindowOpen",void 0),Zi([le()],$i.prototype,"isTextUsWindowOpen",void 0),$i=Zi([ae("meetelise-launcher")],$i);const er=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",$i)};var tr=n(3379),nr=n.n(tr),ir=n(7795),rr=n.n(ir),or=n(569),ar=n.n(or),sr=n(3565),ur=n.n(sr),lr=n(9216),dr=n.n(lr),cr=n(4589),pr=n.n(cr),hr=n(3631),fr={};async function mr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?gr(n.data,e):[]}catch(e){return[]}}fr.styleTagTransform=pr(),fr.setAttributes=ur(),fr.insert=ar().bind(null,"head"),fr.domAPI=rr(),fr.insertStyleElement=dr(),nr()(hr.Z,fr),hr.Z&&hr.Z.locals&&hr.Z.locals;const gr=(e,t)=>{let n=[];switch(t){case"d41619ec-0f79-11ee-8439-93855926ad58":n=["Forthea - PPC","HotPads","Forthea","Locator","Website-apartmentguide.com","Forthea - organic search","Tdc employee","University newspaper","Nashville apartment locators","Forthea - paid social","Apartment list","Off campus partners","Waze ads","Athletic event","Website-apartment guide"];break;case"d4160560-0f79-11ee-8438-fba837bf3a46":n=["Forthea - PPC","Rentgrata","Website-ApartmentFinder.com","Word of Mouth","Texas A&M A-Frame on Campus","Rent.com","Website-craigslist","Apartment List","Website-apartments.com","Forthea - paid social","Forthea - organic search","Website-apartmentguide.com","Forthea","Uhomes","Phone book","Property - website"];break;default:n=[]}return e.sort(),e.filter((e=>{const t=e.toLowerCase();return!n.map((e=>e.toLowerCase())).includes(t)}))};var vr,yr=n(9594),br=n.n(yr),wr=new Uint8Array(16);function Sr(){if(!vr&&!(vr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return vr(wr)}const Tr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,xr=function(e){return"string"==typeof e&&Tr.test(e)};for(var Ar=[],Or=0;Or<256;++Or)Ar.push((Or+256).toString(16).substr(1));const Cr=function(e,t,n){var i=(e=e||{}).random||(e.rng||Sr)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(var r=0;r<16;++r)t[n+r]=i[r];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Ar[e[t+0]]+Ar[e[t+1]]+Ar[e[t+2]]+Ar[e[t+3]]+"-"+Ar[e[t+4]]+Ar[e[t+5]]+"-"+Ar[e[t+6]]+Ar[e[t+7]]+"-"+Ar[e[t+8]]+Ar[e[t+9]]+"-"+Ar[e[t+10]]+Ar[e[t+11]]+Ar[e[t+12]]+Ar[e[t+13]]+Ar[e[t+14]]+Ar[e[t+15]]).toLowerCase();if(!xr(n))throw TypeError("Stringified UUID is invalid");return n}(i)},Ir=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Nr=(e,t,n)=>{const i=mn(new Date),r=n||`lead_${Cr()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:Tn(i),buildingSlug:e,initiatedChat:t}},Er=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(Rr(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Rr=(e,t)=>!(t.buildingSlug!==e||!t.leadId||!t.timestamp||dn(t.timestamp,24));var _r;!function(e){e.noReply="no-reply",e.text="text"}(_r||(_r={}));const Pr=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!==_r.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&&"elise_health_ai"!==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){this.building&&si({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ai.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=Nr(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..."),this.building&&si({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),9e4),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(br())({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}&${this.building?"":"industry=health_care"}`)).data}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ai.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){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ai.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){this.building&&si({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ai.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?(this.building&&si({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ai.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!==_r.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){this.building&&si({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ai.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}},Fr=(e,t,n)=>{const i=`tel:${e}`,r=`sms:${e}`,o=`whatsapp://send?phone=${e}}`,a=`facetime:${e}`,s=`facetime-audio:${e}`,u=/\(\d{3}\)\s\d{3}-\d{4}/g,l=/(tel|sms):\(\d{3}\)\s\d{3}-\d{4}/g,d=/whatsapp:\/\/send\?phone=\d+/g,c=/(facetime|facetime-audio):\d+/g,p=document.body.getElementsByTagName("*");let h=!1;const f=e.replace(/(\d{3})(\d{3})(\d{4})/,"($1) $2-$3");for(let e=0;e<p.length;e++)if(p[e].nodeType===Node.ELEMENT_NODE&&(1===p[e].childNodes.length&&p[e].childNodes[0].nodeType==Node.TEXT_NODE&&(p[e].innerHTML=p[e].innerHTML.replace(u,f),h=!0,si({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"text-insertion",originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ai.info,buildingSlug:n,orgSlug:t})),p[e].hasAttribute("href"))){const u=p[e].getAttribute("href");if(!u)continue;let h="",m=l;u.startsWith("sms:")?h=r:u.startsWith("whatsapp:")?(h=o,m=d):u.startsWith("facetime:")?(h=a,m=c):u.startsWith("facetime-audio:")?(h=s,m=c):h=i;const g=u.replace(m,h);p[e].setAttribute("href",g),si({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"href-insertion",hrefAttribute:u,originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ai.info,buildingSlug:n,orgSlug:t})}h||si({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"no-phone-number-found",website:window.location.href},logType:ai.warn,buildingSlug:n,orgSlug:t})};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.onClick=()=>{},this.brandColor=Fe,this.toExpand=!1}render(){return U`
|
|
3002
|
+
`,Zi([ue({attribute:!0})],$i.prototype,"isMinimized",void 0),Zi([ue()],$i.prototype,"mobileStyles",void 0),Zi([ue({type:Boolean})],$i.prototype,"isFirstMount",void 0),Zi([ue({attribute:!1})],$i.prototype,"autoOpenChatWidget",void 0),Zi([ue()],$i.prototype,"phoneNumber",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingName",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatId",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatCallUsHeader",void 0),Zi([ue({attribute:!1})],$i.prototype,"buildingId",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"orgSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"sgtUrl",void 0),Zi([ue({attribute:!0})],$i.prototype,"designConcept",void 0),Zi([ue({attribute:!0})],$i.prototype,"featureFlagShowDropdown",void 0),Zi([ue({attribute:!1})],$i.prototype,"leadSources",void 0),Zi([ue({attribute:!0})],$i.prototype,"currentLeadSource",void 0),Zi([ue({attribute:!0})],$i.prototype,"escortedToursLink",void 0),Zi([ue({attribute:!0})],$i.prototype,"virtualToursLink",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasCallUsEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasChatEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasEmailEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasSSTEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasTextUsEnabled",void 0),Zi([ue({attribute:!1})],$i.prototype,"layoutOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"unitOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"tourTypeOptions",void 0),Zi([ue({attribute:!0})],$i.prototype,"hasDynamicSchedulingEnabled",void 0),Zi([ue({attribute:!0})],$i.prototype,"onExitChat",void 0),Zi([ue({type:Number})],$i.prototype,"right",void 0),Zi([ue({type:Number})],$i.prototype,"bottom",void 0),Zi([ue({type:Number})],$i.prototype,"top",void 0),Zi([ue({type:Number})],$i.prototype,"left",void 0),Zi([ue({attribute:!0})],$i.prototype,"showTourNextToChat",void 0),Zi([ue({attribute:!1})],$i.prototype,"onChatTapped",void 0),Zi([ue({attribute:!0})],$i.prototype,"onClickMinimize",void 0),Zi([ue({attribute:!1})],$i.prototype,"launcherStyles",void 0),Zi([ue({attribute:!0})],$i.prototype,"brandColor",void 0),Zi([le()],$i.prototype,"isEmailWindowOpen",void 0),Zi([le()],$i.prototype,"isCallUsWindowOpen",void 0),Zi([le()],$i.prototype,"isSSTWindowOpen",void 0),Zi([le()],$i.prototype,"isTextUsWindowOpen",void 0),$i=Zi([ae("meetelise-launcher")],$i);const er=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",$i)};var tr=n(3379),nr=n.n(tr),ir=n(7795),rr=n.n(ir),or=n(569),ar=n.n(or),sr=n(3565),ur=n.n(sr),lr=n(9216),dr=n.n(lr),cr=n(4589),pr=n.n(cr),hr=n(3631),fr={};async function mr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?gr(n.data,e):[]}catch(e){return[]}}fr.styleTagTransform=pr(),fr.setAttributes=ur(),fr.insert=ar().bind(null,"head"),fr.domAPI=rr(),fr.insertStyleElement=dr(),nr()(hr.Z,fr),hr.Z&&hr.Z.locals&&hr.Z.locals;const gr=(e,t)=>{let n=[];switch(t){case"d41619ec-0f79-11ee-8439-93855926ad58":n=["Forthea - PPC","HotPads","Forthea","Locator","Website-apartmentguide.com","Forthea - organic search","Tdc employee","University newspaper","Nashville apartment locators","Forthea - paid social","Apartment list","Off campus partners","Waze ads","Athletic event","Website-apartment guide"];break;case"d4160560-0f79-11ee-8438-fba837bf3a46":n=["Forthea - PPC","Rentgrata","Website-ApartmentFinder.com","Word of Mouth","Texas A&M A-Frame on Campus","Rent.com","Website-craigslist","Apartment List","Website-apartments.com","Forthea - paid social","Forthea - organic search","Website-apartmentguide.com","Forthea","Uhomes","Phone book","Property - website"];break;default:n=[]}return e.sort(),e.filter((e=>{const t=e.toLowerCase();return!n.map((e=>e.toLowerCase())).includes(t)}))};var vr,yr=n(9594),br=n.n(yr),wr=new Uint8Array(16);function Sr(){if(!vr&&!(vr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return vr(wr)}const Tr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,xr=function(e){return"string"==typeof e&&Tr.test(e)};for(var Ar=[],Or=0;Or<256;++Or)Ar.push((Or+256).toString(16).substr(1));const Cr=function(e,t,n){var i=(e=e||{}).random||(e.rng||Sr)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(var r=0;r<16;++r)t[n+r]=i[r];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Ar[e[t+0]]+Ar[e[t+1]]+Ar[e[t+2]]+Ar[e[t+3]]+"-"+Ar[e[t+4]]+Ar[e[t+5]]+"-"+Ar[e[t+6]]+Ar[e[t+7]]+"-"+Ar[e[t+8]]+Ar[e[t+9]]+"-"+Ar[e[t+10]]+Ar[e[t+11]]+Ar[e[t+12]]+Ar[e[t+13]]+Ar[e[t+14]]+Ar[e[t+15]]).toLowerCase();if(!xr(n))throw TypeError("Stringified UUID is invalid");return n}(i)},Ir=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Nr=(e,t,n)=>{const i=mn(new Date),r=n||`lead_${Cr()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:Tn(i),buildingSlug:e,initiatedChat:t}},Er=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(Rr(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Rr=(e,t)=>!(t.buildingSlug!==e||!t.leadId||!t.timestamp||dn(t.timestamp,24));var _r;!function(e){e.noReply="no-reply",e.text="text"}(_r||(_r={}));const Pr=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.rawPubnubMessages=[],this.simpleChatMessages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==_r.noReply&&(this.rawPubnubMessages=[...this.rawPubnubMessages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}],this.simpleChatMessages=this.translatePubnubMessagesIntoSimpleChatMessages(this.rawPubnubMessages));const n="eliseai"!==e.publisher&&"elise_health_ai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.simpleChatMessages,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){this.building&&si({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ai.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=Nr(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..."),this.building&&si({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),9e4),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.translatePubnubMessagesIntoSimpleChatMessages=e=>{const t=[],n={};return e.forEach((e=>{e.message.stream_id?n[e.message.stream_id]?n[e.message.stream_id].push(e):n[e.message.stream_id]=[e]:t.push({timestamp:e.timetoken,message:e.message.text,isLeadMessage:this.isLeadMessage(e),chunks:[{text:e.message.text,order:0,isDone:!0}]})})),Object.keys(n).forEach((e=>{const i=n[e].sort(((e,t)=>{var n,i;return(null!==(n=e.message.order)&&void 0!==n?n:0)-(null!==(i=t.message.order)&&void 0!==i?i:0)})),r=i.map((e=>e.message.text)).join(""),o=i[0],a={timestamp:o.timetoken,message:r,isLeadMessage:this.isLeadMessage(o),chunks:i.map((e=>{var t,n;return{text:e.message.text,order:null!==(t=e.message.order)&&void 0!==t?t:0,isDone:null!==(n=e.message.is_done)&&void 0!==n&&n}}))};t.push(a)})),t.sort(((e,t)=>e.timestamp-t.timestamp)),t},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(br())({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}&${this.building?"":"industry=health_care"}`)).data}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ai.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){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ai.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){this.building&&si({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}async getChannelHistory(e=1e3){var t;try{let n=[],i=null;const r=100;for(let t=0;t<e;t+=r){const o=await new Promise(((n,o)=>{if(!this.pubnub||!this.channel)return[];const a=Math.min(r,e-t);this.pubnub.fetchMessages({channels:[this.channel],count:a,end:null!=i?i:void 0},((e,t)=>{e.error?o(e):n(t)}))})),a=o.channels[this.channel];if(!a||0===a.length)break;if(this.channel&&0!==Object.keys(o.channels).length){const e=o.channels[this.channel],t=[];e.forEach((e=>{e.uuid&&t.push({channel:e.channel,message:e.message,publisher:e.uuid,subscription:e.channel,timetoken:+e.timetoken})})),n=n.concat(t.filter((e=>e.message.messageType!==_r.noReply)))}if(i=a[a.length-1].timetoken,n.length>=e||a.length<r)break}this.rawPubnubMessages=n.slice(0,e),this.simpleChatMessages=this.translatePubnubMessagesIntoSimpleChatMessages(this.rawPubnubMessages),null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.simpleChatMessages,isLoading:!1})}catch(e){this.building&&si({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ai.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}},Fr=(e,t,n)=>{const i=`tel:${e}`,r=`sms:${e}`,o=`whatsapp://send?phone=${e}}`,a=`facetime:${e}`,s=`facetime-audio:${e}`,u=/\(\d{3}\)\s\d{3}-\d{4}/g,l=/(tel|sms):\(\d{3}\)\s\d{3}-\d{4}/g,d=/whatsapp:\/\/send\?phone=\d+/g,c=/(facetime|facetime-audio):\d+/g,p=document.body.getElementsByTagName("*");let h=!1;const f=e.replace(/(\d{3})(\d{3})(\d{4})/,"($1) $2-$3");for(let e=0;e<p.length;e++)if(p[e].nodeType===Node.ELEMENT_NODE&&(1===p[e].childNodes.length&&p[e].childNodes[0].nodeType==Node.TEXT_NODE&&(p[e].innerHTML=p[e].innerHTML.replace(u,f),h=!0,si({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"text-insertion",originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ai.info,buildingSlug:n,orgSlug:t})),p[e].hasAttribute("href"))){const u=p[e].getAttribute("href");if(!u)continue;let h="",m=l;u.startsWith("sms:")?h=r:u.startsWith("whatsapp:")?(h=o,m=d):u.startsWith("facetime:")?(h=a,m=c):u.startsWith("facetime-audio:")?(h=s,m=c):h=i;const g=u.replace(m,h);p[e].setAttribute("href",g),si({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"href-insertion",hrefAttribute:u,originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ai.info,buildingSlug:n,orgSlug:t})}h||si({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"no-phone-number-found",website:window.location.href},logType:ai.warn,buildingSlug:n,orgSlug:t})};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.onClick=()=>{},this.brandColor=Fe,this.toExpand=!1}render(){return U`
|
|
3003
3003
|
<div
|
|
3004
3004
|
class=${this.toExpand?"button-container mini":"button-container"}
|
|
3005
3005
|
@click=${this.onClick}
|
|
@@ -3476,19 +3476,19 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3476
3476
|
.checkbox:hover {
|
|
3477
3477
|
opacity: 0.5;
|
|
3478
3478
|
}
|
|
3479
|
-
`;var Br=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 Lr=class extends re{constructor(){super(...arguments),this.onMount=()=>({}),this.loadingPreviews=!0,this.websitePreviewInfo=[],this.imagesToDisplay=[],this.imageUrlError=[]}
|
|
3479
|
+
`;var Br=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 Lr=class extends re{constructor(){super(...arguments),this.onMount=()=>({}),this.loadingPreviews=!0,this.websitePreviewInfo=[],this.imagesToDisplay=[],this.imageUrlError=[]}updated(e){if(this.onMount(),!e.has("message"))return;if(!this.message)return;const{hyperlinks:t,markedText:n}=this.mapAndMarkHyperLinks(this.message.message),i=/(https?:\/\/[^\s]+)/g,r=[],o=[];this.parsedMessage=U`${n.split("\n").map((e=>{const n=e.split(" ");return n?U`${n.map((e=>{if(t.find((t=>t.id===e))){const n=t.find((t=>t.id===e));if(!n)return;return o.push({redirectTo:null==n?void 0:n.link,source:null==n?void 0:n.link}),U`<a
|
|
3480
3480
|
class="redirect-link"
|
|
3481
3481
|
href="${null==n?void 0:n.link}"
|
|
3482
3482
|
target="_blank"
|
|
3483
3483
|
rel="noopener noreferrer"
|
|
3484
3484
|
>${null==n?void 0:n.hyperlink}
|
|
3485
|
-
</a>`}if(
|
|
3485
|
+
</a>`}if(i.test(e)){const t=this.removeTrailingPunctuation(e);return r.push(this.getLinkData(t)),U`<a
|
|
3486
3486
|
class="redirect-link"
|
|
3487
|
-
href="${
|
|
3487
|
+
href="${t}"
|
|
3488
3488
|
target="_blank"
|
|
3489
3489
|
rel="noopener noreferrer"
|
|
3490
|
-
>${
|
|
3491
|
-
</a>`}return U`${
|
|
3490
|
+
>${t}
|
|
3491
|
+
</a>`}return U`${e} `}))}<br />`:U``}))}`,this.imagesToDisplay=o,Promise.all(r).then((e=>{this.websitePreviewInfo=e}))}removeTrailingPunctuation(e){return[".",",","!","?",":",";"].includes(e[e.length-1])?this.removeTrailingPunctuation(e.slice(0,-1)):e}mapAndMarkHyperLinks(e){const t=Array.from(e.matchAll(/<https?:\/\/[^|]+\|[^>]+>|<a href="https?:\/\/[^"]+"(?: target="[^"]*")?>[^<]+<\/a>/g)),n=[],i=t.map((t=>{const n=t[0];if(void 0===t.index)return;const i=e[t.index-1],r=e[t.index+n.length];if(n.startsWith("<https")||n.startsWith("<http"))return{matchedLink:n,link:n.split("|")[0].replace("<",""),hyperlink:n.split("|")[1].replace(">",""),addSpaceBefore:!(!i||" "===i),addSpaceAfter:!(!r||" "===r)};{const e=n.match(/href="([^"]+)"/),t=n.match(/>[^<]+</);return{matchedLink:n,link:e?e[1]:"",hyperlink:t?t[0].slice(1,-1):"",addSpaceBefore:!(!i||" "===i),addSpaceAfter:!(!r||" "===r)}}}));return i.forEach((t=>{if(t&&t.link&&t.hyperlink){const i=Cr().replace(/-/g,"");n.push({link:this.removeTrailingPunctuation(t.link),hyperlink:this.removeTrailingPunctuation(t.hyperlink),mark:t.matchedLink,id:i}),e=e.replace(t.matchedLink,`${t.addSpaceBefore?" ":""}${i}${t.addSpaceAfter?" ":""}`)}})),{hyperlinks:n,markedText:e}}async getLinkData(e){var n,i,r,o;try{const a=(await t().get(e)).data,s=(new DOMParser).parseFromString(a,"text/html");return s?{title:null!==(i=null===(n=s.querySelector("title"))||void 0===n?void 0:n.textContent)&&void 0!==i?i:null,description:(null===(r=s.querySelector('meta[name="description"]'))||void 0===r?void 0:r.getAttribute("content"))||null,image:(null===(o=s.querySelector('meta[property="og:image"]'))||void 0===o?void 0:o.getAttribute("content"))||null,favicon:null,link:e}:{title:null,description:null,image:null,favicon:null,link:e}}catch(t){return console.error("Error fetching website details:",t),{title:null,description:null,image:null,favicon:null,link:e}}}render(){return this.message?U`<div class="message-inner-body">
|
|
3492
3492
|
<p
|
|
3493
3493
|
class=${fe({"message-text":!0,"webchat-font__desktop":!ln(),"webchat-font__mobile":ln()})}
|
|
3494
3494
|
>
|
|
@@ -3530,7 +3530,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3530
3530
|
</div>
|
|
3531
3531
|
</div>
|
|
3532
3532
|
</a></div> `}))}
|
|
3533
|
-
</div>`:U``}};Lr.styles=[pn,qr],Br([ue({attribute:!0})],Lr.prototype,"message",void 0),Br([ue({attribute:!0})],Lr.prototype,"myPubnub",void 0),Br([ue({attribute:!0})],Lr.prototype,"onMount",void 0),Br([le()],Lr.prototype,"loadingPreviews",void 0),Br([le()],Lr.prototype,"parsedMessage",void 0),Br([le()],Lr.prototype,"websitePreviewInfo",void 0),Br([le()],Lr.prototype,"imagesToDisplay",void 0),Br([le()],Lr.prototype,"imageUrlError",void 0),Lr=Br([ae("pubnub-message")],Lr);var Jr=864e5;function jr(e,t){Ue(2,arguments);var n=gn(e),i=gn(t),r=n.getTime()-Et(n),o=i.getTime()-Et(i);return Math.round((r-o)/Jr)}function Hr(e,t){var n=e.getFullYear()-t.getFullYear()||e.getMonth()-t.getMonth()||e.getDate()-t.getDate()||e.getHours()-t.getHours()||e.getMinutes()-t.getMinutes()||e.getSeconds()-t.getSeconds()||e.getMilliseconds()-t.getMilliseconds();return n<0?-1:n>0?1:n}var Gr=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 zr=class extends re{constructor(){super(...arguments),this.right=void 0,this.bottom=void 0,this.top=void 0,this.left=void 0,this.onMount=()=>({}),this.isHealthChat=!1,this.brandColor=Fe,this.onClickExit=()=>{localStorage.setItem("isChatOpen","false")},this.requiresConsent=!1,this.messages=[],this.isLoadingMessages=!1,this.hasReceivedConsent=!1,this.privacyPolicyUrl="http://bit.ly/me_privacy_policy",this.websitePreviewMapping={},this.sendMessage=async e=>{var t;this.messageInput.value="",this.autoResizeMessageInput(),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"})},this.autoResizeMessageInput=()=>{this.messageInput.style.height="auto",this.messageInput.style.height=this.messageInput.scrollHeight+"px"},this.needsConsent=()=>this.requiresConsent&&!this.hasReceivedConsent}get consentKey(){return`${this.orgSlug}Consent`}firstUpdated(){var e,t;this.messages=(null===(e=this.myPubnub)||void 0===e?void 0:e.
|
|
3533
|
+
</div>`:U``}};Lr.styles=[pn,qr],Br([ue({attribute:!0})],Lr.prototype,"message",void 0),Br([ue({attribute:!0})],Lr.prototype,"myPubnub",void 0),Br([ue({attribute:!0})],Lr.prototype,"onMount",void 0),Br([le()],Lr.prototype,"loadingPreviews",void 0),Br([le()],Lr.prototype,"parsedMessage",void 0),Br([le()],Lr.prototype,"websitePreviewInfo",void 0),Br([le()],Lr.prototype,"imagesToDisplay",void 0),Br([le()],Lr.prototype,"imageUrlError",void 0),Lr=Br([ae("pubnub-message")],Lr);var Jr=864e5;function jr(e,t){Ue(2,arguments);var n=gn(e),i=gn(t),r=n.getTime()-Et(n),o=i.getTime()-Et(i);return Math.round((r-o)/Jr)}function Hr(e,t){var n=e.getFullYear()-t.getFullYear()||e.getMonth()-t.getMonth()||e.getDate()-t.getDate()||e.getHours()-t.getHours()||e.getMinutes()-t.getMinutes()||e.getSeconds()-t.getSeconds()||e.getMilliseconds()-t.getMilliseconds();return n<0?-1:n>0?1:n}var Gr=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 zr=class extends re{constructor(){super(...arguments),this.right=void 0,this.bottom=void 0,this.top=void 0,this.left=void 0,this.onMount=()=>({}),this.isHealthChat=!1,this.brandColor=Fe,this.onClickExit=()=>{localStorage.setItem("isChatOpen","false")},this.requiresConsent=!1,this.messages=[],this.isLoadingMessages=!1,this.hasReceivedConsent=!1,this.privacyPolicyUrl="http://bit.ly/me_privacy_policy",this.websitePreviewMapping={},this.sendMessage=async e=>{var t;this.messageInput.value="",this.autoResizeMessageInput(),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"})},this.autoResizeMessageInput=()=>{this.messageInput.style.height="auto",this.messageInput.style.height=this.messageInput.scrollHeight+"px"},this.needsConsent=()=>this.requiresConsent&&!this.hasReceivedConsent}get consentKey(){return`${this.orgSlug}Consent`}firstUpdated(){var e,t;this.messages=(null===(e=this.myPubnub)||void 0===e?void 0:e.simpleChatMessages)||[],null===(t=this.myPubnub)||void 0===t||t.addChatListener((e=>{this.messages=e.messages,this.isLoadingMessages=e.isLoading})),this.onMount();const n=localStorage.getItem(this.consentKey);if(!n)return void(this.hasReceivedConsent=!1);const i=JSON.parse(n),{timestamp:r,consentId:o}=i,a=function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t),r=Hr(n,i),o=Math.abs(jr(n,i));n.setDate(n.getDate()-r*o);var a=Number(Hr(n,i)===-r),s=r*(o-a);return 0===s?0:s}(new Date,new Date(r));a<7&&o===Wr?this.hasReceivedConsent=!0:(this.hasReceivedConsent=!1,localStorage.removeItem(this.consentKey))}async updated(){this.scrollToChatBottom();try{const e=document.getElementById("#healthchat-container");if(!e)return;e.focus()}catch(e){console.error(e)}}render(){var e,t,n;if(!this.buildingSlug)return U``;let i={};if(i=ln()?{top:void 0,bottom:0,left:void 0,right:0}:{top:void 0===this.top||isNaN(this.top)?void 0:`${this.top}px`,bottom:void 0===this.bottom||isNaN(this.bottom)?"130px":`${this.bottom}px`,left:void 0===this.left||isNaN(this.left)?void 0:`${this.left}px`,right:void 0===this.right||isNaN(this.right)?"18px":`${this.right}px`},this.isHealthChat)return U`
|
|
3534
3534
|
<div
|
|
3535
3535
|
id="healthchat-container"
|
|
3536
3536
|
class=${fe({"pubnub-container__mobile":ln(),"healthchat-container__desktop":!ln()})}
|
|
@@ -3584,10 +3584,10 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3584
3584
|
How can I assist you today?
|
|
3585
3585
|
</p>
|
|
3586
3586
|
</li>
|
|
3587
|
-
${this.messages.map((e=>
|
|
3587
|
+
${this.messages.map((e=>U`
|
|
3588
3588
|
<li
|
|
3589
|
-
class=${
|
|
3590
|
-
key=${e.
|
|
3589
|
+
class=${e.isLeadMessage?"message-container lead-message":"message-container ai-message"}
|
|
3590
|
+
key=${e.timestamp}
|
|
3591
3591
|
>
|
|
3592
3592
|
<pubnub-message
|
|
3593
3593
|
.message=${e}
|
|
@@ -3596,7 +3596,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3596
3596
|
>
|
|
3597
3597
|
</pubnub-message>
|
|
3598
3598
|
</li>
|
|
3599
|
-
`
|
|
3599
|
+
`))}
|
|
3600
3600
|
${this.isLoadingMessages?U`
|
|
3601
3601
|
<li
|
|
3602
3602
|
id="loading-message"
|
|
@@ -3673,10 +3673,10 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3673
3673
|
${this.building.welcomeMessage}
|
|
3674
3674
|
</p>
|
|
3675
3675
|
</li>`:""}
|
|
3676
|
-
${this.messages.map((e=>
|
|
3676
|
+
${this.messages.map((e=>U`
|
|
3677
3677
|
<li
|
|
3678
|
-
class=${Gn()("message-container",{"lead-message":
|
|
3679
|
-
key=${e.
|
|
3678
|
+
class=${Gn()("message-container",{"lead-message":e.isLeadMessage,"ai-message":!e.isLeadMessage,"with-box-shadow":444===r})}
|
|
3679
|
+
key=${e.timestamp}
|
|
3680
3680
|
>
|
|
3681
3681
|
<pubnub-message
|
|
3682
3682
|
.message=${e}
|
|
@@ -3685,7 +3685,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3685
3685
|
>
|
|
3686
3686
|
</pubnub-message>
|
|
3687
3687
|
</li>
|
|
3688
|
-
`
|
|
3688
|
+
`))}
|
|
3689
3689
|
${this.isLoadingMessages?U`
|
|
3690
3690
|
<li id="loading-message" class="message-container ai-message">
|
|
3691
3691
|
<div class="loading-dot dot-1"></div>
|
package/src/MyPubnub.ts
CHANGED
|
@@ -23,18 +23,33 @@ enum MessageType {
|
|
|
23
23
|
text = "text",
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
interface RawPubnubMessage {
|
|
27
27
|
channel: string;
|
|
28
28
|
message: {
|
|
29
29
|
text: string;
|
|
30
30
|
customType: string;
|
|
31
31
|
messageType?: MessageType;
|
|
32
|
+
is_streaming?: boolean;
|
|
33
|
+
is_done?: boolean;
|
|
34
|
+
order?: number;
|
|
35
|
+
stream_id?: string;
|
|
32
36
|
};
|
|
33
37
|
publisher: string;
|
|
34
38
|
subscription: string;
|
|
35
39
|
timetoken: number;
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
export interface SimpleChatMessage {
|
|
43
|
+
timestamp: number;
|
|
44
|
+
message: string;
|
|
45
|
+
isLeadMessage: boolean;
|
|
46
|
+
chunks: {
|
|
47
|
+
text: string;
|
|
48
|
+
order: number;
|
|
49
|
+
isDone: boolean;
|
|
50
|
+
}[];
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
class MyPubnub {
|
|
39
54
|
private apiHost = "https://app.meetelise.com";
|
|
40
55
|
|
|
@@ -50,16 +65,18 @@ class MyPubnub {
|
|
|
50
65
|
leadSource: string | null = null;
|
|
51
66
|
|
|
52
67
|
chatListener:
|
|
53
|
-
| ((res: { messages:
|
|
68
|
+
| ((res: { messages: SimpleChatMessage[]; isLoading: boolean }) => void)
|
|
54
69
|
| null = null;
|
|
55
70
|
|
|
56
|
-
|
|
71
|
+
rawPubnubMessages: RawPubnubMessage[] = [];
|
|
72
|
+
simpleChatMessages: SimpleChatMessage[] = [];
|
|
73
|
+
|
|
57
74
|
listenerParams: ListenerParameters = {
|
|
58
75
|
message: (messageEvent: MessageEvent) => {
|
|
59
76
|
// if the messageEvent is a no-reply, we ignore it and stop loading
|
|
60
77
|
if (messageEvent.message.messageType !== MessageType.noReply) {
|
|
61
|
-
this.
|
|
62
|
-
...this.
|
|
78
|
+
this.rawPubnubMessages = [
|
|
79
|
+
...this.rawPubnubMessages,
|
|
63
80
|
{
|
|
64
81
|
channel: messageEvent.channel,
|
|
65
82
|
message: messageEvent.message,
|
|
@@ -68,12 +85,16 @@ class MyPubnub {
|
|
|
68
85
|
timetoken: +messageEvent.timetoken,
|
|
69
86
|
},
|
|
70
87
|
];
|
|
88
|
+
this.simpleChatMessages =
|
|
89
|
+
this.translatePubnubMessagesIntoSimpleChatMessages(
|
|
90
|
+
this.rawPubnubMessages
|
|
91
|
+
);
|
|
71
92
|
}
|
|
72
93
|
const isWaitingForEliseResponse =
|
|
73
94
|
messageEvent.publisher !== "eliseai" &&
|
|
74
95
|
messageEvent.publisher !== "elise_health_ai";
|
|
75
96
|
this.chatListener?.({
|
|
76
|
-
messages: this.
|
|
97
|
+
messages: this.simpleChatMessages,
|
|
77
98
|
isLoading: isWaitingForEliseResponse,
|
|
78
99
|
});
|
|
79
100
|
if (!isWaitingForEliseResponse && this.eliseResponseTimeout) {
|
|
@@ -101,7 +122,7 @@ class MyPubnub {
|
|
|
101
122
|
|
|
102
123
|
addChatListener(
|
|
103
124
|
listener: (response: {
|
|
104
|
-
messages:
|
|
125
|
+
messages: SimpleChatMessage[];
|
|
105
126
|
isLoading: boolean;
|
|
106
127
|
}) => void
|
|
107
128
|
): void {
|
|
@@ -213,59 +234,86 @@ class MyPubnub {
|
|
|
213
234
|
}
|
|
214
235
|
}
|
|
215
236
|
|
|
216
|
-
async getChannelHistory(): Promise<void> {
|
|
237
|
+
async getChannelHistory(maxTotalMessageChunksToFetch = 1000): Promise<void> {
|
|
217
238
|
try {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
let allMessages: RawPubnubMessage[] = [];
|
|
240
|
+
let startTimeToken: string | number | null = null;
|
|
241
|
+
const maxCountPerFetch = 100;
|
|
242
|
+
for (
|
|
243
|
+
let totalCount = 0;
|
|
244
|
+
totalCount < maxTotalMessageChunksToFetch;
|
|
245
|
+
totalCount += maxCountPerFetch
|
|
246
|
+
) {
|
|
247
|
+
const response: Pubnub.FetchMessagesResponse = await new Promise(
|
|
248
|
+
(resolve, reject) => {
|
|
249
|
+
if (!this.pubnub || !this.channel) return [];
|
|
250
|
+
const countToFetch = Math.min(
|
|
251
|
+
maxCountPerFetch,
|
|
252
|
+
maxTotalMessageChunksToFetch - totalCount
|
|
253
|
+
);
|
|
254
|
+
this.pubnub.fetchMessages(
|
|
255
|
+
{
|
|
256
|
+
channels: [this.channel],
|
|
257
|
+
count: countToFetch,
|
|
258
|
+
end: startTimeToken ?? undefined,
|
|
259
|
+
},
|
|
260
|
+
(status, response) => {
|
|
261
|
+
if (status.error) {
|
|
262
|
+
reject(status);
|
|
263
|
+
} else {
|
|
264
|
+
resolve(response);
|
|
240
265
|
}
|
|
241
|
-
reject(status);
|
|
242
|
-
} else {
|
|
243
|
-
resolve(response);
|
|
244
266
|
}
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
const messages = response.channels[this.channel];
|
|
272
|
+
if (!messages || messages.length === 0) {
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (this.channel && Object.keys(response.channels).length !== 0) {
|
|
277
|
+
const currentChannelMessages = response.channels[this.channel];
|
|
278
|
+
const parsedCurrentChannelMessages: RawPubnubMessage[] = [];
|
|
279
|
+
currentChannelMessages.forEach((message) => {
|
|
280
|
+
if (message.uuid) {
|
|
281
|
+
parsedCurrentChannelMessages.push({
|
|
282
|
+
channel: message.channel,
|
|
283
|
+
message: message.message,
|
|
284
|
+
publisher: message.uuid,
|
|
285
|
+
subscription: message.channel,
|
|
286
|
+
timetoken: +message.timetoken,
|
|
287
|
+
});
|
|
245
288
|
}
|
|
289
|
+
});
|
|
290
|
+
allMessages = allMessages.concat(
|
|
291
|
+
parsedCurrentChannelMessages.filter(
|
|
292
|
+
(m) => m.message.messageType !== MessageType.noReply
|
|
293
|
+
)
|
|
246
294
|
);
|
|
247
295
|
}
|
|
248
|
-
|
|
296
|
+
startTimeToken = messages[messages.length - 1].timetoken;
|
|
249
297
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
channel: message.channel,
|
|
257
|
-
message: message.message,
|
|
258
|
-
publisher: message.uuid,
|
|
259
|
-
subscription: message.channel,
|
|
260
|
-
timetoken: +message.timetoken,
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
this.messages = parsedCurrentChannelMessages.filter(
|
|
265
|
-
(m) => m.message.messageType !== MessageType.noReply
|
|
266
|
-
);
|
|
267
|
-
this.chatListener?.({ messages: this.messages, isLoading: false });
|
|
298
|
+
if (
|
|
299
|
+
allMessages.length >= maxTotalMessageChunksToFetch ||
|
|
300
|
+
messages.length < maxCountPerFetch
|
|
301
|
+
) {
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
268
304
|
}
|
|
305
|
+
this.rawPubnubMessages = allMessages.slice(
|
|
306
|
+
0,
|
|
307
|
+
maxTotalMessageChunksToFetch
|
|
308
|
+
);
|
|
309
|
+
this.simpleChatMessages =
|
|
310
|
+
this.translatePubnubMessagesIntoSimpleChatMessages(
|
|
311
|
+
this.rawPubnubMessages
|
|
312
|
+
);
|
|
313
|
+
this.chatListener?.({
|
|
314
|
+
messages: this.simpleChatMessages,
|
|
315
|
+
isLoading: false,
|
|
316
|
+
});
|
|
269
317
|
} catch (error) {
|
|
270
318
|
if (this.building) {
|
|
271
319
|
sendLoggingEvent({
|
|
@@ -368,9 +416,64 @@ class MyPubnub {
|
|
|
368
416
|
if (this.isLoadingMessages === false) this.isLoadingMessages = true;
|
|
369
417
|
}
|
|
370
418
|
};
|
|
371
|
-
isLeadMessage = (message:
|
|
419
|
+
isLeadMessage = (message: RawPubnubMessage): boolean =>
|
|
372
420
|
message.publisher.includes("lead_") &&
|
|
373
421
|
message.message.customType === "lead_message";
|
|
422
|
+
|
|
423
|
+
translatePubnubMessagesIntoSimpleChatMessages = (
|
|
424
|
+
messages: RawPubnubMessage[]
|
|
425
|
+
): SimpleChatMessage[] => {
|
|
426
|
+
const parsedMessages: SimpleChatMessage[] = [];
|
|
427
|
+
const streamingIdToMessageChunks: {
|
|
428
|
+
[streamId: string]: RawPubnubMessage[];
|
|
429
|
+
} = {};
|
|
430
|
+
messages.forEach((message: RawPubnubMessage) => {
|
|
431
|
+
if (!message.message.stream_id) {
|
|
432
|
+
parsedMessages.push({
|
|
433
|
+
timestamp: message.timetoken,
|
|
434
|
+
message: message.message.text,
|
|
435
|
+
isLeadMessage: this.isLeadMessage(message),
|
|
436
|
+
chunks: [
|
|
437
|
+
{
|
|
438
|
+
text: message.message.text,
|
|
439
|
+
order: 0,
|
|
440
|
+
isDone: true,
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
});
|
|
444
|
+
} else {
|
|
445
|
+
if (streamingIdToMessageChunks[message.message.stream_id]) {
|
|
446
|
+
streamingIdToMessageChunks[message.message.stream_id].push(message);
|
|
447
|
+
} else {
|
|
448
|
+
streamingIdToMessageChunks[message.message.stream_id] = [message];
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
Object.keys(streamingIdToMessageChunks).forEach((streamId) => {
|
|
453
|
+
const messages = streamingIdToMessageChunks[streamId];
|
|
454
|
+
const sortedMessages = messages.sort(
|
|
455
|
+
(a, b) => (a.message.order ?? 0) - (b.message.order ?? 0)
|
|
456
|
+
);
|
|
457
|
+
const text = sortedMessages
|
|
458
|
+
.map((message) => message.message.text)
|
|
459
|
+
.join("");
|
|
460
|
+
const firstMessage = sortedMessages[0];
|
|
461
|
+
const newMessage: SimpleChatMessage = {
|
|
462
|
+
timestamp: firstMessage.timetoken,
|
|
463
|
+
message: text,
|
|
464
|
+
isLeadMessage: this.isLeadMessage(firstMessage),
|
|
465
|
+
chunks: sortedMessages.map((message) => ({
|
|
466
|
+
text: message.message.text,
|
|
467
|
+
order: message.message.order ?? 0,
|
|
468
|
+
isDone: message.message.is_done ?? false,
|
|
469
|
+
})),
|
|
470
|
+
};
|
|
471
|
+
parsedMessages.push(newMessage);
|
|
472
|
+
});
|
|
473
|
+
parsedMessages.sort((a, b) => a.timestamp - b.timestamp);
|
|
474
|
+
|
|
475
|
+
return parsedMessages;
|
|
476
|
+
};
|
|
374
477
|
}
|
|
375
478
|
|
|
376
479
|
export default MyPubnub;
|
|
@@ -3,7 +3,7 @@ import { customElement, property, query, state } from "lit/decorators.js";
|
|
|
3
3
|
import { classMap } from "lit/directives/class-map.js";
|
|
4
4
|
import { styleMap } from "lit/directives/style-map.js";
|
|
5
5
|
import { Building } from "../fetchBuildingInfo";
|
|
6
|
-
import MyPubnub, {
|
|
6
|
+
import MyPubnub, { SimpleChatMessage } from "../MyPubnub";
|
|
7
7
|
import {
|
|
8
8
|
CheckboxEmpty,
|
|
9
9
|
HeyThereEmoji,
|
|
@@ -82,7 +82,7 @@ export class PubnubChat extends LitElement {
|
|
|
82
82
|
messageBody!: HTMLDivElement;
|
|
83
83
|
|
|
84
84
|
@state()
|
|
85
|
-
messages:
|
|
85
|
+
messages: SimpleChatMessage[] = [];
|
|
86
86
|
|
|
87
87
|
@state()
|
|
88
88
|
isLoadingMessages = false;
|
|
@@ -114,9 +114,9 @@ export class PubnubChat extends LitElement {
|
|
|
114
114
|
await this.myPubnub?.sendMessage(message);
|
|
115
115
|
};
|
|
116
116
|
firstUpdated(): void {
|
|
117
|
-
this.messages = this.myPubnub?.
|
|
117
|
+
this.messages = this.myPubnub?.simpleChatMessages || [];
|
|
118
118
|
this.myPubnub?.addChatListener(
|
|
119
|
-
(response: { messages:
|
|
119
|
+
(response: { messages: SimpleChatMessage[]; isLoading: boolean }) => {
|
|
120
120
|
this.messages = response.messages;
|
|
121
121
|
this.isLoadingMessages = response.isLoading;
|
|
122
122
|
}
|
|
@@ -285,10 +285,10 @@ export class PubnubChat extends LitElement {
|
|
|
285
285
|
${this.messages.map((message) => {
|
|
286
286
|
return html`
|
|
287
287
|
<li
|
|
288
|
-
class=${
|
|
288
|
+
class=${message.isLeadMessage
|
|
289
289
|
? "message-container lead-message"
|
|
290
290
|
: "message-container ai-message"}
|
|
291
|
-
key=${message.
|
|
291
|
+
key=${message.timestamp}
|
|
292
292
|
>
|
|
293
293
|
<pubnub-message
|
|
294
294
|
.message=${message}
|
|
@@ -440,11 +440,11 @@ export class PubnubChat extends LitElement {
|
|
|
440
440
|
return html`
|
|
441
441
|
<li
|
|
442
442
|
class=${classNames("message-container", {
|
|
443
|
-
"lead-message":
|
|
444
|
-
"ai-message": !
|
|
443
|
+
"lead-message": message.isLeadMessage,
|
|
444
|
+
"ai-message": !message.isLeadMessage,
|
|
445
445
|
"with-box-shadow": orgId === 444,
|
|
446
446
|
})}
|
|
447
|
-
key=${message.
|
|
447
|
+
key=${message.timestamp}
|
|
448
448
|
>
|
|
449
449
|
<pubnub-message
|
|
450
450
|
.message=${message}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { html, LitElement, TemplateResult } from "lit";
|
|
1
|
+
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
|
|
2
2
|
import { customElement, property, state } from "lit/decorators.js";
|
|
3
|
-
import MyPubnub, {
|
|
3
|
+
import MyPubnub, { SimpleChatMessage } from "../MyPubnub";
|
|
4
4
|
import { v4 as uuid } from "uuid";
|
|
5
5
|
import axios from "axios";
|
|
6
6
|
import { classMap } from "lit/directives/class-map.js";
|
|
@@ -24,8 +24,10 @@ interface ImageToDisplay {
|
|
|
24
24
|
export class PubnubMessage extends LitElement {
|
|
25
25
|
static styles = [InputStyles, pubnubChatStyles];
|
|
26
26
|
|
|
27
|
-
@property({
|
|
28
|
-
|
|
27
|
+
@property({
|
|
28
|
+
attribute: true,
|
|
29
|
+
})
|
|
30
|
+
message: SimpleChatMessage | undefined;
|
|
29
31
|
|
|
30
32
|
@property({ attribute: true })
|
|
31
33
|
myPubnub: MyPubnub | undefined;
|
|
@@ -48,10 +50,12 @@ export class PubnubMessage extends LitElement {
|
|
|
48
50
|
@state()
|
|
49
51
|
imageUrlError: string[] = [];
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
updated(changedProperties: PropertyValues<this>): void {
|
|
54
|
+
this.onMount();
|
|
55
|
+
if (!changedProperties.has("message")) return;
|
|
52
56
|
if (!this.message) return;
|
|
53
57
|
const { hyperlinks, markedText } = this.mapAndMarkHyperLinks(
|
|
54
|
-
this.message.message
|
|
58
|
+
this.message.message
|
|
55
59
|
);
|
|
56
60
|
const urlRegex = /(https?:\/\/[^\s]+)/g; // Regular expression to match URLs
|
|
57
61
|
const loadingWebsitePreviews: Promise<WebsitePreview>[] = [];
|
|
@@ -223,10 +227,6 @@ export class PubnubMessage extends LitElement {
|
|
|
223
227
|
}
|
|
224
228
|
}
|
|
225
229
|
|
|
226
|
-
updated(): void {
|
|
227
|
-
this.onMount();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
230
|
render(): TemplateResult {
|
|
231
231
|
if (!this.message) return html``;
|
|
232
232
|
return html`<div class="message-inner-body">
|