@meetelise/chat 1.20.216 → 1.20.218
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
|
@@ -2999,7 +2999,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
2999
2999
|
${bi}
|
|
3000
3000
|
${wi}
|
|
3001
3001
|
${Si}
|
|
3002
|
-
`,Zi([ue({attribute:!0})],$i.prototype,"isMinimized",void 0),Zi([ue()],$i.prototype,"mobileStyles",void 0),Zi([ue({type:Boolean})],$i.prototype,"isFirstMount",void 0),Zi([ue({attribute:!1})],$i.prototype,"autoOpenChatWidget",void 0),Zi([ue()],$i.prototype,"phoneNumber",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingName",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatId",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatCallUsHeader",void 0),Zi([ue({attribute:!1})],$i.prototype,"buildingId",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"orgSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"sgtUrl",void 0),Zi([ue({attribute:!0})],$i.prototype,"designConcept",void 0),Zi([ue({attribute:!0})],$i.prototype,"featureFlagShowDropdown",void 0),Zi([ue({attribute:!1})],$i.prototype,"leadSources",void 0),Zi([ue({attribute:!0})],$i.prototype,"currentLeadSource",void 0),Zi([ue({attribute:!0})],$i.prototype,"escortedToursLink",void 0),Zi([ue({attribute:!0})],$i.prototype,"virtualToursLink",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasCallUsEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasChatEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasEmailEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasSSTEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasTextUsEnabled",void 0),Zi([ue({attribute:!1})],$i.prototype,"layoutOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"unitOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"tourTypeOptions",void 0),Zi([ue({attribute:!0})],$i.prototype,"hasDynamicSchedulingEnabled",void 0),Zi([ue({attribute:!0})],$i.prototype,"onExitChat",void 0),Zi([ue({type:Number})],$i.prototype,"right",void 0),Zi([ue({type:Number})],$i.prototype,"bottom",void 0),Zi([ue({type:Number})],$i.prototype,"top",void 0),Zi([ue({type:Number})],$i.prototype,"left",void 0),Zi([ue({attribute:!0})],$i.prototype,"showTourNextToChat",void 0),Zi([ue({attribute:!1})],$i.prototype,"onChatTapped",void 0),Zi([ue({attribute:!0})],$i.prototype,"onClickMinimize",void 0),Zi([ue({attribute:!1})],$i.prototype,"launcherStyles",void 0),Zi([ue({attribute:!0})],$i.prototype,"brandColor",void 0),Zi([le()],$i.prototype,"isEmailWindowOpen",void 0),Zi([le()],$i.prototype,"isCallUsWindowOpen",void 0),Zi([le()],$i.prototype,"isSSTWindowOpen",void 0),Zi([le()],$i.prototype,"isTextUsWindowOpen",void 0),$i=Zi([ae("meetelise-launcher")],$i);const er=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",$i)};var tr=n(3379),nr=n.n(tr),ir=n(7795),rr=n.n(ir),or=n(569),ar=n.n(or),sr=n(3565),ur=n.n(sr),lr=n(9216),dr=n.n(lr),cr=n(4589),pr=n.n(cr),hr=n(3631),fr={};async function mr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?gr(n.data,e):[]}catch(e){return[]}}fr.styleTagTransform=pr(),fr.setAttributes=ur(),fr.insert=ar().bind(null,"head"),fr.domAPI=rr(),fr.insertStyleElement=dr(),nr()(hr.Z,fr),hr.Z&&hr.Z.locals&&hr.Z.locals;const gr=(e,t)=>{let n=[];switch(t){case"d41619ec-0f79-11ee-8439-93855926ad58":n=["Forthea - PPC","HotPads","Forthea","Locator","Website-apartmentguide.com","Forthea - organic search","Tdc employee","University newspaper","Nashville apartment locators","Forthea - paid social","Apartment list","Off campus partners","Waze ads","Athletic event","Website-apartment guide"];break;case"d4160560-0f79-11ee-8438-fba837bf3a46":n=["Forthea - PPC","Rentgrata","Website-ApartmentFinder.com","Word of Mouth","Texas A&M A-Frame on Campus","Rent.com","Website-craigslist","Apartment List","Website-apartments.com","Forthea - paid social","Forthea - organic search","Website-apartmentguide.com","Forthea","Uhomes","Phone book","Property - website"];break;default:n=[]}return e.sort(),e.filter((e=>{const t=e.toLowerCase();return!n.map((e=>e.toLowerCase())).includes(t)}))};var vr,yr=n(9594),br=n.n(yr),wr=new Uint8Array(16);function Sr(){if(!vr&&!(vr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return vr(wr)}const Tr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,xr=function(e){return"string"==typeof e&&Tr.test(e)};for(var Ar=[],Or=0;Or<256;++Or)Ar.push((Or+256).toString(16).substr(1));const Cr=function(e,t,n){var i=(e=e||{}).random||(e.rng||Sr)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(var r=0;r<16;++r)t[n+r]=i[r];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Ar[e[t+0]]+Ar[e[t+1]]+Ar[e[t+2]]+Ar[e[t+3]]+"-"+Ar[e[t+4]]+Ar[e[t+5]]+"-"+Ar[e[t+6]]+Ar[e[t+7]]+"-"+Ar[e[t+8]]+Ar[e[t+9]]+"-"+Ar[e[t+10]]+Ar[e[t+11]]+Ar[e[t+12]]+Ar[e[t+13]]+Ar[e[t+14]]+Ar[e[t+15]]).toLowerCase();if(!xr(n))throw TypeError("Stringified UUID is invalid");return n}(i)},Ir=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Nr=(e,t,n)=>{const i=mn(new Date),r=n||`lead_${Cr()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:Tn(i),buildingSlug:e,initiatedChat:t}},Er=e=>{const t=localStorage.getItem("com.elise.webchat.slug="+e);if(t)try{const n=JSON.parse(t),i={leadId:n.leadId,timestamp:new Date(n.timestamp),buildingSlug:n.buildingSlug,initiatedChat:n.initiatedChat};if(Rr(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Rr=(e,t)=>!(t.buildingSlug!==e||!t.leadId||!t.timestamp||dn(t.timestamp,24));var _r;!function(e){e.noReply="no-reply",e.text="text",e.media="media"}(_r||(_r={}));const Pr=e=>e.type===Fr.text,Mr=e=>e.type===Fr.media;var Fr;!function(e){e.text="text",e.media="media"}(Fr||(Fr={}));const Dr=class{constructor(e,t,n,i=null,r){this.apiHost="https://app.meetelise.com",this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.isCurrentlyStreamingMessage=!1,this.chatListener=null,this.rawPubnubMessages=[],this.simpleChatMessages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==_r.noReply&&(this.rawPubnubMessages=[...this.rawPubnubMessages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}],this.simpleChatMessages=this.translatePubnubMessagesIntoSimpleChatMessages(this.rawPubnubMessages));const n="eliseai"!==e.publisher&&"elise_health_ai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.simpleChatMessages,isLoading:n}),!n&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}},this.handleDisconnect=()=>{this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.removeChatListeners()},this.removeChatListeners=()=>{this.pubnub&&this.channel&&(this.pubnub.unsubscribe({channels:[this.channel]}),this.pubnub.removeListener(this.listenerParams))},this.sendMessage=async e=>{if(e){if(!this.pubnub){const e=Nr(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))return}await this.withAuthToken((async()=>{var t,n;this.pubnub&&this.channel&&(this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.eliseResponseTimeout=setTimeout((()=>{console.error("Elise AI did not respond in time..."),this.building&&si({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),9e4),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(t=this.building)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,userId:null===(n=this.building)||void 0===n?void 0:n.userId,leadSource:this.leadSource,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:Fr.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:Fr.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:Fr.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}`}addChatListener(e){this.chatListener=e}async initializePubnub(e){if(!e.leadId)return;this.leadUserId=e.leadId;const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(br())({publishKey:t.keys.publish_key,subscribeKey:t.keys.subscribe_key,userId:this.leadUserId,authKey:t.auth.result.token}),this.withAuthToken((()=>new Promise((()=>this.handleChatListeners())))),await this.withAuthToken((()=>this.getChannelHistory())),this.pubnub):void 0}async fetchToken(e,n){try{return(await t().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${n}&${this.building?"":"industry=health_care"}`)).data}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return null}async fetchChannelExists(e){try{return(await t().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return!1}async withAuthToken(t){try{await t()}catch(n){if(n instanceof e.AxiosError&&n&&n.response&&403===n.response.status)try{if(!this.pubnub||!this.leadUserId||!this.channel)return;const e=await this.fetchToken(this.leadUserId,this.channel);if(!e)return;this.pubnub.setAuthKey(e.auth.result.token),await t()}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}async getChannelHistory(e=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.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!==_r.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")}},kr=(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 Ur=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 qr=class extends re{constructor(){super(...arguments),this.onClick=()=>{},this.brandColor=Me,this.toExpand=!1}render(){return U`
|
|
3002
|
+
`,Zi([ue({attribute:!0})],$i.prototype,"isMinimized",void 0),Zi([ue()],$i.prototype,"mobileStyles",void 0),Zi([ue({type:Boolean})],$i.prototype,"isFirstMount",void 0),Zi([ue({attribute:!1})],$i.prototype,"autoOpenChatWidget",void 0),Zi([ue()],$i.prototype,"phoneNumber",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingName",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatId",void 0),Zi([ue({attribute:!0})],$i.prototype,"chatCallUsHeader",void 0),Zi([ue({attribute:!1})],$i.prototype,"buildingId",void 0),Zi([ue({attribute:!0})],$i.prototype,"buildingSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"orgSlug",void 0),Zi([ue({attribute:!0})],$i.prototype,"sgtUrl",void 0),Zi([ue({attribute:!0})],$i.prototype,"designConcept",void 0),Zi([ue({attribute:!0})],$i.prototype,"featureFlagShowDropdown",void 0),Zi([ue({attribute:!1})],$i.prototype,"leadSources",void 0),Zi([ue({attribute:!0})],$i.prototype,"currentLeadSource",void 0),Zi([ue({attribute:!0})],$i.prototype,"escortedToursLink",void 0),Zi([ue({attribute:!0})],$i.prototype,"virtualToursLink",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasCallUsEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasChatEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasEmailEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasSSTEnabled",void 0),Zi([ue({type:Boolean})],$i.prototype,"hasTextUsEnabled",void 0),Zi([ue({attribute:!1})],$i.prototype,"layoutOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"unitOptions",void 0),Zi([ue({attribute:!1})],$i.prototype,"tourTypeOptions",void 0),Zi([ue({attribute:!0})],$i.prototype,"hasDynamicSchedulingEnabled",void 0),Zi([ue({attribute:!0})],$i.prototype,"onExitChat",void 0),Zi([ue({type:Number})],$i.prototype,"right",void 0),Zi([ue({type:Number})],$i.prototype,"bottom",void 0),Zi([ue({type:Number})],$i.prototype,"top",void 0),Zi([ue({type:Number})],$i.prototype,"left",void 0),Zi([ue({attribute:!0})],$i.prototype,"showTourNextToChat",void 0),Zi([ue({attribute:!1})],$i.prototype,"onChatTapped",void 0),Zi([ue({attribute:!0})],$i.prototype,"onClickMinimize",void 0),Zi([ue({attribute:!1})],$i.prototype,"launcherStyles",void 0),Zi([ue({attribute:!0})],$i.prototype,"brandColor",void 0),Zi([le()],$i.prototype,"isEmailWindowOpen",void 0),Zi([le()],$i.prototype,"isCallUsWindowOpen",void 0),Zi([le()],$i.prototype,"isSSTWindowOpen",void 0),Zi([le()],$i.prototype,"isTextUsWindowOpen",void 0),$i=Zi([ae("meetelise-launcher")],$i);const er=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",$i)};var tr=n(3379),nr=n.n(tr),ir=n(7795),rr=n.n(ir),or=n(569),ar=n.n(or),sr=n(3565),ur=n.n(sr),lr=n(9216),dr=n.n(lr),cr=n(4589),pr=n.n(cr),hr=n(3631),fr={};async function mr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?gr(n.data,e):[]}catch(e){return[]}}fr.styleTagTransform=pr(),fr.setAttributes=ur(),fr.insert=ar().bind(null,"head"),fr.domAPI=rr(),fr.insertStyleElement=dr(),nr()(hr.Z,fr),hr.Z&&hr.Z.locals&&hr.Z.locals;const gr=(e,t)=>{let n=[];switch(t){case"d41619ec-0f79-11ee-8439-93855926ad58":n=["Forthea - PPC","HotPads","Forthea","Locator","Website-apartmentguide.com","Forthea - organic search","Tdc employee","University newspaper","Nashville apartment locators","Forthea - paid social","Apartment list","Off campus partners","Waze ads","Athletic event","Website-apartment guide"];break;case"d4160560-0f79-11ee-8438-fba837bf3a46":n=["Forthea - PPC","Rentgrata","Website-ApartmentFinder.com","Word of Mouth","Texas A&M A-Frame on Campus","Rent.com","Website-craigslist","Apartment List","Website-apartments.com","Forthea - paid social","Forthea - organic search","Website-apartmentguide.com","Forthea","Uhomes","Phone book","Property - website"];break;default:n=[]}return e.sort(),e.filter((e=>{const t=e.toLowerCase();return!n.map((e=>e.toLowerCase())).includes(t)}))};var vr,yr=n(9594),br=n.n(yr),wr=new Uint8Array(16);function Sr(){if(!vr&&!(vr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return vr(wr)}const Tr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,xr=function(e){return"string"==typeof e&&Tr.test(e)};for(var Ar=[],Or=0;Or<256;++Or)Ar.push((Or+256).toString(16).substr(1));const Cr=function(e,t,n){var i=(e=e||{}).random||(e.rng||Sr)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(var r=0;r<16;++r)t[n+r]=i[r];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Ar[e[t+0]]+Ar[e[t+1]]+Ar[e[t+2]]+Ar[e[t+3]]+"-"+Ar[e[t+4]]+Ar[e[t+5]]+"-"+Ar[e[t+6]]+Ar[e[t+7]]+"-"+Ar[e[t+8]]+Ar[e[t+9]]+"-"+Ar[e[t+10]]+Ar[e[t+11]]+Ar[e[t+12]]+Ar[e[t+13]]+Ar[e[t+14]]+Ar[e[t+15]]).toLowerCase();if(!xr(n))throw TypeError("Stringified UUID is invalid");return n}(i)},Ir=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Nr=(e,t,n)=>{const i=mn(new Date),r=n||`lead_${Cr()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:Tn(i),buildingSlug:e,initiatedChat:t}},Er=e=>{const t=localStorage.getItem("com.elise.webchat.slug="+e);if(t)try{const n=JSON.parse(t),i={leadId:n.leadId,timestamp:new Date(n.timestamp),buildingSlug:n.buildingSlug,initiatedChat:n.initiatedChat};if(Rr(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Rr=(e,t)=>!(t.buildingSlug!==e||!t.leadId||!t.timestamp||dn(t.timestamp,24));var _r;!function(e){e.noReply="no-reply",e.text="text",e.media="media"}(_r||(_r={}));const Pr=e=>e.type===Fr.text,Mr=e=>e.type===Fr.media;var Fr;!function(e){e.text="text",e.media="media"}(Fr||(Fr={}));const Dr=class{constructor(e,t,n,i=null,r){this.apiHost="https://app.meetelise.com",this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.isCurrentlyStreamingMessage=!1,this.chatListener=null,this.rawPubnubMessages=[],this.simpleChatMessages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==_r.noReply&&(this.rawPubnubMessages=[...this.rawPubnubMessages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}],this.simpleChatMessages=this.translatePubnubMessagesIntoSimpleChatMessages(this.rawPubnubMessages));const n="eliseai"!==e.publisher&&"elise_health_ai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.simpleChatMessages,isLoading:n}),!n&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}},this.handleDisconnect=()=>{this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.removeChatListeners()},this.removeChatListeners=()=>{this.pubnub&&this.channel&&(this.pubnub.unsubscribe({channels:[this.channel]}),this.pubnub.removeListener(this.listenerParams))},this.sendMessage=async e=>{if(e){if(!this.pubnub){const e=Nr(this.buildingSlug,!0,this.leadUserId);if(!await this.initializePubnub(e))return}await this.withAuthToken((async()=>{var t,n;this.pubnub&&this.channel&&(this.eliseResponseTimeout&&(clearTimeout(this.eliseResponseTimeout),this.eliseResponseTimeout=null),this.eliseResponseTimeout=setTimeout((()=>{console.error("Elise AI did not respond in time..."),this.building&&si({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),9e4),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(t=this.building)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,userId:null===(n=this.building)||void 0===n?void 0:n.userId,leadSource:this.leadSource,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:Fr.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:Fr.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:Fr.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}`}addChatListener(e){this.chatListener=e}async initializePubnub(e){if(!e.leadId)return;this.leadUserId=e.leadId;const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(br())({publishKey:t.keys.publish_key,subscribeKey:t.keys.subscribe_key,userId:this.leadUserId,authKey:t.auth.result.token}),this.withAuthToken((()=>new Promise((()=>this.handleChatListeners())))),await this.withAuthToken((()=>this.getChannelHistory())),this.pubnub):void 0}async fetchToken(e,n){try{return(await t().get(`${this.apiHost}/platformApi/webchat/pn/request-token?user_id=${e}&channel=${n}&${this.building?"":"industry=health_care"}`)).data}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return null}async fetchChannelExists(e){try{return(await t().get(`${this.apiHost}/platformApi/webchat/check-channel-exists?channel_name=${e}`)).data}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}return!1}async withAuthToken(t){try{await t()}catch(n){if(n instanceof e.AxiosError&&n&&n.response&&403===n.response.status)try{if(!this.pubnub||!this.leadUserId||!this.channel)return;const e=await this.fetchToken(this.leadUserId,this.channel);if(!e)return;this.pubnub.setAuthKey(e.auth.result.token),await t()}catch(e){this.building&&si({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ai.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}async getChannelHistory(e=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!==_r.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")}},kr=(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 Ur=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 qr=class extends re{constructor(){super(...arguments),this.onClick=()=>{},this.brandColor=Me,this.toExpand=!1}render(){return U`
|
|
3003
3003
|
<div
|
|
3004
3004
|
class=${this.toExpand?"button-container mini":"button-container"}
|
|
3005
3005
|
@click=${this.onClick}
|
|
@@ -3506,7 +3506,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3506
3506
|
target="_blank"
|
|
3507
3507
|
rel="noopener noreferrer"
|
|
3508
3508
|
>${t}
|
|
3509
|
-
</a>`}return U`${e} `}))}<br />`:U``}))}`,this.imagesToDisplay=o,Promise.all(r).then((e=>{this.websitePreviewInfo=e}))}removeTrailingPunctuation(e){return[".",",","!","?",":",";"].includes(e[e.length-1])?this.removeTrailingPunctuation(e.slice(0,-1)):e}mapAndMarkHyperLinks(e){const t=Array.from(e.matchAll(/<https?:\/\/[^|]+\|[^>]+>|<a href="[^"]+"(?: target="[^"]*")?>[^<]+<\/a
|
|
3509
|
+
</a>`}return U`${e} `}))}<br />`:U``}))}`,this.imagesToDisplay=o,Promise.all(r).then((e=>{this.websitePreviewInfo=e}))}removeTrailingPunctuation(e){return[".",",","!","?",":",";"].includes(e[e.length-1])?this.removeTrailingPunctuation(e.slice(0,-1)):e}mapAndMarkHyperLinks(e){const t=Array.from(e.matchAll(/<https?:\/\/[^|]+\|[^>]+>|<a href="[^"]+"(?: target="[^"]*")?>[^<]+<\/a>|\[.*?\]\(http[s]?:\/\/.*?\)/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=Cr().replace(/-/g,"");n.push({link:this.removeTrailingPunctuation(t.link),hyperlink:this.removeTrailingPunctuation(t.hyperlink),mark:t.matchedLink,id:i}),e=e.replace(t.matchedLink,`${t.addSpaceBefore?" ":""}${i}${t.addSpaceAfter?" ":""}`)}})),{hyperlinks:n,markedText:e}}async getLinkData(e){var n,i,r,o;try{const a=(await t().get(e)).data,s=(new DOMParser).parseFromString(a,"text/html");return s?{title:null!==(i=null===(n=s.querySelector("title"))||void 0===n?void 0:n.textContent)&&void 0!==i?i:null,description:(null===(r=s.querySelector('meta[name="description"]'))||void 0===r?void 0:r.getAttribute("content"))||null,image:(null===(o=s.querySelector('meta[property="og:image"]'))||void 0===o?void 0:o.getAttribute("content"))||null,favicon:null,link:e}:{title:null,description:null,image:null,favicon:null,link:e}}catch(t){return console.error("Error fetching website details:",t),{title:null,description:null,image:null,favicon:null,link:e}}}render(){return this.message?U`<div class="message-inner-body">
|
|
3510
3510
|
${this.isMessageStillStreamingChunks()?U`<div class="message-loader"><mini-loader></mini-loader></div>`:""}
|
|
3511
3511
|
<p
|
|
3512
3512
|
class=${fe({"message-text":!0,"webchat-font__desktop":!ln(),"webchat-font__mobile":ln()})}
|
package/src/MyPubnub.ts
CHANGED
|
@@ -307,12 +307,14 @@ class MyPubnub {
|
|
|
307
307
|
);
|
|
308
308
|
|
|
309
309
|
const messages = response.channels[this.channel];
|
|
310
|
+
if (!messages) {
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
310
313
|
messages.sort((a, b) => +a.timetoken - +b.timetoken);
|
|
311
314
|
|
|
312
315
|
if (!messages || messages.length === 0) {
|
|
313
316
|
break;
|
|
314
317
|
}
|
|
315
|
-
|
|
316
318
|
if (this.channel && Object.keys(response.channels).length !== 0) {
|
|
317
319
|
const currentChannelMessages = response.channels[this.channel];
|
|
318
320
|
const parsedCurrentChannelMessages: RawPubnubMessage[] = [];
|
|
@@ -144,9 +144,9 @@ export class PubnubMessage extends LitElement {
|
|
|
144
144
|
}[];
|
|
145
145
|
markedText: string;
|
|
146
146
|
} {
|
|
147
|
-
// Updated regex to match
|
|
147
|
+
// Updated regex to match all formats (EliseAI, embedded links, and markdown).
|
|
148
148
|
const regex =
|
|
149
|
-
/<https?:\/\/[^|]+\|[^>]+>|<a href="[^"]+"(?: target="[^"]*")?>[^<]+<\/a
|
|
149
|
+
/<https?:\/\/[^|]+\|[^>]+>|<a href="[^"]+"(?: target="[^"]*")?>[^<]+<\/a>|\[.*?\]\(http[s]?:\/\/.*?\)/g;
|
|
150
150
|
|
|
151
151
|
const matches = Array.from(text.matchAll(regex));
|
|
152
152
|
const listHyperlinks: {
|
|
@@ -171,7 +171,7 @@ export class PubnubMessage extends LitElement {
|
|
|
171
171
|
addSpaceBefore: !!(charBefore && charBefore !== " "),
|
|
172
172
|
addSpaceAfter: !!(charAfter && charAfter !== " "),
|
|
173
173
|
};
|
|
174
|
-
} else {
|
|
174
|
+
} else if (matchedLink.startsWith("<a href=")) {
|
|
175
175
|
// Handle for embedded links (<a>...</a>)
|
|
176
176
|
const linkMatch = matchedLink.match(/href="([^"]+)"/);
|
|
177
177
|
const hyperlinkMatch = matchedLink.match(/>[^<]+</);
|
|
@@ -182,6 +182,16 @@ export class PubnubMessage extends LitElement {
|
|
|
182
182
|
addSpaceBefore: !!(charBefore && charBefore !== " "),
|
|
183
183
|
addSpaceAfter: !!(charAfter && charAfter !== " "),
|
|
184
184
|
};
|
|
185
|
+
} else {
|
|
186
|
+
// Handle for markdown links
|
|
187
|
+
const [hyperlinkMatch, linkMatch] = matchedLink.split("](");
|
|
188
|
+
return {
|
|
189
|
+
matchedLink,
|
|
190
|
+
link: linkMatch ? linkMatch.slice(0, -1) : "",
|
|
191
|
+
hyperlink: hyperlinkMatch ? hyperlinkMatch.slice(1) : "",
|
|
192
|
+
addSpaceBefore: !!(charBefore && charBefore !== " "),
|
|
193
|
+
addSpaceAfter: !!(charAfter && charAfter !== " "),
|
|
194
|
+
};
|
|
185
195
|
}
|
|
186
196
|
});
|
|
187
197
|
|