@meetelise/chat 1.20.159 → 1.20.161
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/demo/index.html
CHANGED
|
@@ -117,14 +117,14 @@
|
|
|
117
117
|
<!-- Webpack dev server will serve the bundle, index.js, at the path '/' -->
|
|
118
118
|
<script type="module" async>
|
|
119
119
|
import MEChat from "/index.js";
|
|
120
|
-
MEChat.start({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
// MEChat.start({
|
|
121
|
+
// // // 123 Main Street
|
|
122
|
+
// organization: "test-company",
|
|
123
|
+
// building: "3fc93384-91f5-11ed-98a3-43f5a2f42588",
|
|
124
|
+
// });
|
|
125
|
+
MEChat.healthcareStart({
|
|
126
|
+
id: "1234567890",
|
|
124
127
|
});
|
|
125
|
-
// MEChat.healthcareStart({
|
|
126
|
-
// id: '1234567890'
|
|
127
|
-
// })
|
|
128
128
|
</script>
|
|
129
129
|
<main>
|
|
130
130
|
<h1>Example Page</h1>
|
package/public/dist/index.js
CHANGED
|
@@ -2930,7 +2930,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
2930
2930
|
${mi}
|
|
2931
2931
|
${gi}
|
|
2932
2932
|
${vi}
|
|
2933
|
-
`,Wi([ue({attribute:!0})],Qi.prototype,"isMinimized",void 0),Wi([ue()],Qi.prototype,"mobileStyles",void 0),Wi([ue({type:Boolean})],Qi.prototype,"isFirstMount",void 0),Wi([ue({attribute:!1})],Qi.prototype,"autoOpenChatWidget",void 0),Wi([ue()],Qi.prototype,"phoneNumber",void 0),Wi([ue({attribute:!0})],Qi.prototype,"buildingName",void 0),Wi([ue({attribute:!0})],Qi.prototype,"chatId",void 0),Wi([ue({attribute:!0})],Qi.prototype,"chatCallUsHeader",void 0),Wi([ue({attribute:!1})],Qi.prototype,"buildingId",void 0),Wi([ue({attribute:!0})],Qi.prototype,"buildingSlug",void 0),Wi([ue({attribute:!0})],Qi.prototype,"orgSlug",void 0),Wi([ue({attribute:!0})],Qi.prototype,"sgtUrl",void 0),Wi([ue({attribute:!0})],Qi.prototype,"designConcept",void 0),Wi([ue({attribute:!0})],Qi.prototype,"featureFlagShowDropdown",void 0),Wi([ue({attribute:!1})],Qi.prototype,"leadSources",void 0),Wi([ue({attribute:!0})],Qi.prototype,"currentLeadSource",void 0),Wi([ue({attribute:!0})],Qi.prototype,"escortedToursLink",void 0),Wi([ue({attribute:!0})],Qi.prototype,"virtualToursLink",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasCallUsEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasChatEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasEmailEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasSSTEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasTextUsEnabled",void 0),Wi([ue({attribute:!1})],Qi.prototype,"layoutOptions",void 0),Wi([ue({attribute:!1})],Qi.prototype,"unitOptions",void 0),Wi([ue({attribute:!1})],Qi.prototype,"tourTypeOptions",void 0),Wi([ue({attribute:!0})],Qi.prototype,"showTourNextToChat",void 0),Wi([ue({attribute:!1})],Qi.prototype,"onChatTapped",void 0),Wi([ue({attribute:!0})],Qi.prototype,"onClickMinimize",void 0),Wi([ue({attribute:!1})],Qi.prototype,"launcherStyles",void 0),Wi([ue({attribute:!0})],Qi.prototype,"brandColor",void 0),Wi([le()],Qi.prototype,"isEmailWindowOpen",void 0),Wi([le()],Qi.prototype,"isCallUsWindowOpen",void 0),Wi([le()],Qi.prototype,"isSSTWindowOpen",void 0),Wi([le()],Qi.prototype,"isTextUsWindowOpen",void 0),Qi=Wi([ae("meetelise-launcher")],Qi);const Vi=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",Qi)};var Ki=n(3379),Xi=n.n(Ki),Yi=n(7795),Zi=n.n(Yi),$i=n(569),er=n.n($i),tr=n(3565),nr=n.n(tr),ir=n(9216),rr=n.n(ir),or=n(4589),ar=n.n(or),sr=n(3631),ur={};async function lr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?dr(n.data,e):[]}catch(e){return[]}}ur.styleTagTransform=ar(),ur.setAttributes=nr(),ur.insert=er().bind(null,"head"),ur.domAPI=Zi(),ur.insertStyleElement=rr(),Xi()(sr.Z,ur),sr.Z&&sr.Z.locals&&sr.Z.locals;const dr=(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 cr,pr=n(9594),hr=n.n(pr),fr=new Uint8Array(16);function mr(){if(!cr&&!(cr="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 cr(fr)}const gr=/^(?:[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,vr=function(e){return"string"==typeof e&&gr.test(e)};for(var yr=[],br=0;br<256;++br)yr.push((br+256).toString(16).substr(1));const wr=function(e,t,n){var i=(e=e||{}).random||(e.rng||mr)();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=(yr[e[t+0]]+yr[e[t+1]]+yr[e[t+2]]+yr[e[t+3]]+"-"+yr[e[t+4]]+yr[e[t+5]]+"-"+yr[e[t+6]]+yr[e[t+7]]+"-"+yr[e[t+8]]+yr[e[t+9]]+"-"+yr[e[t+10]]+yr[e[t+11]]+yr[e[t+12]]+yr[e[t+13]]+yr[e[t+14]]+yr[e[t+15]]).toLowerCase();if(!vr(n))throw TypeError("Stringified UUID is invalid");return n}(i)};var Sr=36e5;const Tr=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Ar=(e,t,n)=>{const i=pn(new Date),r=n||`lead_${wr()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:yn(i),buildingSlug:e,initiatedChat:t}},xr=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(Or(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Or=(e,t)=>!(t.buildingSlug!==e||!t.leadId||!t.timestamp)&&!function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t);return n.getTime()<i.getTime()}(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,n*Sr)}(t.timestamp,24),Date.now());var Cr;!function(e){e.noReply="no-reply",e.text="text"}(Cr||(Cr={}));const Ir=class{constructor(e,t,n,i=null,r){this.apiHost="https://app.meetelise.com",this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==Cr.noReply&&(this.messages=[...this.messages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}]);const n="eliseai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.messages,isLoading:n}),!n&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){ii({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ni.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=Ar(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..."),ii({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),6e4),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(t=this.building)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,userId:null===(n=this.building)||void 0===n?void 0:n.userId,leadSource:this.leadSource}}))})),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.buildingSlug=e,this.building=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`}addChatListener(e){this.chatListener=e}async initializePubnub(e){if(!e.leadId)return;this.leadUserId=e.leadId;const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(hr())({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}`)).data}catch(e){ii({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}async getChannelHistory(){var e;try{const t=await new Promise(((e,t)=>{this.pubnub&&this.channel&&this.pubnub.fetchMessages({channels:[this.channel],count:100},((n,i)=>{n.error?(ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ni.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),t(n)):e(i)}))}));if(this.channel&&0!==Object.keys(t.channels).length){const n=t.channels[this.channel],i=[];n.forEach((e=>{e.uuid&&i.push({channel:e.channel,message:e.message,publisher:e.uuid,subscription:e.channel,timetoken:+e.timetoken})})),this.messages=i.filter((e=>e.message.messageType!==Cr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ni.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}},Nr=(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,ii({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"text-insertion",originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ni.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),ii({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"href-insertion",hrefAttribute:u,originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ni.info,buildingSlug:n,orgSlug:t})}h||ii({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"no-phone-number-found",website:window.location.href},logType:ni.warn,buildingSlug:n,orgSlug:t})};var Er=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 Rr=class extends re{constructor(){super(...arguments),this.onClick=()=>{},this.brandColor=Fe,this.toExpand=!1}render(){return U`
|
|
2933
|
+
`,Wi([ue({attribute:!0})],Qi.prototype,"isMinimized",void 0),Wi([ue()],Qi.prototype,"mobileStyles",void 0),Wi([ue({type:Boolean})],Qi.prototype,"isFirstMount",void 0),Wi([ue({attribute:!1})],Qi.prototype,"autoOpenChatWidget",void 0),Wi([ue()],Qi.prototype,"phoneNumber",void 0),Wi([ue({attribute:!0})],Qi.prototype,"buildingName",void 0),Wi([ue({attribute:!0})],Qi.prototype,"chatId",void 0),Wi([ue({attribute:!0})],Qi.prototype,"chatCallUsHeader",void 0),Wi([ue({attribute:!1})],Qi.prototype,"buildingId",void 0),Wi([ue({attribute:!0})],Qi.prototype,"buildingSlug",void 0),Wi([ue({attribute:!0})],Qi.prototype,"orgSlug",void 0),Wi([ue({attribute:!0})],Qi.prototype,"sgtUrl",void 0),Wi([ue({attribute:!0})],Qi.prototype,"designConcept",void 0),Wi([ue({attribute:!0})],Qi.prototype,"featureFlagShowDropdown",void 0),Wi([ue({attribute:!1})],Qi.prototype,"leadSources",void 0),Wi([ue({attribute:!0})],Qi.prototype,"currentLeadSource",void 0),Wi([ue({attribute:!0})],Qi.prototype,"escortedToursLink",void 0),Wi([ue({attribute:!0})],Qi.prototype,"virtualToursLink",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasCallUsEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasChatEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasEmailEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasSSTEnabled",void 0),Wi([ue({type:Boolean})],Qi.prototype,"hasTextUsEnabled",void 0),Wi([ue({attribute:!1})],Qi.prototype,"layoutOptions",void 0),Wi([ue({attribute:!1})],Qi.prototype,"unitOptions",void 0),Wi([ue({attribute:!1})],Qi.prototype,"tourTypeOptions",void 0),Wi([ue({attribute:!0})],Qi.prototype,"showTourNextToChat",void 0),Wi([ue({attribute:!1})],Qi.prototype,"onChatTapped",void 0),Wi([ue({attribute:!0})],Qi.prototype,"onClickMinimize",void 0),Wi([ue({attribute:!1})],Qi.prototype,"launcherStyles",void 0),Wi([ue({attribute:!0})],Qi.prototype,"brandColor",void 0),Wi([le()],Qi.prototype,"isEmailWindowOpen",void 0),Wi([le()],Qi.prototype,"isCallUsWindowOpen",void 0),Wi([le()],Qi.prototype,"isSSTWindowOpen",void 0),Wi([le()],Qi.prototype,"isTextUsWindowOpen",void 0),Qi=Wi([ae("meetelise-launcher")],Qi);const Vi=()=>{window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",Qi)};var Ki=n(3379),Xi=n.n(Ki),Yi=n(7795),Zi=n.n(Yi),$i=n(569),er=n.n($i),tr=n(3565),nr=n.n(tr),ir=n(9216),rr=n.n(ir),or=n(4589),ar=n.n(or),sr=n(3631),ur={};async function lr(e){try{const n=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/lead-sources`);return n.data?dr(n.data,e):[]}catch(e){return[]}}ur.styleTagTransform=ar(),ur.setAttributes=nr(),ur.insert=er().bind(null,"head"),ur.domAPI=Zi(),ur.insertStyleElement=rr(),Xi()(sr.Z,ur),sr.Z&&sr.Z.locals&&sr.Z.locals;const dr=(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 cr,pr=n(9594),hr=n.n(pr),fr=new Uint8Array(16);function mr(){if(!cr&&!(cr="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 cr(fr)}const gr=/^(?:[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,vr=function(e){return"string"==typeof e&&gr.test(e)};for(var yr=[],br=0;br<256;++br)yr.push((br+256).toString(16).substr(1));const wr=function(e,t,n){var i=(e=e||{}).random||(e.rng||mr)();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=(yr[e[t+0]]+yr[e[t+1]]+yr[e[t+2]]+yr[e[t+3]]+"-"+yr[e[t+4]]+yr[e[t+5]]+"-"+yr[e[t+6]]+yr[e[t+7]]+"-"+yr[e[t+8]]+yr[e[t+9]]+"-"+yr[e[t+10]]+yr[e[t+11]]+yr[e[t+12]]+yr[e[t+13]]+yr[e[t+14]]+yr[e[t+15]]).toLowerCase();if(!vr(n))throw TypeError("Stringified UUID is invalid");return n}(i)};var Sr=36e5;const Tr=e=>localStorage.removeItem("com.elise.webchat.slug="+e),Ar=(e,t,n)=>{const i=pn(new Date),r=n||`lead_${wr()}_${e}`;return localStorage.setItem("com.elise.webchat.slug="+e,JSON.stringify({buildingSlug:e,leadId:r,timestamp:i,initiatedChat:t})),{leadId:r,timestamp:yn(i),buildingSlug:e,initiatedChat:t}},xr=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(Or(e,i))return i}catch(e){console.warn("Error getting chat storage key")}return{leadId:null,timestamp:null,buildingSlug:null,initiatedChat:!1}},Or=(e,t)=>!(t.buildingSlug!==e||!t.leadId||!t.timestamp)&&!function(e,t){Ue(2,arguments);var n=qe(e),i=qe(t);return n.getTime()<i.getTime()}(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,n*Sr)}(t.timestamp,24),Date.now());var Cr;!function(e){e.noReply="no-reply",e.text="text"}(Cr||(Cr={}));const Ir=class{constructor(e,t,n,i=null,r){this.apiHost="https://app.meetelise.com",this.building=null,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.leadSource=null,this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==Cr.noReply&&(this.messages=[...this.messages,{channel:e.channel,message:e.message,publisher:e.publisher,subscription:e.subscription,timetoken:+e.timetoken}]);const n="eliseai"!==e.publisher&&"elise_health_ai"!==e.publisher;null===(t=this.chatListener)||void 0===t||t.call(this,{messages:this.messages,isLoading:n}),!n&&this.eliseResponseTimeout&&clearTimeout(this.eliseResponseTimeout),this.isLoadingMessages=n}},this.isLoadingMessages=!1,this.handleChatListeners=()=>{if(this.pubnub&&this.channel)try{this.pubnub.subscribe({channels:[this.channel]}),this.pubnub.addListener(this.listenerParams)}catch(e){ii({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:ni.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=Ar(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..."),ii({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}),6e4),await this.pubnub.publish({channel:this.channel,message:{text:e,customType:"lead_message",buildingId:null===(t=this.building)||void 0===t?void 0:t.id,buildingSlug:this.buildingSlug,userId:null===(n=this.building)||void 0===n?void 0:n.userId,leadSource:this.leadSource}}))})),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.buildingSlug=e,this.building=t,this.orgSlug=n,this.leadSource=i,this.leadUserId=r,this.channel=`webchat_${r}`}addChatListener(e){this.chatListener=e}async initializePubnub(e){if(!e.leadId)return;this.leadUserId=e.leadId;const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(hr())({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){ii({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:ni.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){ii({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:ni.error,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}async getChannelHistory(){var e;try{const t=await new Promise(((e,t)=>{this.pubnub&&this.channel&&this.pubnub.fetchMessages({channels:[this.channel],count:100},((n,i)=>{n.error?(ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:ni.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug}),t(n)):e(i)}))}));if(this.channel&&0!==Object.keys(t.channels).length){const n=t.channels[this.channel],i=[];n.forEach((e=>{e.uuid&&i.push({channel:e.channel,message:e.message,publisher:e.uuid,subscription:e.channel,timetoken:+e.timetoken})})),this.messages=i.filter((e=>e.message.messageType!==Cr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ii({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:ni.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}},Nr=(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,ii({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"text-insertion",originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ni.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),ii({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"href-insertion",hrefAttribute:u,originalPhoneNumber:p[e].innerHTML,newPhoneNumber:f,website:window.location.href},logType:ni.info,buildingSlug:n,orgSlug:t})}h||ii({logTitle:"DNI_WEBSITE_INSERTION",logData:{type:"no-phone-number-found",website:window.location.href},logType:ni.warn,buildingSlug:n,orgSlug:t})};var Er=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 Rr=class extends re{constructor(){super(...arguments),this.onClick=()=>{},this.brandColor=Fe,this.toExpand=!1}render(){return U`
|
|
2934
2934
|
<div
|
|
2935
2935
|
class=${this.toExpand?"button-container mini":"button-container"}
|
|
2936
2936
|
@click=${this.onClick}
|
|
@@ -3477,8 +3477,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3477
3477
|
<p
|
|
3478
3478
|
class=${fe({"message-text":!0,"webchat-font__desktop":!un(),"webchat-font__mobile":un()})}
|
|
3479
3479
|
>
|
|
3480
|
-
|
|
3481
|
-
questions!
|
|
3480
|
+
Hi, I'm Elise. How can I assist you today?
|
|
3482
3481
|
</p>
|
|
3483
3482
|
</li>
|
|
3484
3483
|
${this.messages.map((e=>{var t,n;return U`
|
package/src/MyPubnub.ts
CHANGED
|
@@ -69,7 +69,9 @@ class MyPubnub {
|
|
|
69
69
|
},
|
|
70
70
|
];
|
|
71
71
|
}
|
|
72
|
-
const isWaitingForEliseResponse =
|
|
72
|
+
const isWaitingForEliseResponse =
|
|
73
|
+
messageEvent.publisher !== "eliseai" &&
|
|
74
|
+
messageEvent.publisher !== "elise_health_ai";
|
|
73
75
|
this.chatListener?.({
|
|
74
76
|
messages: this.messages,
|
|
75
77
|
isLoading: isWaitingForEliseResponse,
|
|
@@ -117,7 +119,7 @@ class MyPubnub {
|
|
|
117
119
|
|
|
118
120
|
// These keys are OK to expose live, the authKey generated by the BE is what
|
|
119
121
|
// is used to authenticate the user. Ideally, should also add rate limiting
|
|
120
|
-
// and/or IP whitelisting to the BE endpoint that generates the token
|
|
122
|
+
// and/or IP whitelisting to the BE endpoint that generates the token!
|
|
121
123
|
this.pubnub = new Pubnub({
|
|
122
124
|
publishKey: pubnubToken.keys.publish_key,
|
|
123
125
|
subscribeKey: pubnubToken.keys.subscribe_key,
|
|
@@ -134,7 +136,11 @@ class MyPubnub {
|
|
|
134
136
|
): Promise<TokenResponse | null> {
|
|
135
137
|
try {
|
|
136
138
|
const response = await axios.get(
|
|
137
|
-
`${
|
|
139
|
+
`${
|
|
140
|
+
this.apiHost
|
|
141
|
+
}/platformApi/webchat/pn/request-token?user_id=${lead}&channel=${channel}&${
|
|
142
|
+
this.building ? "" : `industry=health_care`
|
|
143
|
+
}`
|
|
138
144
|
);
|
|
139
145
|
return response.data;
|
|
140
146
|
} catch (error) {
|
|
@@ -180,8 +180,7 @@ export class PubnubChat extends LitElement {
|
|
|
180
180
|
["webchat-font__mobile"]: isMobile(),
|
|
181
181
|
})}
|
|
182
182
|
>
|
|
183
|
-
|
|
184
|
-
questions!
|
|
183
|
+
Hi, I'm Elise. How can I assist you today?
|
|
185
184
|
</p>
|
|
186
185
|
</li>
|
|
187
186
|
${this.messages.map((message) => {
|