@meetelise/chat 1.20.230 → 1.20.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetelise/chat",
3
- "version": "1.20.230",
3
+ "version": "1.20.232",
4
4
  "description": "",
5
5
  "main": "public/dist/index.js",
6
6
  "type": "module",
@@ -131,15 +131,13 @@
131
131
  };
132
132
 
133
133
  MEChat.start({
134
- // organization: "f1ba5a20-d207-4e5a-879e-65199e7d0a53",
135
- // building: "5066bd44-5caa-11ee-b3d3-7bea9959423f",
136
-
134
+ organization: "elise-ai",
135
+ //building: "test-yardi-building",
136
+ building: "930196d8-3527-11ee-a65a-b70940a36fe6",
137
137
  onWidgetLoaded: onWidgetLoaded,
138
138
  // organization: "00f18938-9632-40b9-8d7f-f30e219c94fc",
139
139
  // building: "19e21cda-d05b-11ee-b3bd-cf9cc1ace7e5",
140
140
  // 123 Main Street
141
- organization: "test-company",
142
- building: "e2e-test-yardi-building",
143
141
  // organization: "edward-rose",
144
142
  // building: "rivers-edge-apartments",
145
143
  // // mobileStyles: {
@@ -3016,7 +3016,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
3016
3016
  ${wi}
3017
3017
  ${Si}
3018
3018
  ${Ti}
3019
- `,Zi([ue({attribute:!0})],er.prototype,"isMinimized",void 0),Zi([ue()],er.prototype,"mobileStyles",void 0),Zi([ue({type:Boolean})],er.prototype,"isFirstMount",void 0),Zi([ue({attribute:!1})],er.prototype,"autoOpenChatWidget",void 0),Zi([ue()],er.prototype,"phoneNumber",void 0),Zi([ue({attribute:!0})],er.prototype,"buildingName",void 0),Zi([ue({attribute:!0})],er.prototype,"chatId",void 0),Zi([ue({attribute:!0})],er.prototype,"chatCallUsHeader",void 0),Zi([ue({attribute:!1})],er.prototype,"buildingId",void 0),Zi([ue({attribute:!0})],er.prototype,"buildingSlug",void 0),Zi([ue({attribute:!0})],er.prototype,"orgSlug",void 0),Zi([ue({attribute:!0})],er.prototype,"sgtUrl",void 0),Zi([ue({attribute:!0})],er.prototype,"designConcept",void 0),Zi([ue({attribute:!0})],er.prototype,"featureFlagShowDropdown",void 0),Zi([ue({attribute:!1})],er.prototype,"leadSources",void 0),Zi([ue({attribute:!0})],er.prototype,"currentLeadSource",void 0),Zi([ue({attribute:!0})],er.prototype,"escortedToursLink",void 0),Zi([ue({attribute:!0})],er.prototype,"virtualToursLink",void 0),Zi([ue({type:Boolean})],er.prototype,"hasCallUsEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasChatEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasEmailEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasSSTEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasTextUsEnabled",void 0),Zi([ue({attribute:!1})],er.prototype,"layoutOptions",void 0),Zi([ue({attribute:!1})],er.prototype,"unitOptions",void 0),Zi([ue({attribute:!1})],er.prototype,"tourTypeOptions",void 0),Zi([ue({attribute:!0})],er.prototype,"hasDynamicSchedulingEnabled",void 0),Zi([ue({attribute:!0})],er.prototype,"onExitChat",void 0),Zi([ue({type:Number})],er.prototype,"right",void 0),Zi([ue({type:Number})],er.prototype,"bottom",void 0),Zi([ue({type:Number})],er.prototype,"top",void 0),Zi([ue({type:Number})],er.prototype,"left",void 0),Zi([ue({attribute:!0})],er.prototype,"showTourNextToChat",void 0),Zi([ue({attribute:!1})],er.prototype,"onChatTapped",void 0),Zi([ue({attribute:!0})],er.prototype,"onClickMinimize",void 0),Zi([ue({attribute:!1})],er.prototype,"launcherStyles",void 0),Zi([ue({attribute:!0})],er.prototype,"brandColor",void 0),Zi([ue({attribute:!0})],er.prototype,"leadSourceClient",void 0),Zi([le()],er.prototype,"isEmailWindowOpen",void 0),Zi([le()],er.prototype,"isCallUsWindowOpen",void 0),Zi([le()],er.prototype,"isSSTWindowOpen",void 0),Zi([le()],er.prototype,"isTextUsWindowOpen",void 0),er=Zi([ae("meetelise-launcher")],er);const tr=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",er)};var nr=n(3379),ir=n.n(nr),rr=n(7795),or=n.n(rr),ar=n(569),sr=n.n(ar),ur=n(3565),lr=n.n(ur),dr=n(9216),cr=n.n(dr),pr=n(4589),hr=n.n(pr),fr=n(3631),mr={};async function gr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?vr(n.data,e):[]}catch(e){return[]}}mr.styleTagTransform=hr(),mr.setAttributes=lr(),mr.insert=sr().bind(null,"head"),mr.domAPI=or(),mr.insertStyleElement=cr(),ir()(fr.Z,mr),fr.Z&&fr.Z.locals&&fr.Z.locals;const vr=(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 yr,br=n(9594),wr=n.n(br),Sr=new Uint8Array(16);function Tr(){if(!yr&&!(yr="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 yr(Sr)}const xr=/^(?:[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,Ar=function(e){return"string"==typeof e&&xr.test(e)};for(var Or=[],Cr=0;Cr<256;++Cr)Or.push((Cr+256).toString(16).substr(1));const Ir=function(e,t,n){var i=(e=e||{}).random||(e.rng||Tr)();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=(Or[e[t+0]]+Or[e[t+1]]+Or[e[t+2]]+Or[e[t+3]]+"-"+Or[e[t+4]]+Or[e[t+5]]+"-"+Or[e[t+6]]+Or[e[t+7]]+"-"+Or[e[t+8]]+Or[e[t+9]]+"-"+Or[e[t+10]]+Or[e[t+11]]+Or[e[t+12]]+Or[e[t+13]]+Or[e[t+14]]+Or[e[t+15]]).toLowerCase();if(!Ar(n))throw TypeError("Stringified UUID is invalid");return n}(i)},Nr=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Er=(e,t,n)=>{const i=vn(new Date),r=n||`lead_${Ir()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:An(i),buildingSlug:e,initiatedChat:t}},Rr=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(_r(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},_r=(e,t)=>{try{if(t.timestamp&&t.initiatedChat){const e=new Date("2024-06-06T21:30:00Z"),n=new Date("2024-06-06T18:30:00Z");if(un(t.timestamp,e)&&function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t);return n.getTime()>i.getTime()}(t.timestamp,n))return!1}}catch(e){console.warn("Error checking chat storage key validity")}return!(t.buildingSlug!==e||!t.leadId||!t.timestamp||cn(t.timestamp,24))};var Pr;!function(e){e.noReply="no-reply",e.text="text",e.media="media"}(Pr||(Pr={}));const Mr=e=>e.type===Dr.text,Fr=e=>e.type===Dr.media;var Dr;!function(e){e.text="text",e.media="media"}(Dr||(Dr={}));const kr=class{constructor(e,t,n,i=null,r,o=null){this.apiHost="https://app.meetelise.com",this.leadSourceClient=null,this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.isCurrentlyStreamingMessage=!1,this.chatListener=null,this.rawPubnubMessages=[],this.simpleChatMessages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==Pr.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=Er(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))return}await this.withAuthToken((async()=>{var t,n,i;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),0===this.simpleChatMessages.length&&(null===(t=this.leadSourceClient)||void 0===t||t.checkAndHandleForLogLeadSource({webchatAction:"chat",stateId:null})),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(n=this.building)||void 0===n?void 0:n.id,buildingSlug:this.buildingSlug,userId:null===(i=this.building)||void 0===i?void 0:i.userId,leadSource:this.leadSource,isDevState:this.shouldCreateAsDevState()}}))})),!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=>{var i;"media"===e.message.messageType?t.push({timestamp:e.timetoken,media:null!==(i=e.message.media)&&void 0!==i?i:[],isLeadMessage:this.isLeadMessage(e),type:Dr.media}):!e.message.stream_id||e.message.is_done&&0===e.message.order?t.push({timestamp:e.timetoken,message:e.message.text,isLeadMessage:this.isLeadMessage(e),chunks:[{text:e.message.text,order:0,isDone:!0}],type:Dr.text}):n[e.message.stream_id]?n[e.message.stream_id].push(e):n[e.message.stream_id]=[e]})),Object.keys(n).forEach((e=>{const i=n[e],r=this.getConsecutiveChunks(i.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)}))),o=r.map((e=>e.message.text)).join(""),a=r[0],s={timestamp:a.timetoken,message:o,isLeadMessage:this.isLeadMessage(a),chunks:r.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}})),type:Dr.text};this.isCurrentlyStreamingMessage=this.isMessageStillStreamingChunks(r),t.push(s)})),t.sort(((e,t)=>e.timestamp-t.timestamp)),t},this.getConsecutiveChunks=e=>{var t,n;const i=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=[];let o=null!==(t=i[0].message.order)&&void 0!==t?t:0;for(const e of i){if((null!==(n=e.message.order)&&void 0!==n?n:-1)!==o)break;r.push(e),o++}return r},this.isMessageStillStreamingChunks=e=>{const t=e.find((e=>e.message.is_done));return!t||e.length===t.message.order},this.buildingSlug=e,this.building=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`,this.leadSourceClient=o}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(wr())({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=1500){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,start:null!=i?i:void 0},((e,t)=>{e.error?o(e):n(t)}))})),a=o.channels[this.channel];if(!a)break;if(a.sort(((e,t)=>+e.timetoken-+t.timetoken)),!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!==Pr.noReply)))}if(i=a[0].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})}}shouldCreateAsDevState(){return location.href.startsWith("https://app.meetelise.com/settings/widgets")}},Ur=(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 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};let Br=class extends re{constructor(){super(...arguments),this.onClick=()=>{},this.brandColor=Me,this.toExpand=!1}render(){return U`
3019
+ `,Zi([ue({attribute:!0})],er.prototype,"isMinimized",void 0),Zi([ue()],er.prototype,"mobileStyles",void 0),Zi([ue({type:Boolean})],er.prototype,"isFirstMount",void 0),Zi([ue({attribute:!1})],er.prototype,"autoOpenChatWidget",void 0),Zi([ue()],er.prototype,"phoneNumber",void 0),Zi([ue({attribute:!0})],er.prototype,"buildingName",void 0),Zi([ue({attribute:!0})],er.prototype,"chatId",void 0),Zi([ue({attribute:!0})],er.prototype,"chatCallUsHeader",void 0),Zi([ue({attribute:!1})],er.prototype,"buildingId",void 0),Zi([ue({attribute:!0})],er.prototype,"buildingSlug",void 0),Zi([ue({attribute:!0})],er.prototype,"orgSlug",void 0),Zi([ue({attribute:!0})],er.prototype,"sgtUrl",void 0),Zi([ue({attribute:!0})],er.prototype,"designConcept",void 0),Zi([ue({attribute:!0})],er.prototype,"featureFlagShowDropdown",void 0),Zi([ue({attribute:!1})],er.prototype,"leadSources",void 0),Zi([ue({attribute:!0})],er.prototype,"currentLeadSource",void 0),Zi([ue({attribute:!0})],er.prototype,"escortedToursLink",void 0),Zi([ue({attribute:!0})],er.prototype,"virtualToursLink",void 0),Zi([ue({type:Boolean})],er.prototype,"hasCallUsEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasChatEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasEmailEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasSSTEnabled",void 0),Zi([ue({type:Boolean})],er.prototype,"hasTextUsEnabled",void 0),Zi([ue({attribute:!1})],er.prototype,"layoutOptions",void 0),Zi([ue({attribute:!1})],er.prototype,"unitOptions",void 0),Zi([ue({attribute:!1})],er.prototype,"tourTypeOptions",void 0),Zi([ue({attribute:!0})],er.prototype,"hasDynamicSchedulingEnabled",void 0),Zi([ue({attribute:!0})],er.prototype,"onExitChat",void 0),Zi([ue({type:Number})],er.prototype,"right",void 0),Zi([ue({type:Number})],er.prototype,"bottom",void 0),Zi([ue({type:Number})],er.prototype,"top",void 0),Zi([ue({type:Number})],er.prototype,"left",void 0),Zi([ue({attribute:!0})],er.prototype,"showTourNextToChat",void 0),Zi([ue({attribute:!1})],er.prototype,"onChatTapped",void 0),Zi([ue({attribute:!0})],er.prototype,"onClickMinimize",void 0),Zi([ue({attribute:!1})],er.prototype,"launcherStyles",void 0),Zi([ue({attribute:!0})],er.prototype,"brandColor",void 0),Zi([ue({attribute:!0})],er.prototype,"leadSourceClient",void 0),Zi([le()],er.prototype,"isEmailWindowOpen",void 0),Zi([le()],er.prototype,"isCallUsWindowOpen",void 0),Zi([le()],er.prototype,"isSSTWindowOpen",void 0),Zi([le()],er.prototype,"isTextUsWindowOpen",void 0),er=Zi([ae("meetelise-launcher")],er);const tr=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",er)};var nr=n(3379),ir=n.n(nr),rr=n(7795),or=n.n(rr),ar=n(569),sr=n.n(ar),ur=n(3565),lr=n.n(ur),dr=n(9216),cr=n.n(dr),pr=n(4589),hr=n.n(pr),fr=n(3631),mr={};async function gr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?vr(n.data,e):[]}catch(e){return[]}}mr.styleTagTransform=hr(),mr.setAttributes=lr(),mr.insert=sr().bind(null,"head"),mr.domAPI=or(),mr.insertStyleElement=cr(),ir()(fr.Z,mr),fr.Z&&fr.Z.locals&&fr.Z.locals;const vr=(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 yr,br=n(9594),wr=n.n(br),Sr=new Uint8Array(16);function Tr(){if(!yr&&!(yr="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 yr(Sr)}const xr=/^(?:[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,Ar=function(e){return"string"==typeof e&&xr.test(e)};for(var Or=[],Cr=0;Cr<256;++Cr)Or.push((Cr+256).toString(16).substr(1));const Ir=function(e,t,n){var i=(e=e||{}).random||(e.rng||Tr)();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=(Or[e[t+0]]+Or[e[t+1]]+Or[e[t+2]]+Or[e[t+3]]+"-"+Or[e[t+4]]+Or[e[t+5]]+"-"+Or[e[t+6]]+Or[e[t+7]]+"-"+Or[e[t+8]]+Or[e[t+9]]+"-"+Or[e[t+10]]+Or[e[t+11]]+Or[e[t+12]]+Or[e[t+13]]+Or[e[t+14]]+Or[e[t+15]]).toLowerCase();if(!Ar(n))throw TypeError("Stringified UUID is invalid");return n}(i)},Nr=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Er=(e,t,n)=>{const i=vn(new Date),r=n||`lead_${Ir()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:An(i),buildingSlug:e,initiatedChat:t}},Rr=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(_r(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},_r=(e,t)=>{try{if(t.timestamp&&t.initiatedChat){const e=new Date("2024-06-06T21:30:00Z");if(un(t.timestamp,e))return!1}}catch(e){console.warn("Error checking chat storage key validity")}return!(t.buildingSlug!==e||!t.leadId||!t.timestamp||cn(t.timestamp,24))};var Pr;!function(e){e.noReply="no-reply",e.text="text",e.media="media"}(Pr||(Pr={}));const Mr=e=>e.type===Dr.text,Fr=e=>e.type===Dr.media;var Dr;!function(e){e.text="text",e.media="media"}(Dr||(Dr={}));const kr=class{constructor(e,t,n,i=null,r,o=null){this.apiHost="https://app.meetelise.com",this.leadSourceClient=null,this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.isCurrentlyStreamingMessage=!1,this.chatListener=null,this.rawPubnubMessages=[],this.simpleChatMessages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==Pr.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=Er(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))return}await this.withAuthToken((async()=>{var t,n,i;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),0===this.simpleChatMessages.length&&(null===(t=this.leadSourceClient)||void 0===t||t.checkAndHandleForLogLeadSource({webchatAction:"chat",stateId:null})),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(n=this.building)||void 0===n?void 0:n.id,buildingSlug:this.buildingSlug,userId:null===(i=this.building)||void 0===i?void 0:i.userId,leadSource:this.leadSource,isDevState:this.shouldCreateAsDevState()}}))})),!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=>{var i;"media"===e.message.messageType?t.push({timestamp:e.timetoken,media:null!==(i=e.message.media)&&void 0!==i?i:[],isLeadMessage:this.isLeadMessage(e),type:Dr.media}):!e.message.stream_id||e.message.is_done&&0===e.message.order?t.push({timestamp:e.timetoken,message:e.message.text,isLeadMessage:this.isLeadMessage(e),chunks:[{text:e.message.text,order:0,isDone:!0}],type:Dr.text}):n[e.message.stream_id]?n[e.message.stream_id].push(e):n[e.message.stream_id]=[e]})),Object.keys(n).forEach((e=>{const i=n[e],r=this.getConsecutiveChunks(i.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)}))),o=r.map((e=>e.message.text)).join(""),a=r[0],s={timestamp:a.timetoken,message:o,isLeadMessage:this.isLeadMessage(a),chunks:r.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}})),type:Dr.text};this.isCurrentlyStreamingMessage=this.isMessageStillStreamingChunks(r),t.push(s)})),t.sort(((e,t)=>e.timestamp-t.timestamp)),t},this.getConsecutiveChunks=e=>{var t,n;const i=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=[];let o=null!==(t=i[0].message.order)&&void 0!==t?t:0;for(const e of i){if((null!==(n=e.message.order)&&void 0!==n?n:-1)!==o)break;r.push(e),o++}return r},this.isMessageStillStreamingChunks=e=>{const t=e.find((e=>e.message.is_done));return!t||e.length===t.message.order},this.buildingSlug=e,this.building=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`,this.leadSourceClient=o}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(wr())({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=1500){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,start:null!=i?i:void 0},((e,t)=>{e.error?o(e):n(t)}))})),a=o.channels[this.channel];if(!a)break;if(a.sort(((e,t)=>+e.timetoken-+t.timetoken)),!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!==Pr.noReply)))}if(i=a[0].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})}}shouldCreateAsDevState(){return location.href.startsWith("https://app.meetelise.com/settings/widgets")}},Ur=(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 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};let Br=class extends re{constructor(){super(...arguments),this.onClick=()=>{},this.brandColor=Me,this.toExpand=!1}render(){return U`
3020
3020
  <div
3021
3021
  class=${this.toExpand?"button-container mini":"button-container"}
3022
3022
  @click=${this.onClick}
@@ -3511,19 +3511,19 @@ otherwise there's some empty space at the bottom of the button, which interferes
3511
3511
  transform: rotate(360deg);
3512
3512
  }
3513
3513
  }
3514
- `,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}([ae("mini-loader")],Qr);var Vr=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 Kr=class extends re{constructor(){super(...arguments),this.onMount=()=>({}),this.loadingPreviews=!0,this.websitePreviewInfo=[],this.imagesToDisplay=[],this.imageUrlError=[]}isMessageStillStreamingChunks(){if(!this.message)return!1;const e=this.message.chunks.find((e=>e.isDone));return!e||this.message.chunks.length===e.order}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=this.sanitizeMarkdownText(e),a=this.preserveHTMLTags(n);return a?U`${a.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
3515
- class="redirect-link"
3516
- href="${null==n?void 0:n.link}"
3517
- target="_blank"
3518
- rel="noopener noreferrer"
3519
- >${null==n?void 0:n.hyperlink}
3520
- </a>`}if(i.test(e)){const t=this.removeTrailingPunctuation(e);return r.push(this.getLinkData(t)),U`<a
3521
- class="redirect-link"
3522
- href="${t}"
3523
- target="_blank"
3524
- rel="noopener noreferrer"
3525
- >${t}
3526
- </a>`}return U`${Wr(Gr().sanitize(e))} `}))}<br />`:U``}))}`,this.imagesToDisplay=o,Promise.all(r).then((e=>{this.websitePreviewInfo=e}))}preserveHTMLTags(e){var t;const n=e.match(/(<\/?[a-z][^>]*>[^<]*<\/?[a-z]*>|[\w':#$()-]+[.,?!]?|\S)/gi);return null!==(t=null==n?void 0:n.filter((e=>""!==e.trim())))&&void 0!==t?t:[]}sanitizeMarkdownText(e){return e.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*?)\*\*/gim,"<b>$1</b>").replace(/\*(.*?)\*/gim,"<i>$1</i>").trim()}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="[^"]+"(?: 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)};if(n.startsWith("<a href=")){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)}}{const[e,t]=n.split("](");return{matchedLink:n,link:t?t.slice(0,-1):"",hyperlink:e?e.slice(1):"",addSpaceBefore:!(!i||" "===i),addSpaceAfter:!(!r||" "===r)}}}));return i.forEach((t=>{if(t&&t.link&&t.hyperlink){const i=Ir().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">
3514
+ `,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}([ae("mini-loader")],Qr);var Vr=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 Kr=class extends re{constructor(){super(...arguments),this.onMount=()=>({}),this.loadingPreviews=!0,this.websitePreviewInfo=[],this.imagesToDisplay=[],this.imageUrlError=[]}isMessageStillStreamingChunks(){if(!this.message)return!1;const e=this.message.chunks.find((e=>e.isDone));return!e||this.message.chunks.length===e.order}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.trim().split("\n").map((e=>{const n=this.sanitizeMarkdownText(e),a=this.preserveHTMLTags(n);return a?U`${a.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
3515
+ class="redirect-link"
3516
+ href="${null==n?void 0:n.link}"
3517
+ target="_blank"
3518
+ rel="noopener noreferrer"
3519
+ >${null==n?void 0:n.hyperlink}
3520
+ </a>`}if(i.test(e)){const t=this.removeTrailingPunctuation(e);return r.push(this.getLinkData(t)),U`<a
3521
+ class="redirect-link"
3522
+ href="${t}"
3523
+ target="_blank"
3524
+ rel="noopener noreferrer"
3525
+ >${t}
3526
+ </a>`}return U`${Wr(Gr().sanitize(e))} `}))}<br />`:U``}))}`,this.imagesToDisplay=o,Promise.all(r).then((e=>{this.websitePreviewInfo=e}))}preserveHTMLTags(e){var t;const n=e.match(/(<\/?[a-z][^>]*>[^<]*<\/?[a-z]*>|[\w':#$()-]+[.,?!]?|\S)/gi);return null!==(t=null==n?void 0:n.filter((e=>""!==e.trim())))&&void 0!==t?t:[]}sanitizeMarkdownText(e){return e.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*?)\*\*/gim,"<b>$1</b>").replace(/\*(.*?)\*/gim,"<i>$1</i>").trim()}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="[^"]+"(?: 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)};if(n.startsWith("<a href=")){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)}}{const[e,t]=n.split("](");return{matchedLink:n,link:t?t.slice(0,-1):"",hyperlink:e?e.slice(1):"",addSpaceBefore:!(!i||" "===i),addSpaceAfter:!(!r||" "===r)}}}));return i.forEach((t=>{if(t&&t.link&&t.hyperlink){const i=Ir().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">
3527
3527
  ${this.isMessageStillStreamingChunks()?U`<div class="message-loader"><mini-loader></mini-loader></div>`:""}
3528
3528
  <p
3529
3529
  class=${fe({"message-text":!0,"webchat-font__desktop":!dn(),"webchat-font__mobile":dn()})}
@@ -87,44 +87,46 @@ export class PubnubMessage extends LitElement {
87
87
  const urlRegex = /(https?:\/\/[^\s]+)/g; // Regular expression to match URLs
88
88
  const loadingWebsitePreviews: Promise<WebsitePreview>[] = [];
89
89
  const imagesToDisplay: ImageToDisplay[] = [];
90
-
91
- this.parsedMessage = html`${markedText.split("\n").map((line) => {
92
- const sanitizedLine = this.sanitizeMarkdownText(line);
93
- const allWords = this.preserveHTMLTags(sanitizedLine);
94
- if (!allWords) return html``;
95
- return html`${allWords.map((word) => {
96
- if (hyperlinks.find((obj) => obj.id === word)) {
97
- // EliseAI made hyperlink
98
- const link = hyperlinks.find((obj) => obj.id === word);
99
- if (!link) return;
100
- imagesToDisplay.push({
101
- redirectTo: link?.link,
102
- source: link?.link,
103
- });
104
- return html`<a
105
- class="redirect-link"
106
- href="${link?.link}"
107
- target="_blank"
108
- rel="noopener noreferrer"
109
- >${link?.hyperlink}
110
- </a>`;
111
- }
112
- if (urlRegex.test(word)) {
113
- // general url
114
- const link = this.removeTrailingPunctuation(word);
115
- loadingWebsitePreviews.push(this.getLinkData(link));
116
- return html`<a
117
- class="redirect-link"
118
- href="${link}"
119
- target="_blank"
120
- rel="noopener noreferrer"
121
- >${link}
122
- </a>`;
123
- } else {
124
- return html`${unsafeHTML(DOMPurify.sanitize(word))} `;
125
- }
126
- })}<br />`;
127
- })}`;
90
+ this.parsedMessage = html`${markedText
91
+ .trim()
92
+ .split("\n")
93
+ .map((line) => {
94
+ const sanitizedLine = this.sanitizeMarkdownText(line);
95
+ const allWords = this.preserveHTMLTags(sanitizedLine);
96
+ if (!allWords) return html``;
97
+ return html`${allWords.map((word) => {
98
+ if (hyperlinks.find((obj) => obj.id === word)) {
99
+ // EliseAI made hyperlink
100
+ const link = hyperlinks.find((obj) => obj.id === word);
101
+ if (!link) return;
102
+ imagesToDisplay.push({
103
+ redirectTo: link?.link,
104
+ source: link?.link,
105
+ });
106
+ return html`<a
107
+ class="redirect-link"
108
+ href="${link?.link}"
109
+ target="_blank"
110
+ rel="noopener noreferrer"
111
+ >${link?.hyperlink}
112
+ </a>`;
113
+ }
114
+ if (urlRegex.test(word)) {
115
+ // general url
116
+ const link = this.removeTrailingPunctuation(word);
117
+ loadingWebsitePreviews.push(this.getLinkData(link));
118
+ return html`<a
119
+ class="redirect-link"
120
+ href="${link}"
121
+ target="_blank"
122
+ rel="noopener noreferrer"
123
+ >${link}
124
+ </a>`;
125
+ } else {
126
+ return html`${unsafeHTML(DOMPurify.sanitize(word))} `;
127
+ }
128
+ })}<br />`;
129
+ })}`;
128
130
  this.imagesToDisplay = imagesToDisplay;
129
131
  Promise.all(loadingWebsitePreviews).then((results) => {
130
132
  this.websitePreviewInfo = results;
@@ -3,7 +3,6 @@ import { v4 as uuid } from "uuid";
3
3
  import formatISO from "date-fns/formatISO";
4
4
  import { isTimestampExpired } from "./utils";
5
5
  import isBefore from "date-fns/isBefore";
6
- import isAfter from "date-fns/isAfter";
7
6
 
8
7
  export interface ChatStorageKey {
9
8
  leadId: string | null;
@@ -82,11 +81,7 @@ export const isChatKeyValid = (
82
81
  try {
83
82
  if (storageValue.timestamp && storageValue.initiatedChat) {
84
83
  const topBoundaryTimestamp = new Date("2024-06-06T21:30:00Z");
85
- const bottomBoundaryTimestamp = new Date("2024-06-06T18:30:00Z");
86
- if (
87
- isBefore(storageValue.timestamp, topBoundaryTimestamp) &&
88
- isAfter(storageValue.timestamp, bottomBoundaryTimestamp)
89
- ) {
84
+ if (isBefore(storageValue.timestamp, topBoundaryTimestamp)) {
90
85
  return false;
91
86
  }
92
87
  }