@meetelise/chat 1.51.12 → 1.51.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/public/dist/index.js
CHANGED
|
@@ -6044,7 +6044,7 @@ xmlns="http://www.w3.org/2000/svg"
|
|
|
6044
6044
|
${Wa}
|
|
6045
6045
|
${Va}
|
|
6046
6046
|
${qa}
|
|
6047
|
-
`,Hl([ue({attribute:!0})],Gl.prototype,"isMinimized",void 0),Hl([ue()],Gl.prototype,"mobileStyles",void 0),Hl([ue({type:Boolean})],Gl.prototype,"isFirstMount",void 0),Hl([ue({attribute:!1})],Gl.prototype,"autoOpenChatWidget",void 0),Hl([ue()],Gl.prototype,"phoneNumber",void 0),Hl([ue({attribute:!0})],Gl.prototype,"buildingName",void 0),Hl([ue({attribute:!0})],Gl.prototype,"chatId",void 0),Hl([ue({attribute:!0})],Gl.prototype,"orgLegalName",void 0),Hl([ue({attribute:!1})],Gl.prototype,"country",void 0),Hl([ue({attribute:!0})],Gl.prototype,"chatCallUsHeader",void 0),Hl([ue({attribute:!1})],Gl.prototype,"buildingId",void 0),Hl([ue({type:Number})],Gl.prototype,"orgId",void 0),Hl([ue({attribute:!1})],Gl.prototype,"leadSourceParams",void 0),Hl([ue({attribute:!0})],Gl.prototype,"buildingSlug",void 0),Hl([ue({attribute:!0})],Gl.prototype,"orgSlug",void 0),Hl([ue({attribute:!0})],Gl.prototype,"sgtUrl",void 0),Hl([ue({attribute:!0})],Gl.prototype,"selfGuidedTourEnabled",void 0),Hl([ue({attribute:!0})],Gl.prototype,"selfGuidedToursTypeOffered",void 0),Hl([ue({attribute:!0})],Gl.prototype,"designConcept",void 0),Hl([ue({attribute:!0})],Gl.prototype,"featureFlagShowDropdown",void 0),Hl([ue({attribute:!1})],Gl.prototype,"leadSources",void 0),Hl([ue({attribute:!0})],Gl.prototype,"currentLeadSource",void 0),Hl([ue({attribute:!0})],Gl.prototype,"escortedToursLink",void 0),Hl([ue({attribute:!0})],Gl.prototype,"escortedToursTypeOffered",void 0),Hl([ue({attribute:!0})],Gl.prototype,"virtualToursLink",void 0),Hl([ue({attribute:!0})],Gl.prototype,"virtualToursTypeOffered",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasChatEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasChatEnabledMobile",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasEmailEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasEmailEnabledMobile",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasApplyNowEnabledDesktop",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasApplyNowEnabledMobile",void 0),Hl([ue({attribute:!0})],Gl.prototype,"applicationLink",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasCallUsEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasCallUsEnabledMobile",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasTextUsEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasTextUsEnabledMobile",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasSSTEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasSSTEnabledMobile",void 0),Hl([ue({attribute:!1})],Gl.prototype,"tourTypeOptions",void 0),Hl([ue({attribute:!1})],Gl.prototype,"layoutOptions",void 0),Hl([ue({attribute:!0})],Gl.prototype,"bedroomPreferenceRequired",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasDynamicSchedulingEnabled",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasPricingCalculatorEnabledDesktop",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasPricingCalculatorEnabledMobile",void 0),Hl([ue({attribute:!1})],Gl.prototype,"hasHideMobileFeatures",void 0),Hl([ue({type:Number})],Gl.prototype,"right",void 0),Hl([ue({type:Number})],Gl.prototype,"bottom",void 0),Hl([ue({type:Number})],Gl.prototype,"top",void 0),Hl([ue({type:Number})],Gl.prototype,"left",void 0),Hl([ue({attribute:!0})],Gl.prototype,"showTourNextToChat",void 0),Hl([ue({attribute:!1})],Gl.prototype,"onChatTapped",void 0),Hl([ue({attribute:!0})],Gl.prototype,"onClickMinimize",void 0),Hl([ue({attribute:!0})],Gl.prototype,"onSstClose",void 0),Hl([ue({attribute:!0})],Gl.prototype,"overrideRentgrata",void 0),Hl([ue({attribute:!1})],Gl.prototype,"launcherStyles",void 0),Hl([ue({attribute:!0})],Gl.prototype,"primaryColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"backgroundColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"foregroundColorOnPrimaryBackgroundColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"foregroundColorOnSecondaryBackgroundColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"leadSourceClient",void 0),Hl([de()],Gl.prototype,"leadSourceMultitouchClient",void 0),Hl([de()],Gl.prototype,"_isMobile",void 0),Hl([de()],Gl.prototype,"isEmailWindowOpen",void 0),Hl([de()],Gl.prototype,"isCallUsWindowOpen",void 0),Hl([de()],Gl.prototype,"isSSTWindowOpen",void 0),Hl([de()],Gl.prototype,"isTextUsWindowOpen",void 0),Hl([de()],Gl.prototype,"isCalculatorWindowOpen",void 0),Hl([de()],Gl.prototype,"isMobileFeaturesExpanded",void 0),Gl=Hl([se("meetelise-launcher")],Gl);const zl=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",Gl)},Ql=["app.meetelise.com","staging.eliseai.com","localhost"],Wl={calculator:{desktop:"calcDesktop",mobile:"calcMobile"},email:{desktop:"emailDesktop",mobile:"emailMobile"},call:{desktop:"callDesktop",mobile:"callMobile"},text:{desktop:"textDesktop",mobile:"textMobile"},sst:{desktop:"sstDesktop",mobile:"sstMobile"}},Vl=e=>{const t=window.location.hostname;if(!Ql.includes(t))return e;const n=(e=>{if(!e)return{};try{return e.split(",").reduce((e,t)=>{const[n,i]=t.split(":");return n&&i&&n in Wl&&(e[n]="true"===i.toLowerCase()),e},{})}catch(e){return{}}})(new URLSearchParams(window.location.search).get("widgets"));if(0===Object.keys(n).length)return e;const i={...e};return Object.entries(n).forEach(([e,t])=>{const n=Wl[e];n&&(i[n.desktop]=t,i[n.mobile]=t)}),i};var ql=n(5072),Yl=n.n(ql),Kl=n(7825),Xl=n.n(Kl),Zl=n(7659),Jl=n.n(Zl),eu=n(5056),tu=n.n(eu),nu=n(540),iu=n.n(nu),ru=n(1113),ou=n.n(ru),au=n(5541),su={};su.styleTagTransform=ou(),su.setAttributes=tu(),su.insert=Jl().bind(null,"head"),su.domAPI=Xl(),su.insertStyleElement=iu();Yl()(au.A,su);au.A&&au.A.locals&&au.A.locals;async function lu(e,t){try{const n=await r().get(`https://app.meetelise.com/platformApi/webchat/${t}/lead-sources`);if(n.data){if("7e352741-1120-4ccf-9929-5dc99193a908"===e){const e=["Zillow","Apartments.com","Google PPC","Google Maps","Apple Maps","Social Media","Print Marketing"];return n.data.filter(t=>e.includes(t))}return uu(n.data,t)}return[]}catch(e){return[]}}const uu=(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)})};async function du(e){var t,n;if(!e)return!1;try{return null!==(n=null===(t=(await r().get(`https://app.meetelise.com/platformApi/webchat/${e}/aip`)).data)||void 0===t?void 0:t.is_aip)&&void 0!==n&&n}catch(e){return!1}}var cu,hu=n(8805),pu=n.n(hu),fu=new Uint8Array(16);function gu(){if(!cu&&!(cu="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 cu(fu)}const mu=/^(?:[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;const yu=function(e){return"string"==typeof e&&mu.test(e)};for(var bu=[],vu=0;vu<256;++vu)bu.push((vu+256).toString(16).substr(1));const wu=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(bu[e[t+0]]+bu[e[t+1]]+bu[e[t+2]]+bu[e[t+3]]+"-"+bu[e[t+4]]+bu[e[t+5]]+"-"+bu[e[t+6]]+bu[e[t+7]]+"-"+bu[e[t+8]]+bu[e[t+9]]+"-"+bu[e[t+10]]+bu[e[t+11]]+bu[e[t+12]]+bu[e[t+13]]+bu[e[t+14]]+bu[e[t+15]]).toLowerCase();if(!yu(n))throw TypeError("Stringified UUID is invalid");return n};const Cu=function(e,t,n){var i=(e=e||{}).random||(e.rng||gu)();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 wu(i)},xu=e=>localStorage.removeItem("com.elise.webchat.slug="+e),$u=(e,t,n)=>{const i=Br(new Date),r=n||`lead_${Cu()}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:Vr(i),buildingSlug:e,initiatedChat:t}},Su=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(Au(e,i))return i}catch(e){}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Au=(e,t)=>{try{if(t.timestamp&&t.initiatedChat){const e=new Date("2024-06-06T21:30:00Z");if($r(t.timestamp,e))return!1}}catch(e){}return!(t.buildingSlug!==e||!t.leadId||!t.timestamp)&&!Ir(t.timestamp,24)};var Eu;!function(e){e.noReply="no-reply",e.text="text",e.media="media"}(Eu||(Eu={}));const Tu=e=>e.type===_u.text,ku=e=>e.type===_u.media;var _u;!function(e){e.text="text",e.media="media"}(_u||(_u={}));const Ou=class{constructor(e,t,n,i=null,r,o,a=null,s=Ic.Default){this.apiHost="https://app.meetelise.com",this.leadSourceClient=null,this.leadSourceMultitouchClient=null,this.buildingWebchatView=null,this.eliseResponseTimeout=null,this.isWaitingForStreamingMessages=!1,this.firedScheduledTourConfirmationIds=new Set,this.widgetType=Ic.Default,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.sessionToken=null,this.isCurrentlyStreamingMessage=!1,this.chatListener=null,this.rawPubnubMessages=[],this.simpleChatMessages=[],this.listenerParams={message:e=>{var t;const n={channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken};this.rawPubnubMessages=[...this.rawPubnubMessages,n],this.markEveryPreviousNoReplyMessageDone(this.rawPubnubMessages),this.rawPubnubMessages=this.rawPubnubMessages.filter(e=>e.message.messageType!==Eu.noReply),this.simpleChatMessages=this.translatePubnubMessagesIntoSimpleChatMessages(this.rawPubnubMessages),this.checkAndHandleDelayStreamingMessages();const i="eliseai"!==e.publisher&&"elise_health_ai"!==e.publisher;if(null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.simpleChatMessages,isLoading:i}),!i&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=i,"ai_message"===e.message.customType){const t=e.message.stream_id,n=null!=t?t:String(+e.timetoken);(t?this.reconstructStreamText(t):e.message.text).includes("confirmed for your")&&this.fireScheduledTourEventOnce(n,e.message)}this.checkAndHandleGTMForLeadEmail(e)}},this.isLoadingMessages=!1,this.isFirstChatMessageSent=!1,this.streamingMessageTimeout=null,this.checkAndHandleDelayStreamingMessages=({delayToFetchHistoryInMs:e=1e4}={})=>{this.streamingMessageTimeout&&(clearTimeout(this.streamingMessageTimeout),this.streamingMessageTimeout=null);const t=new Map;this.rawPubnubMessages.forEach(e=>{var n;const i=e.message.stream_id;i&&t.set(i,[...null!==(n=t.get(i))&&void 0!==n?n:[],e])});const n=[...t.entries()].filter(([,e])=>!this.isStreamComplete(e)).map(([e])=>e);n.length>0&&(this.streamingMessageTimeout=setTimeout(()=>{Ho({logTitle:"PUBNUB_WARN_DELAYED_STREAMING_MESSAGES",logData:{channel:this.channel},logType:Fo.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),this.getChannelHistory().then(()=>n.forEach(e=>this.checkAndFireTourConfirmationForStream(e)))},e))},this.isStreamComplete=e=>{var t;const n=e.find(e=>e.message.is_done);if(!n)return!1;const i=new Set(e.map(e=>{var t;return null!==(t=e.message.order)&&void 0!==t?t:0}));for(let e=0;e<=(null!==(t=n.message.order)&&void 0!==t?t:0);e++)if(!i.has(e))return!1;return!0},this.getStreamChunks=e=>this.removeDuplicatedRawPubnubMessages(this.rawPubnubMessages).filter(t=>t.message.stream_id===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)}),this.reconstructStreamText=e=>this.getStreamChunks(e).map(e=>e.message.text).join(""),this.fireScheduledTourEventOnce=(e,t)=>{var n;this.firedScheduledTourConfirmationIds.has(e)||(this.firedScheduledTourConfirmationIds.add(e),$o("scheduledTourEvent",{tourDetails:t,buildingId:null===(n=this.buildingWebchatView)||void 0===n?void 0:n.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel}))},this.checkAndFireTourConfirmationForStream=e=>{var t;if(this.reconstructStreamText(e).includes("confirmed for your")){const n=this.getStreamChunks(e);this.fireScheduledTourEventOnce(e,null===(t=n[n.length-1])||void 0===t?void 0:t.message)}},this.checkAndHandleGTMForLeadEmail=e=>{var t;try{if("lead_message"!==e.message.customType)return;if(!(e=>{try{return/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b/.test(e)}catch(e){return!1}})(e.message.text))return;$o("leadProvidedEmail",{buildingId:null===(t=this.buildingWebchatView)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel})}catch(e){return}},this.markEveryPreviousNoReplyMessageDone=e=>{var t,n;for(let i=e.length-1;i>=0;i--){const r=null===(t=e[i])||void 0===t?void 0:t.message,o=i>0&&(null===(n=e[i-1])||void 0===n?void 0:n.message);(null==r?void 0:r.messageType)===Eu.noReply&&o&&(o.is_done=!0)}},this.checkMessageChunkValid=e=>{try{return!!e.message&&!!e.message.text&&e.message.text.length>0&&!!e.message.customType}catch(e){return!1}},this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}},this.handleDisconnect=()=>{this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.streamingMessageTimeout&&(clearTimeout(this.streamingMessageTimeout),this.streamingMessageTimeout=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=$u(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))return}await this.withAuthToken(async()=>{var t,n,i,r,o,a,s,l,u;this.pubnub&&this.channel&&(this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.eliseResponseTimeout=setTimeout(()=>{this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:Fo.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})),this.widgetType===Ic.Utilities?await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",widgetType:this.widgetType,isDevState:this.shouldCreateAsDevState(),orgSlug:this.orgSlug}}):(await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(n=this.buildingWebchatView)||void 0===n?void 0:n.id,buildingSlug:this.buildingSlug,userId:null===(i=this.buildingWebchatView)||void 0===i?void 0:i.userId,leadSource:this.leadSource,widgetType:this.widgetType,isDevState:this.shouldCreateAsDevState(),lead_sources_with_timestamps:(null!==(o=null===(r=this.leadSourceMultitouchClient)||void 0===r?void 0:r.getSafeLeadSourceTouchpointsWithDefault({includedUserSelectedLeadSource:null}))&&void 0!==o?o:[]).map(e=>Tr({...e}))}}),null===(a=this.leadSourceClient)||void 0===a||a.resetLeadSource(),null===(s=this.leadSourceMultitouchClient)||void 0===s||s.resetLeadSourceTouchpoints()),this.isFirstChatMessageSent||($o("firstChatMessageSent",{message:e,buildingId:null===(l=this.buildingWebchatView)||void 0===l?void 0:l.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel}),this.isFirstChatMessageSent=!0),$o("chatMessageSent",{message:e,buildingId:null===(u=this.buildingWebchatView)||void 0===u?void 0:u.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel}))}),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.removeDuplicatedRawPubnubMessages=e=>{const t=new Set;return e.filter(e=>{if("lead_message"===e.message.customType||!e.message.stream_id||!e.message.order)return!0;const n=`${e.message.stream_id}-${e.message.order}-${e.message.messageType}`;return t.has(n)?(Ho({logTitle:"PUBNUB_WARN_DUPLICATE_MESSAGE",logData:{message:e,channel:this.channel},logType:Fo.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),!1):(t.add(n),!0)})},this.translatePubnubMessagesIntoSimpleChatMessages=e=>{const t=[],n={};return this.removeDuplicatedRawPubnubMessages(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:_u.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:_u.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:_u.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.buildingWebchatView=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`,this.leadSourceClient=a,this.leadSourceMultitouchClient=o,this.widgetType=s}async initSession(e,t,n){try{const i={building_slug:e,org_slug:t};n&&(i.lead_id=n);const o=await r().post(`${this.apiHost}/platformApi/webchat/init`,i);return this.sessionToken=o.data.session_token,this.leadUserId=o.data.lead_id,this.channel=o.data.channel,o.data}catch(e){return this.buildingWebchatView&&Ho({logTitle:"WEBCHAT_INIT_SESSION_ERROR",logData:{error:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e}),null}}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(pu())({publishKey:t.keys.publish_key,subscribeKey:t.keys.subscribe_key,userId:this.leadUserId,authKey:t.auth.result.token,origin:"meetelise.pubnubapi.com"}),this.withAuthToken(()=>new Promise(()=>this.handleChatListeners())),await this.withAuthToken(()=>this.getChannelHistory()),this.pubnub):void 0}async fetchToken(e,t){try{if(this.sessionToken){const e="healthcare"===this.widgetType?"?industry=health_care":"";return(await r().get(`${this.apiHost}/platformApi/webchat/pn/v2/request-token${e}`,{headers:{"X-Session-Token":this.sessionToken}})).data}return(await r().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${t}&${"healthcare"===this.widgetType?"industry=health_care":""}`)).data}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}return null}async fetchChannelExists(e){try{return(await r().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}return!1}async withAuthToken(e){try{await e()}catch(t){if(t instanceof i.AxiosError&&t&&t.response&&403===t.response.status)try{if(!this.pubnub||!this.leadUserId||!this.channel)return;const t=await this.fetchToken(this.leadUserId,this.channel);if(!t)return;this.pubnub.setAuthKey(t.auth.result.token),await e()}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}}}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})}),this.markEveryPreviousNoReplyMessageDone(t),n=n.concat(t.filter(e=>e.message.messageType!==Eu.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.buildingWebchatView&&Ho({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:Fo.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}}shouldCreateAsDevState(){return location.href.startsWith("https://app.meetelise.com/settings/widgets")||location.href.includes("demo/utilities")}},Pu=new Set(["8009855990","8338526262","8002221222","8006624357","8002738255","8007997233","8007874889","8006564673","8004224453","8883737888","8006213362","8009506264","8558272736","8008435678","8007862929","8008523836","8007849433","8007729100","8006699777","8006858470","8004322209","8003473735","8008778339","8009552232","8002255342","8009272891","8003049320","8007937724","8002382333","8003353863","8776858878","8003329227","8776554371","8772944357","8772944356","6092925760","6092926735","8007928339","8008329173","8882853036","6092921210","8007929773","8003561561","8003826717","8005727233","8009291040","8888958179","8006879512","8004262537","8773475463","8774149251","8005103102","8889372835","8007010710","8007010720","8774288844","8007929745","8003283838","6092927060","6092928319","8008527899","8662401347","8009923678","8776522873","8776527624","8003313937","8008435437","8776536783","8778392339","8003676274","8006896411"]),Iu=e=>{const t=e.replace(/\D/g,"").replace(/^1(\d{10})$/,"$1");return Pu.has(t)},Nu=(e,t,n)=>{try{const i=e.replace(/\D/g,"").replace(/^1(\d{10})$/,"$1"),r=`tel:${i}`,o=`sms:${i}`,a=`whatsapp://send?phone=${i}`,s=`facetime:${i}`,l=`facetime-audio:${i}`,u=/(?:\+1[\s.-]?)?(?:\(\d{3}\)[\s.-]?|\d{3}[\s.-])\d{3}[\s.-]?\d{4}/g,d=/(tel|sms):(?:\+1\s)?(?:(?:\(\d{3}\)\s|\d{3}-)\d{3}-\d{4}|\d{10,11})/g,c=/whatsapp:\/\/send\?phone=\d+/g,h=/(facetime|facetime-audio):\d+/g,p=/emergency|emergencia/i,f=300,g=e=>!(!e||e.length>f)&&p.test(e),m=e=>{var t,n,i,r;if(g(e.textContent))return!0;if(g(null===(t=e.previousElementSibling)||void 0===t?void 0:t.textContent)||g(null===(n=e.nextElementSibling)||void 0===n?void 0:n.textContent))return!0;const o=e.parentElement;return!(!o||!g(null===(i=o.previousElementSibling)||void 0===i?void 0:i.textContent)&&!g(null===(r=o.nextElementSibling)||void 0===r?void 0:r.textContent))},y=document.body.getElementsByTagName("*");let b=!1;const v=i.replace(/(\d{3})(\d{3})(\d{4})/,"($1) $2-$3");let w=!1,C=!1,x=0;for(let e=0;e<y.length;e++)if(y[e].nodeType===Node.ELEMENT_NODE&&!m(y[e])){if(1===y[e].childNodes.length&&y[e].childNodes[0].nodeType==Node.TEXT_NODE){const t=y[e].textContent;if(!t)continue;const n=t.replace(u,e=>{if(Iu(e))return e;return e.startsWith("+1 ")?`+1 ${v}`:v});t!==n&&(x++,y[e].textContent=n),b=!0,w||(w=!0)}if(y[e].hasAttribute("href")){const t=y[e].getAttribute("href");if(!t)continue;let n="",i=d;if(t.startsWith("sms:")?n=o:t.startsWith("whatsapp:")?(n=a,i=c):t.startsWith("facetime:")?(n=s,i=h):t.startsWith("facetime-audio:")?(n=l,i=h):n=r,Iu(t))continue;const u=t.replace(i,n);if(y[e].setAttribute("href",u),(t.startsWith("tel:")||t.startsWith("sms:"))&&u===t&&u!==n){t.replace(/\D/g,"").length>=7&&y[e].setAttribute("href",t.startsWith("tel:")?r:o)}C||(C=!0)}}return w&&Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"text-insertion",newPhoneNumber:v,website:window.location.href},logType:Fo.info,buildingSlug:n,orgSlug:t}),C&&Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"href-insertion",newPhoneNumber:v,website:window.location.href},logType:Fo.info,buildingSlug:n,orgSlug:t}),b||Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"no-phone-number-found",website:window.location.href},logType:Fo.warn,buildingSlug:n,orgSlug:t}),x}catch(e){return Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"insertion-error",error:e instanceof Error?e.message:String(e),website:window.location.href},logType:Fo.error,buildingSlug:n,orgSlug:t,error:e}),0}};var Mu=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 Du=class extends oe{constructor(){super(...arguments),this.onClick=()=>{},this.primaryColor=qn,this.foregroundColorOnPrimaryBackgroundColor="white",this.toExpand=!1}render(){return R`
|
|
6047
|
+
`,Hl([ue({attribute:!0})],Gl.prototype,"isMinimized",void 0),Hl([ue()],Gl.prototype,"mobileStyles",void 0),Hl([ue({type:Boolean})],Gl.prototype,"isFirstMount",void 0),Hl([ue({attribute:!1})],Gl.prototype,"autoOpenChatWidget",void 0),Hl([ue()],Gl.prototype,"phoneNumber",void 0),Hl([ue({attribute:!0})],Gl.prototype,"buildingName",void 0),Hl([ue({attribute:!0})],Gl.prototype,"chatId",void 0),Hl([ue({attribute:!0})],Gl.prototype,"orgLegalName",void 0),Hl([ue({attribute:!1})],Gl.prototype,"country",void 0),Hl([ue({attribute:!0})],Gl.prototype,"chatCallUsHeader",void 0),Hl([ue({attribute:!1})],Gl.prototype,"buildingId",void 0),Hl([ue({type:Number})],Gl.prototype,"orgId",void 0),Hl([ue({attribute:!1})],Gl.prototype,"leadSourceParams",void 0),Hl([ue({attribute:!0})],Gl.prototype,"buildingSlug",void 0),Hl([ue({attribute:!0})],Gl.prototype,"orgSlug",void 0),Hl([ue({attribute:!0})],Gl.prototype,"sgtUrl",void 0),Hl([ue({attribute:!0})],Gl.prototype,"selfGuidedTourEnabled",void 0),Hl([ue({attribute:!0})],Gl.prototype,"selfGuidedToursTypeOffered",void 0),Hl([ue({attribute:!0})],Gl.prototype,"designConcept",void 0),Hl([ue({attribute:!0})],Gl.prototype,"featureFlagShowDropdown",void 0),Hl([ue({attribute:!1})],Gl.prototype,"leadSources",void 0),Hl([ue({attribute:!0})],Gl.prototype,"currentLeadSource",void 0),Hl([ue({attribute:!0})],Gl.prototype,"escortedToursLink",void 0),Hl([ue({attribute:!0})],Gl.prototype,"escortedToursTypeOffered",void 0),Hl([ue({attribute:!0})],Gl.prototype,"virtualToursLink",void 0),Hl([ue({attribute:!0})],Gl.prototype,"virtualToursTypeOffered",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasChatEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasChatEnabledMobile",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasEmailEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasEmailEnabledMobile",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasApplyNowEnabledDesktop",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasApplyNowEnabledMobile",void 0),Hl([ue({attribute:!0})],Gl.prototype,"applicationLink",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasCallUsEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasCallUsEnabledMobile",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasTextUsEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasTextUsEnabledMobile",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasSSTEnabledDesktop",void 0),Hl([ue({type:Boolean})],Gl.prototype,"hasSSTEnabledMobile",void 0),Hl([ue({attribute:!1})],Gl.prototype,"tourTypeOptions",void 0),Hl([ue({attribute:!1})],Gl.prototype,"layoutOptions",void 0),Hl([ue({attribute:!0})],Gl.prototype,"bedroomPreferenceRequired",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasDynamicSchedulingEnabled",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasPricingCalculatorEnabledDesktop",void 0),Hl([ue({attribute:!0})],Gl.prototype,"hasPricingCalculatorEnabledMobile",void 0),Hl([ue({attribute:!1})],Gl.prototype,"hasHideMobileFeatures",void 0),Hl([ue({type:Number})],Gl.prototype,"right",void 0),Hl([ue({type:Number})],Gl.prototype,"bottom",void 0),Hl([ue({type:Number})],Gl.prototype,"top",void 0),Hl([ue({type:Number})],Gl.prototype,"left",void 0),Hl([ue({attribute:!0})],Gl.prototype,"showTourNextToChat",void 0),Hl([ue({attribute:!1})],Gl.prototype,"onChatTapped",void 0),Hl([ue({attribute:!0})],Gl.prototype,"onClickMinimize",void 0),Hl([ue({attribute:!0})],Gl.prototype,"onSstClose",void 0),Hl([ue({attribute:!0})],Gl.prototype,"overrideRentgrata",void 0),Hl([ue({attribute:!1})],Gl.prototype,"launcherStyles",void 0),Hl([ue({attribute:!0})],Gl.prototype,"primaryColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"backgroundColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"foregroundColorOnPrimaryBackgroundColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"foregroundColorOnSecondaryBackgroundColor",void 0),Hl([ue({attribute:!0})],Gl.prototype,"leadSourceClient",void 0),Hl([de()],Gl.prototype,"leadSourceMultitouchClient",void 0),Hl([de()],Gl.prototype,"_isMobile",void 0),Hl([de()],Gl.prototype,"isEmailWindowOpen",void 0),Hl([de()],Gl.prototype,"isCallUsWindowOpen",void 0),Hl([de()],Gl.prototype,"isSSTWindowOpen",void 0),Hl([de()],Gl.prototype,"isTextUsWindowOpen",void 0),Hl([de()],Gl.prototype,"isCalculatorWindowOpen",void 0),Hl([de()],Gl.prototype,"isMobileFeaturesExpanded",void 0),Gl=Hl([se("meetelise-launcher")],Gl);const zl=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",Gl)},Ql=["app.meetelise.com","staging.eliseai.com","localhost"],Wl={calculator:{desktop:"calcDesktop",mobile:"calcMobile"},email:{desktop:"emailDesktop",mobile:"emailMobile"},call:{desktop:"callDesktop",mobile:"callMobile"},text:{desktop:"textDesktop",mobile:"textMobile"},sst:{desktop:"sstDesktop",mobile:"sstMobile"}},Vl=e=>{const t=window.location.hostname;if(!Ql.includes(t))return e;const n=(e=>{if(!e)return{};try{return e.split(",").reduce((e,t)=>{const[n,i]=t.split(":");return n&&i&&n in Wl&&(e[n]="true"===i.toLowerCase()),e},{})}catch(e){return{}}})(new URLSearchParams(window.location.search).get("widgets"));if(0===Object.keys(n).length)return e;const i={...e};return Object.entries(n).forEach(([e,t])=>{const n=Wl[e];n&&(i[n.desktop]=t,i[n.mobile]=t)}),i};var ql=n(5072),Yl=n.n(ql),Kl=n(7825),Xl=n.n(Kl),Zl=n(7659),Jl=n.n(Zl),eu=n(5056),tu=n.n(eu),nu=n(540),iu=n.n(nu),ru=n(1113),ou=n.n(ru),au=n(5541),su={};su.styleTagTransform=ou(),su.setAttributes=tu(),su.insert=Jl().bind(null,"head"),su.domAPI=Xl(),su.insertStyleElement=iu();Yl()(au.A,su);au.A&&au.A.locals&&au.A.locals;async function lu(e,t){try{const n=await r().get(`https://app.meetelise.com/platformApi/webchat/${t}/lead-sources`);if(n.data){if("7e352741-1120-4ccf-9929-5dc99193a908"===e){const e=["Zillow","Apartments.com","Google PPC","Google Maps","Apple Maps","Social Media","Print Marketing"];return n.data.filter(t=>e.includes(t))}return uu(n.data,t)}return[]}catch(e){return[]}}const uu=(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)})};async function du(e){var t,n;if(!e)return!1;try{return null!==(n=null===(t=(await r().get(`https://app.meetelise.com/platformApi/webchat/${e}/aip`)).data)||void 0===t?void 0:t.is_aip)&&void 0!==n&&n}catch(e){return!1}}var cu,hu=n(8805),pu=n.n(hu),fu=new Uint8Array(16);function gu(){if(!cu&&!(cu="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 cu(fu)}const mu=/^(?:[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;const yu=function(e){return"string"==typeof e&&mu.test(e)};for(var bu=[],vu=0;vu<256;++vu)bu.push((vu+256).toString(16).substr(1));const wu=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(bu[e[t+0]]+bu[e[t+1]]+bu[e[t+2]]+bu[e[t+3]]+"-"+bu[e[t+4]]+bu[e[t+5]]+"-"+bu[e[t+6]]+bu[e[t+7]]+"-"+bu[e[t+8]]+bu[e[t+9]]+"-"+bu[e[t+10]]+bu[e[t+11]]+bu[e[t+12]]+bu[e[t+13]]+bu[e[t+14]]+bu[e[t+15]]).toLowerCase();if(!yu(n))throw TypeError("Stringified UUID is invalid");return n};const Cu=function(e,t,n){var i=(e=e||{}).random||(e.rng||gu)();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 wu(i)},xu=e=>localStorage.removeItem("com.elise.webchat.slug="+e),$u=(e,t,n)=>{const i=Br(new Date),r=n||`lead_${Cu()}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:Vr(i),buildingSlug:e,initiatedChat:t}},Su=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(Au(e,i))return i}catch(e){}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Au=(e,t)=>{try{if(t.timestamp&&t.initiatedChat){const e=new Date("2024-06-06T21:30:00Z");if($r(t.timestamp,e))return!1}}catch(e){}return!(t.buildingSlug!==e||!t.leadId||!t.timestamp)&&!Ir(t.timestamp,24)};var Eu;!function(e){e.noReply="no-reply",e.text="text",e.media="media"}(Eu||(Eu={}));const Tu=e=>e.type===_u.text,ku=e=>e.type===_u.media;var _u;!function(e){e.text="text",e.media="media"}(_u||(_u={}));const Ou=class{constructor(e,t,n,i=null,r,o,a=null,s=Ic.Default){this.apiHost="https://app.meetelise.com",this.leadSourceClient=null,this.leadSourceMultitouchClient=null,this.buildingWebchatView=null,this.eliseResponseTimeout=null,this.isWaitingForStreamingMessages=!1,this.firedScheduledTourConfirmationIds=new Set,this.widgetType=Ic.Default,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.sessionToken=null,this.isCurrentlyStreamingMessage=!1,this.chatListener=null,this.rawPubnubMessages=[],this.simpleChatMessages=[],this.listenerParams={message:e=>{var t;const n={channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken};this.rawPubnubMessages=[...this.rawPubnubMessages,n],this.markEveryPreviousNoReplyMessageDone(this.rawPubnubMessages),this.rawPubnubMessages=this.rawPubnubMessages.filter(e=>e.message.messageType!==Eu.noReply),this.simpleChatMessages=this.translatePubnubMessagesIntoSimpleChatMessages(this.rawPubnubMessages),this.checkAndHandleDelayStreamingMessages();const i="eliseai"!==e.publisher&&"elise_health_ai"!==e.publisher;if(null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.simpleChatMessages,isLoading:i}),!i&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=i,"ai_message"===e.message.customType){const t=e.message.stream_id,n=null!=t?t:String(+e.timetoken);(t?this.reconstructStreamText(t):e.message.text).includes("confirmed for your")&&this.fireScheduledTourEventOnce(n,e.message)}this.checkAndHandleGTMForLeadEmail(e)}},this.isLoadingMessages=!1,this.isFirstChatMessageSent=!1,this.streamingMessageTimeout=null,this.checkAndHandleDelayStreamingMessages=({delayToFetchHistoryInMs:e=1e4}={})=>{this.streamingMessageTimeout&&(clearTimeout(this.streamingMessageTimeout),this.streamingMessageTimeout=null);const t=new Map;this.rawPubnubMessages.forEach(e=>{var n;const i=e.message.stream_id;i&&t.set(i,[...null!==(n=t.get(i))&&void 0!==n?n:[],e])});const n=[...t.entries()].filter(([,e])=>!this.isStreamComplete(e)).map(([e])=>e);n.length>0&&(this.streamingMessageTimeout=setTimeout(()=>{Ho({logTitle:"PUBNUB_WARN_DELAYED_STREAMING_MESSAGES",logData:{channel:this.channel},logType:Fo.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),this.getChannelHistory().then(()=>n.forEach(e=>this.checkAndFireTourConfirmationForStream(e)))},e))},this.isStreamComplete=e=>{var t;const n=e.find(e=>e.message.is_done);if(!n)return!1;const i=new Set(e.map(e=>{var t;return null!==(t=e.message.order)&&void 0!==t?t:0}));for(let e=0;e<=(null!==(t=n.message.order)&&void 0!==t?t:0);e++)if(!i.has(e))return!1;return!0},this.getStreamChunks=e=>this.removeDuplicatedRawPubnubMessages(this.rawPubnubMessages).filter(t=>t.message.stream_id===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)}),this.reconstructStreamText=e=>this.getStreamChunks(e).map(e=>e.message.text).join(""),this.fireScheduledTourEventOnce=(e,t)=>{var n;this.firedScheduledTourConfirmationIds.has(e)||(this.firedScheduledTourConfirmationIds.add(e),$o("scheduledTourEvent",{tourDetails:t,buildingId:null===(n=this.buildingWebchatView)||void 0===n?void 0:n.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel}))},this.checkAndFireTourConfirmationForStream=e=>{var t;if(this.reconstructStreamText(e).includes("confirmed for your")){const n=this.getStreamChunks(e);this.fireScheduledTourEventOnce(e,null===(t=n[n.length-1])||void 0===t?void 0:t.message)}},this.checkAndHandleGTMForLeadEmail=e=>{var t;try{if("lead_message"!==e.message.customType)return;if(!(e=>{try{return/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b/.test(e)}catch(e){return!1}})(e.message.text))return;$o("leadProvidedEmail",{buildingId:null===(t=this.buildingWebchatView)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel})}catch(e){return}},this.markEveryPreviousNoReplyMessageDone=e=>{var t,n;for(let i=e.length-1;i>=0;i--){const r=null===(t=e[i])||void 0===t?void 0:t.message,o=i>0&&(null===(n=e[i-1])||void 0===n?void 0:n.message);(null==r?void 0:r.messageType)===Eu.noReply&&o&&(o.is_done=!0)}},this.checkMessageChunkValid=e=>{try{return!!e.message&&!!e.message.text&&e.message.text.length>0&&!!e.message.customType}catch(e){return!1}},this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}},this.handleDisconnect=()=>{this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.streamingMessageTimeout&&(clearTimeout(this.streamingMessageTimeout),this.streamingMessageTimeout=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=$u(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))return}await this.withAuthToken(async()=>{var t,n,i,r,o,a,s,l,u;this.pubnub&&this.channel&&(this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.eliseResponseTimeout=setTimeout(()=>{this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:Fo.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})),this.widgetType===Ic.Utilities?await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",widgetType:this.widgetType,isDevState:this.shouldCreateAsDevState(),orgSlug:this.orgSlug}}):(await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(n=this.buildingWebchatView)||void 0===n?void 0:n.id,buildingSlug:this.buildingSlug,userId:null===(i=this.buildingWebchatView)||void 0===i?void 0:i.userId,leadSource:this.leadSource,widgetType:this.widgetType,isDevState:this.shouldCreateAsDevState(),lead_sources_with_timestamps:(null!==(o=null===(r=this.leadSourceMultitouchClient)||void 0===r?void 0:r.getSafeLeadSourceTouchpointsWithDefault({includedUserSelectedLeadSource:null}))&&void 0!==o?o:[]).map(e=>Tr({...e}))}}),null===(a=this.leadSourceClient)||void 0===a||a.resetLeadSource(),null===(s=this.leadSourceMultitouchClient)||void 0===s||s.resetLeadSourceTouchpoints()),this.isFirstChatMessageSent||($o("firstChatMessageSent",{message:e,buildingId:null===(l=this.buildingWebchatView)||void 0===l?void 0:l.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel}),this.isFirstChatMessageSent=!0),$o("chatMessageSent",{message:e,buildingId:null===(u=this.buildingWebchatView)||void 0===u?void 0:u.id,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,leadUserId:this.leadUserId,channel:this.channel}))}),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.removeDuplicatedRawPubnubMessages=e=>{const t=new Set;return e.filter(e=>{if("lead_message"===e.message.customType||!e.message.stream_id||!e.message.order)return!0;const n=`${e.message.stream_id}-${e.message.order}-${e.message.messageType}`;return t.has(n)?(Ho({logTitle:"PUBNUB_WARN_DUPLICATE_MESSAGE",logData:{message:e,channel:this.channel},logType:Fo.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),!1):(t.add(n),!0)})},this.translatePubnubMessagesIntoSimpleChatMessages=e=>{const t=[],n={};return this.removeDuplicatedRawPubnubMessages(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:_u.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:_u.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:_u.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.buildingWebchatView=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`,this.leadSourceClient=a,this.leadSourceMultitouchClient=o,this.widgetType=s}async initSession(e,t,n){try{const i={building_slug:e,org_slug:t};n&&(i.lead_id=n);const o=await r().post(`${this.apiHost}/platformApi/webchat/init`,i);return this.sessionToken=o.data.session_token,this.leadUserId=o.data.lead_id,this.channel=o.data.channel,o.data}catch(e){return this.buildingWebchatView&&Ho({logTitle:"WEBCHAT_INIT_SESSION_ERROR",logData:{error:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e}),null}}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(pu())({publishKey:t.keys.publish_key,subscribeKey:t.keys.subscribe_key,userId:this.leadUserId,authKey:t.auth.result.token,origin:"meetelise.pubnubapi.com"}),this.withAuthToken(()=>new Promise(()=>this.handleChatListeners())),await this.withAuthToken(()=>this.getChannelHistory()),this.pubnub):void 0}async fetchToken(e,t){try{if(this.sessionToken){const e="healthcare"===this.widgetType?"?industry=health_care":"";return(await r().get(`${this.apiHost}/platformApi/webchat/pn/v2/request-token${e}`,{headers:{"X-Session-Token":this.sessionToken}})).data}return(await r().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${t}&${"healthcare"===this.widgetType?"industry=health_care":""}`)).data}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}return null}async fetchChannelExists(e){try{return(await r().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}return!1}async withAuthToken(e){try{await e()}catch(t){if(t instanceof i.AxiosError&&t&&t.response&&403===t.response.status)try{if(!this.pubnub||!this.leadUserId||!this.channel)return;const t=await this.fetchToken(this.leadUserId,this.channel);if(!t)return;this.pubnub.setAuthKey(t.auth.result.token),await e()}catch(e){this.buildingWebchatView&&Ho({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:Fo.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}}}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})}),this.markEveryPreviousNoReplyMessageDone(t),n=n.concat(t.filter(e=>e.message.messageType!==Eu.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.buildingWebchatView&&Ho({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:Fo.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug,error:e})}}shouldCreateAsDevState(){return location.href.startsWith("https://app.meetelise.com/settings/widgets")||location.href.includes("demo/utilities")}},Pu=new Set(["8009855990","8338526262","8002221222","8006624357","8002738255","8007997233","8007874889","8006564673","8004224453","8883737888","8006213362","8009506264","8558272736","8008435678","8007862929","8008523836","8007849433","8007729100","8006699777","8006858470","8004322209","8003473735","8008778339","8009552232","8002255342","8009272891","8003049320","8007937724","8002382333","8003353863","8776858878","8003329227","8776554371","8772944357","8772944356","6092925760","6092926735","8007928339","8008329173","8882853036","6092921210","8007929773","8003561561","8003826717","8005727233","8009291040","8888958179","8006879512","8004262537","8773475463","8774149251","8005103102","8889372835","8007010710","8007010720","8774288844","8007929745","8003283838","6092927060","6092928319","8008527899","8662401347","8009923678","8776522873","8776527624","8003313937","8008435437","8776536783","8778392339","8003676274","8006896411"]),Iu=e=>{const t=e.replace(/\D/g,"").replace(/^1(\d{10})$/,"$1");return Pu.has(t)},Nu=(e,t,n)=>{try{const i=e.replace(/\D/g,"").replace(/^1(\d{10})$/,"$1"),r=`tel:${i}`,o=`sms:${i}`,a=`whatsapp://send?phone=${i}`,s=`facetime:${i}`,l=`facetime-audio:${i}`,u=/(?:\+1[\s.-]?)?(?:\([2-9]\d{2}\)[\s.-]?|[2-9]\d{2}[\s.-])[2-9]\d{2}[\s.-]?\d{4}/g,d=/(tel|sms):(?:\+1\s)?(?:(?:\(\d{3}\)\s|\d{3}-)\d{3}-\d{4}|\d{10,11})/g,c=/whatsapp:\/\/send\?phone=\d+/g,h=/(facetime|facetime-audio):\d+/g,p=/emergency|emergencia/i,f=300,g=e=>!(!e||e.length>f)&&p.test(e),m=e=>{var t,n,i,r;if(g(e.textContent))return!0;if(g(null===(t=e.previousElementSibling)||void 0===t?void 0:t.textContent)||g(null===(n=e.nextElementSibling)||void 0===n?void 0:n.textContent))return!0;const o=e.parentElement;return!(!o||!g(null===(i=o.previousElementSibling)||void 0===i?void 0:i.textContent)&&!g(null===(r=o.nextElementSibling)||void 0===r?void 0:r.textContent))},y=document.body.getElementsByTagName("*");let b=!1;const v=i.replace(/(\d{3})(\d{3})(\d{4})/,"($1) $2-$3");let w=!1,C=!1,x=0;for(let e=0;e<y.length;e++)if(y[e].nodeType===Node.ELEMENT_NODE&&!m(y[e])){if(1===y[e].childNodes.length&&y[e].childNodes[0].nodeType==Node.TEXT_NODE){const t=y[e].textContent;if(!t)continue;const n=t.replace(u,e=>{if(Iu(e))return e;return e.startsWith("+1 ")?`+1 ${v}`:v});t!==n&&(x++,y[e].textContent=n),b=!0,w||(w=!0)}if(y[e].hasAttribute("href")){const t=y[e].getAttribute("href");if(!t)continue;let n="",i=d;if(t.startsWith("sms:")?n=o:t.startsWith("whatsapp:")?(n=a,i=c):t.startsWith("facetime:")?(n=s,i=h):t.startsWith("facetime-audio:")?(n=l,i=h):n=r,Iu(t))continue;const u=t.replace(i,n);if(y[e].setAttribute("href",u),(t.startsWith("tel:")||t.startsWith("sms:"))&&u===t&&u!==n){t.replace(/\D/g,"").length>=7&&y[e].setAttribute("href",t.startsWith("tel:")?r:o)}C||(C=!0)}}return w&&Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"text-insertion",newPhoneNumber:v,website:window.location.href},logType:Fo.info,buildingSlug:n,orgSlug:t}),C&&Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"href-insertion",newPhoneNumber:v,website:window.location.href},logType:Fo.info,buildingSlug:n,orgSlug:t}),b||Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"no-phone-number-found",website:window.location.href},logType:Fo.warn,buildingSlug:n,orgSlug:t}),x}catch(e){return Ho({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"insertion-error",error:e instanceof Error?e.message:String(e),website:window.location.href},logType:Fo.error,buildingSlug:n,orgSlug:t,error:e}),0}};var Mu=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 Du=class extends oe{constructor(){super(...arguments),this.onClick=()=>{},this.primaryColor=qn,this.foregroundColorOnPrimaryBackgroundColor="white",this.toExpand=!1}render(){return R`
|
|
6048
6048
|
<button
|
|
6049
6049
|
class=${this.toExpand?"button-container mini":"button-container"}
|
|
6050
6050
|
@click=${this.onClick}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { expect } from "@esm-bundle/chai";
|
|
2
|
+
import { insertDNIIntoWebsite } from "./insertDNIIntoWebsite";
|
|
3
|
+
|
|
4
|
+
const DNI_NUMBER = "3035550123";
|
|
5
|
+
const DNI_DISPLAY = "(303) 555-0123";
|
|
6
|
+
|
|
7
|
+
const render = (html: string): void => {
|
|
8
|
+
document.body.innerHTML = html;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const insert = (cleanPhoneNumber: string = DNI_NUMBER): number =>
|
|
12
|
+
insertDNIIntoWebsite(cleanPhoneNumber, "test-org", "test-building");
|
|
13
|
+
|
|
14
|
+
const textOf = (selector: string): string | null =>
|
|
15
|
+
document.querySelector(selector)?.textContent ?? null;
|
|
16
|
+
|
|
17
|
+
const hrefOf = (selector: string): string | null =>
|
|
18
|
+
document.querySelector(selector)?.getAttribute("href") ?? null;
|
|
19
|
+
|
|
20
|
+
describe("insertDNIIntoWebsite", () => {
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
document.body.innerHTML = "";
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("display text", () => {
|
|
26
|
+
it("replaces common US phone formats", () => {
|
|
27
|
+
const formats = [
|
|
28
|
+
"(855) 383-2298",
|
|
29
|
+
"855-383-2298",
|
|
30
|
+
"855.383.2298",
|
|
31
|
+
"855 383 2298",
|
|
32
|
+
"(855)383-2298",
|
|
33
|
+
"855-3832298",
|
|
34
|
+
];
|
|
35
|
+
render(formats.map((f, i) => `<span id="n${i}">${f}</span>`).join(""));
|
|
36
|
+
|
|
37
|
+
insert();
|
|
38
|
+
|
|
39
|
+
formats.forEach((format, i) => {
|
|
40
|
+
expect(textOf(`#n${i}`)).to.equal(DNI_DISPLAY, format);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("keeps a +1 country code prefix", () => {
|
|
45
|
+
render(`<span id="n">+1 855-383-2298</span>`);
|
|
46
|
+
|
|
47
|
+
insert();
|
|
48
|
+
|
|
49
|
+
expect(textOf("#n")).to.equal(`+1 ${DNI_DISPLAY}`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("replaces a number embedded in surrounding text", () => {
|
|
53
|
+
render(`<p id="n">Call us at 855-383-2298 today!</p>`);
|
|
54
|
+
|
|
55
|
+
insert();
|
|
56
|
+
|
|
57
|
+
expect(textOf("#n")).to.equal(`Call us at ${DNI_DISPLAY} today!`);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("accepts 10-digit, 11-digit, and +1 DNI numbers", () => {
|
|
61
|
+
for (const dni of ["3035550123", "13035550123", "+13035550123"]) {
|
|
62
|
+
render(`<span id="n">855-383-2298</span>`);
|
|
63
|
+
|
|
64
|
+
insert(dni);
|
|
65
|
+
|
|
66
|
+
expect(textOf("#n")).to.equal(DNI_DISPLAY, dni);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("replaces both the text and tel: href of a phone link", () => {
|
|
71
|
+
render(`<a id="n" href="tel:8553832298">(855) 383-2298</a>`);
|
|
72
|
+
|
|
73
|
+
insert();
|
|
74
|
+
|
|
75
|
+
expect(textOf("#n")).to.equal(DNI_DISPLAY);
|
|
76
|
+
expect(hrefOf("#n")).to.equal(`tel:${DNI_NUMBER}`);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("NANP validity", () => {
|
|
81
|
+
it("ignores numbers whose area code starts with 0 or 1", () => {
|
|
82
|
+
render(
|
|
83
|
+
`<span id="a">123-456-7890</span><span id="b">(023) 456-7890</span>`
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
insert();
|
|
87
|
+
|
|
88
|
+
expect(textOf("#a")).to.equal("123-456-7890");
|
|
89
|
+
expect(textOf("#b")).to.equal("(023) 456-7890");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("ignores numbers whose exchange starts with 0 or 1", () => {
|
|
93
|
+
render(
|
|
94
|
+
`<span id="a">(212) 155-1234</span><span id="b">212-055-1234</span>`
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
insert();
|
|
98
|
+
|
|
99
|
+
expect(textOf("#a")).to.equal("(212) 155-1234");
|
|
100
|
+
expect(textOf("#b")).to.equal("212-055-1234");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("ignores western US longitudes in visible text", () => {
|
|
104
|
+
render(`<p id="n">Lat/Long: 39.9038078, -104.9932859</p>`);
|
|
105
|
+
|
|
106
|
+
insert();
|
|
107
|
+
|
|
108
|
+
expect(textOf("#n")).to.equal("Lat/Long: 39.9038078, -104.9932859");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("keeps JSON-LD geo coordinates valid", () => {
|
|
112
|
+
render(
|
|
113
|
+
`<script id="n" type="application/ld+json">${JSON.stringify({
|
|
114
|
+
"@type": "ApartmentComplex",
|
|
115
|
+
telephone: "855-383-2298",
|
|
116
|
+
geo: {
|
|
117
|
+
"@type": "GeoCoordinates",
|
|
118
|
+
latitude: 39.9038078,
|
|
119
|
+
longitude: -104.9932859,
|
|
120
|
+
},
|
|
121
|
+
})}</script>`
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
insert();
|
|
125
|
+
|
|
126
|
+
const schema = JSON.parse(textOf("#n") ?? "");
|
|
127
|
+
expect(schema.geo.latitude).to.equal(39.9038078);
|
|
128
|
+
expect(schema.geo.longitude).to.equal(-104.9932859);
|
|
129
|
+
expect(schema.telephone).to.equal(DNI_DISPLAY);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("guardrails", () => {
|
|
134
|
+
it("does not replace protected numbers", () => {
|
|
135
|
+
render(`<a id="n" href="tel:8002221222">800-222-1222</a>`);
|
|
136
|
+
|
|
137
|
+
insert();
|
|
138
|
+
|
|
139
|
+
expect(textOf("#n")).to.equal("800-222-1222");
|
|
140
|
+
expect(hrefOf("#n")).to.equal("tel:8002221222");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("does not replace numbers next to emergency text", () => {
|
|
144
|
+
render(
|
|
145
|
+
`<div><strong>After-hours emergency</strong><span id="en">855-383-2298</span></div>` +
|
|
146
|
+
`<div><strong>Mantenimiento de emergencia</strong><span id="es">855-383-2298</span></div>`
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
insert();
|
|
150
|
+
|
|
151
|
+
expect(textOf("#en")).to.equal("855-383-2298");
|
|
152
|
+
expect(textOf("#es")).to.equal("855-383-2298");
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("hrefs", () => {
|
|
157
|
+
it("rewrites tel: hrefs in any format", () => {
|
|
158
|
+
const hrefs = [
|
|
159
|
+
"tel:8553832298",
|
|
160
|
+
"tel:18553832298",
|
|
161
|
+
"tel:+18553832298",
|
|
162
|
+
"tel:855-383-2298",
|
|
163
|
+
"tel:(855) 383-2298",
|
|
164
|
+
];
|
|
165
|
+
render(
|
|
166
|
+
hrefs.map((h, i) => `<a id="h${i}" href="${h}">Call</a>`).join("")
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
insert();
|
|
170
|
+
|
|
171
|
+
hrefs.forEach((href, i) => {
|
|
172
|
+
expect(hrefOf(`#h${i}`)).to.equal(`tel:${DNI_NUMBER}`, href);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("rewrites sms, whatsapp, and facetime hrefs", () => {
|
|
177
|
+
render(
|
|
178
|
+
`<a id="sms" href="sms:8553832298">Text</a>` +
|
|
179
|
+
`<a id="wa" href="whatsapp://send?phone=18553832298">WhatsApp</a>` +
|
|
180
|
+
`<a id="ft" href="facetime:8553832298">FaceTime</a>` +
|
|
181
|
+
`<a id="fta" href="facetime-audio:8553832298">FaceTime Audio</a>`
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
insert();
|
|
185
|
+
|
|
186
|
+
expect(hrefOf("#sms")).to.equal(`sms:${DNI_NUMBER}`);
|
|
187
|
+
expect(hrefOf("#wa")).to.equal(`whatsapp://send?phone=${DNI_NUMBER}`);
|
|
188
|
+
expect(hrefOf("#ft")).to.equal(`facetime:${DNI_NUMBER}`);
|
|
189
|
+
expect(hrefOf("#fta")).to.equal(`facetime-audio:${DNI_NUMBER}`);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("leaves non-phone hrefs untouched", () => {
|
|
193
|
+
render(`<a id="n" href="/floor-plans">Floor plans</a>`);
|
|
194
|
+
|
|
195
|
+
insert();
|
|
196
|
+
|
|
197
|
+
expect(hrefOf("#n")).to.equal("/floor-plans");
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe("return value", () => {
|
|
202
|
+
it("counts elements whose display text changed", () => {
|
|
203
|
+
render(
|
|
204
|
+
`<span>855-383-2298</span><span>(855) 383-2298</span>` +
|
|
205
|
+
`<a href="tel:8553832298">Call</a><span>123-456-7890</span>`
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
expect(insert()).to.equal(2);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("returns 0 when no phone number is found", () => {
|
|
212
|
+
render(`<p>No phone numbers here, just 39.9038078, -104.9932859.</p>`);
|
|
213
|
+
|
|
214
|
+
expect(insert()).to.equal(0);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -31,7 +31,7 @@ export const insertDNIIntoWebsite = (
|
|
|
31
31
|
const newFacetimeAudioNumber = `facetime-audio:${cleanedNumber}`;
|
|
32
32
|
|
|
33
33
|
const phoneNumberPattern =
|
|
34
|
-
/(?:\+1[\s.-]?)?(?:\(\d{
|
|
34
|
+
/(?:\+1[\s.-]?)?(?:\([2-9]\d{2}\)[\s.-]?|[2-9]\d{2}[\s.-])[2-9]\d{2}[\s.-]?\d{4}/g;
|
|
35
35
|
const hrefNumberPattern =
|
|
36
36
|
/(tel|sms):(?:\+1\s)?(?:(?:\(\d{3}\)\s|\d{3}-)\d{3}-\d{4}|\d{10,11})/g;
|
|
37
37
|
|