@meetelise/chat 1.20.130 → 1.20.132
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
|
@@ -122,6 +122,9 @@
|
|
|
122
122
|
organization: "test-company",
|
|
123
123
|
building: "3fc93384-91f5-11ed-98a3-43f5a2f42588",
|
|
124
124
|
|
|
125
|
+
// organization: "d1a1060d-3844-48d4-a454-1ba26292bc69",
|
|
126
|
+
// building: "25feb690-c76f-11ed-83b9-a7aa9698a486",
|
|
127
|
+
|
|
125
128
|
// organization: "TT",
|
|
126
129
|
// building: "ffc97070-5c73-11ed-8507-77860136d3bf",
|
|
127
130
|
|
|
@@ -157,7 +160,7 @@
|
|
|
157
160
|
// building: "1ac49f90-6150-11ed-b327-1b3f05e7b9db",
|
|
158
161
|
|
|
159
162
|
// organization: "sparrow",
|
|
160
|
-
// building: "
|
|
163
|
+
// building: "8e87ae6e-eae8-11ed-aae8-fb82f4692a79",
|
|
161
164
|
});
|
|
162
165
|
</script>
|
|
163
166
|
<main>
|
package/public/dist/index.js
CHANGED
|
@@ -3159,7 +3159,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3159
3159
|
display: none;
|
|
3160
3160
|
}
|
|
3161
3161
|
.redirect-link {
|
|
3162
|
-
color:
|
|
3162
|
+
color: inherit;
|
|
3163
3163
|
}
|
|
3164
3164
|
|
|
3165
3165
|
#loading-message {
|
|
@@ -3277,7 +3277,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3277
3277
|
-webkit-line-clamp: 2;
|
|
3278
3278
|
overflow: hidden;
|
|
3279
3279
|
text-overflow: ellipsis;
|
|
3280
|
-
height: 24px;
|
|
3280
|
+
max-height: 24px;
|
|
3281
3281
|
}
|
|
3282
3282
|
.website-preview-description {
|
|
3283
3283
|
font-size: 10px;
|
|
@@ -3333,19 +3333,19 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3333
3333
|
cursor: pointer;
|
|
3334
3334
|
width: fit-content;
|
|
3335
3335
|
}
|
|
3336
|
-
`;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.onMount=()=>({}),this.loadingPreviews=!0,this.websitePreviewInfo=[],this.imagesToDisplay=[],this.imageUrlError=[]
|
|
3336
|
+
`;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.onMount=()=>({}),this.loadingPreviews=!0,this.websitePreviewInfo=[],this.imagesToDisplay=[],this.imageUrlError=[]}firstUpdated(){if(!this.message)return;const{hyperlinks:e,markedText:t}=this.mapAndMarkHyperLinks(this.message.message.text),n=/(https?:\/\/[^\s]+)/g,i=[],r=[];this.parsedMessage=k`${t.split("\n").map((t=>{const o=t.split(" ");return o?k`${o.map((t=>{if(e.find((e=>e.id===t))){const n=e.find((e=>e.id===t));if(!n)return;return r.push({redirectTo:null==n?void 0:n.link,source:null==n?void 0:n.link}),k`<a
|
|
3337
3337
|
class="redirect-link"
|
|
3338
3338
|
href="${null==n?void 0:n.link}"
|
|
3339
3339
|
target="_blank"
|
|
3340
3340
|
rel="noopener noreferrer"
|
|
3341
3341
|
>${null==n?void 0:n.hyperlink}
|
|
3342
|
-
</a>`}
|
|
3342
|
+
</a>`}if(n.test(t)){const e=this.removeTrailingPunctuation(t);return i.push(this.getLinkData(e)),k`<a
|
|
3343
3343
|
class="redirect-link"
|
|
3344
|
-
href="${
|
|
3344
|
+
href="${e}"
|
|
3345
3345
|
target="_blank"
|
|
3346
3346
|
rel="noopener noreferrer"
|
|
3347
|
-
>${
|
|
3348
|
-
</a>`
|
|
3347
|
+
>${e}
|
|
3348
|
+
</a>`}return k`${t} `}))}<br />`:k``}))}`,this.imagesToDisplay=r,Promise.all(i).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?:\/\/[^|]+\|[^>]+>/g)),n=[];return t.forEach((t=>{try{const i=t[0].split("|")[0].replace("<",""),r=t[0].split("|")[1].replace(">","");if(i&&r){const o=Sr().replace(/-/g,"");n.push({link:this.removeTrailingPunctuation(i),hyperlink:this.removeTrailingPunctuation(r),mark:t[0],id:o}),e=e.replace(t[0],o)}}catch(e){}})),{hyperlinks:n,markedText:e}}async getLinkData(e){var n,i,r,o,a,s;try{const u=(await t().get(e)).data,l=(new DOMParser).parseFromString(u,"text/html");return l?{title:null!==(i=null===(n=l.querySelector("title"))||void 0===n?void 0:n.textContent)&&void 0!==i?i:null,description:(null===(r=l.querySelector('meta[name="description"]'))||void 0===r?void 0:r.getAttribute("content"))||null,image:(null===(o=l.querySelector('meta[property="og:image"]'))||void 0===o?void 0:o.getAttribute("content"))||null,favicon:(null===(a=l.querySelector('link[rel="shortcut icon"]'))||void 0===a?void 0:a.getAttribute("href"))||(null===(s=l.querySelector('link[rel="icon"]'))||void 0===s?void 0:s.getAttribute("href"))||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}}}updated(){this.onMount()}render(){return this.message?k`<div class="message-inner-body">
|
|
3349
3349
|
<p class="message-text">${this.parsedMessage}</p>
|
|
3350
3350
|
${this.websitePreviewInfo.length>0&&this.websitePreviewInfo.some((e=>e.title&&(e.image||e.favicon)))?k`<br />`:""}
|
|
3351
3351
|
${this.imagesToDisplay.map((e=>k`<a
|
|
@@ -3375,9 +3375,9 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3375
3375
|
|
|
3376
3376
|
<div class="website-preview-body">
|
|
3377
3377
|
<p class="message-text website-preview-title">${e.title}</p>
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3378
|
+
${e.description?k`<p class="message-text website-preview-description">
|
|
3379
|
+
${e.description}
|
|
3380
|
+
</p>`:""}
|
|
3381
3381
|
</div>
|
|
3382
3382
|
</div>
|
|
3383
3383
|
</a></div> `}))}
|
|
@@ -3492,7 +3492,7 @@ otherwise there's some empty space at the bottom of the button, which interferes
|
|
|
3492
3492
|
</button>
|
|
3493
3493
|
</div>
|
|
3494
3494
|
</div>
|
|
3495
|
-
`:k``}};_r.styles=[Nr],Pr([ue({attribute:!0})],_r.prototype,"onMount",void 0),Pr([ue({attribute:!0})],_r.prototype,"channel",void 0),Pr([ue({attribute:!0})],_r.prototype,"myPubnub",void 0),Pr([ue({attribute:!0})],_r.prototype,"buildingSlug",void 0),Pr([ue({attribute:!0})],_r.prototype,"building",void 0),Pr([ue({attribute:!0})],_r.prototype,"brandColor",void 0),Pr([ue({attribute:!0})],_r.prototype,"onClickExit",void 0),Pr([ue({attribute:!0})],_r.prototype,"requiresConsent",void 0),Pr([de("#message-input",!0)],_r.prototype,"messageInput",void 0),Pr([de("#conversation-body",!0)],_r.prototype,"messageBody",void 0),Pr([le()],_r.prototype,"messages",void 0),Pr([le()],_r.prototype,"isMobile",void 0),Pr([le()],_r.prototype,"isLoadingMessages",void 0),Pr([le()],_r.prototype,"hasReceivedConsent",void 0),Pr([le()],_r.prototype,"privacyPolicyUrl",void 0),Pr([le()],_r.prototype,"websitePreviewMapping",void 0),_r=Pr([ae("pubnub-chat")],_r);const Fr={};var Mr=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a};let Dr=class extends re{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.chatId="",this.analytics=null,this.isMobile=Un(),this.launcher=null,this.building=null,this.designConcept=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=Vn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.showTourNextToChat=!1,this.displayPubnubChat=!1,this.myPubnub=null,this.enabledChatWidgets={call:!0,chat:!0,email:!0,text:!0,sst:!0},this.webchatConfigHasAutoOpenChat=!1,this.requiresConsent=!1,this.privacyPolicyUrl="http://bit.ly/me_privacy_policy",this.launcherRef=Ae(),this.firstUpdated=async()=>{await this.setBuildingDerivedInfo(),await this.initializeChatVariables(),this.handleChatInitializeAnalytics()},this.setBuildingDerivedInfo=async()=>{var e,n,i,r,o,a,s,u,l,d,c,p,h,f,m,g,v,y;if(!this.buildingSlug||!this.orgSlug)return;const b=await hi(this.orgSlug,this.buildingSlug);if(1!==b.active)return;const[w,S,T,A,x,O,C]=await Promise.all([vi(this.buildingSlug),cr(this.buildingSlug),yi(this.buildingSlug,document.referrer),Kn(this.buildingSlug),Xn(this.buildingSlug),gi(b.id),Yn(this.buildingSlug)]);b.phoneNumber=Ne(b.phoneNumber),this.building=b,this.designConcept=null!==(e=null==w?void 0:w.abTestType)&&void 0!==e?e:"",this.leadSources=S,this.currentLeadSource=T,this.featureFlagShowDropdown=A;const I=await(async e=>{if(Fr[e])return Fr[e];try{const n=`https://app.meetelise.com/sms_management_numbers/webchat/building/${e}/numbers`,i=await t().get(n);return Fr[e]=i.data,i.data}catch(t){return ai({logTitle:"ERROR_LOADING_PHONE_NUMBERS",logData:{error:t,buildingId:e},logType:oi.error}),[]}})(b.id);this.enabledChatWidgets={call:O&&!O.isGlobalDefault?O.config.shouldShowPhone:null===(r=null===(i=null===(n=this.building)||void 0===n?void 0:n.chatWidgets)||void 0===i?void 0:i.includes("CALL"))||void 0===r||r,chat:O&&!O.isGlobalDefault?O.config.shouldShowChat:null===(s=null===(a=null===(o=this.building)||void 0===o?void 0:o.chatWidgets)||void 0===a?void 0:a.includes("CHAT"))||void 0===s||s,email:O&&!O.isGlobalDefault?O.config.shouldShowEmail:null===(d=null===(l=null===(u=this.building)||void 0===u?void 0:u.chatWidgets)||void 0===l?void 0:l.includes("EMAIL"))||void 0===d||d,text:(O&&!O.isGlobalDefault?O.config.shouldShowText:null===(h=null===(p=null===(c=this.building)||void 0===c?void 0:c.chatWidgets)||void 0===p?void 0:p.includes("SMS"))||void 0===h||h)&&I.length>0,sst:O&&!O.isGlobalDefault?O.config.shouldShowSst:null===(g=null===(m=null===(f=this.building)||void 0===f?void 0:f.chatWidgets)||void 0===m?void 0:m.includes("SST"))||void 0===g||g},O&&O.config&&(this.brandColor=null!==(v=O.config.primaryColor)&&void 0!==v?v:null,this.webchatConfigHasAutoOpenChat=O.config.autoOpenChat,this.requiresConsent=O.config.requiresConsent,this.privacyPolicyUrl=null!==(y=O.config.privacyPolicyUrl)&&void 0!==y?y:this.privacyPolicyUrl,O.config.displayStyle===fi.MINIMIZED&&(this.isMinimized=!0),O.config.displayStyle===fi.PILLS&&(this.designConcept=null),O.config.displayStyle===fi.EMOJI&&(this.designConcept=fi.EMOJI)),null===this.brandColor&&(this.brandColor=Fe);let N=null;x&&(N=await async function(e,n){try{const i=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/phone-number-by-source?source=${n}`);return i.data?{number:Ne(i.data.number),isMatch:i.data.isMatch,isPropertyWebsiteCatchall:i.data.isPropertyWebsiteCatchall}:null}catch(e){return null}}(this.buildingSlug,this.currentLeadSource)),C&&(null==N?void 0:N.number)&&Or(N.number,this.orgSlug,this.buildingSlug);const E=localStorage.getItem("eliseai_phone_number_devtest");E&&(console.info("Using dev test phone number: ",E),Or(E,this.orgSlug,this.buildingSlug)),this.phoneNumberForSource=N||{number:this.building.phoneNumber,isMatch:!1,isPropertyWebsiteCatchall:!0},this.currentLeadSource&&(this.leadSources.includes(this.currentLeadSource)||this.leadSources.push(this.currentLeadSource)),An(this.building.id)},this.initializeChatVariables=async()=>{this.building&&(this.building.conversationMaintenanceMode?console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear."):(this.myPubnub=new class{constructor(e,t,n){this.apiHost="https://app.meetelise.com",this.building=null,this.ttlHours=24,this.eliseResponseTimeout=null,this.pubnub=null,this.leadUserId="",this.channel="",this.chatListener=null,this.messages=[],this.listenerParams={message:e=>{var t;e.message.messageType!==Tr.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){ai({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:oi.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&&!await this.initializePubnub())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..."),ai({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:oi.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}}))})),!1===this.isLoadingMessages&&(this.isLoadingMessages=!0)}},this.isLeadMessage=e=>e.publisher.includes("lead_")&&"lead_message"===e.message.customType,this.clearChatStorageKey=()=>localStorage.removeItem("com.eliseai.webchat.slug="+this.buildingSlug),this.createChatStorageKey=e=>{const t=tn(new Date),n=null!=e?e:`lead_${Sr()}_${this.buildingSlug}`;return localStorage.setItem("com.eliseai.webchat.slug="+this.buildingSlug,JSON.stringify({buildingSlug:this.buildingSlug,leadId:n,timestamp:t})),{leadId:n,timestamp:un(t),buildingSlug:this.buildingSlug}},this.getChatStorageKey=(e=!0)=>{const t=localStorage.getItem("com.eliseai.webchat.slug="+this.buildingSlug);if(t)try{const e=JSON.parse(t),n=e.buildingSlug,i=e.leadId,r=new Date(e.timestamp);if(this.isChatKeyValid({leadId:i,timestamp:r,buildingSlug:n}))return{leadId:i,timestamp:r,buildingSlug:n}}catch(e){console.warn("Error getting chat storage key")}return e?this.createChatStorageKey():{leadId:null,timestamp:null,buildingSlug:null}},this.isChatKeyValid=e=>!(e.buildingSlug!==this.buildingSlug||!e.leadId||!e.timestamp||function(e,t){ke(2,arguments);var n=qe(e),i=qe(t);return n.getTime()<i.getTime()}(xr(e.timestamp,this.ttlHours),Date.now())),this.buildingSlug=e,this.building=t,this.orgSlug=n}addChatListener(e){this.chatListener=e}async initializePubnub(){const e=this.getChatStorageKey();if(!e.leadId)return void ai({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:oi.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug});this.leadUserId=e.leadId,this.channel=`webchat_${this.leadUserId}`,e.timestamp&&function(e,t){ke(2,arguments);var n=qe(e),i=qe(t);return n.getTime()>i.getTime()}(e.timestamp,xr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(fr())({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){ai({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:oi.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){ai({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:oi.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){ai({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:oi.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?(ai({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:oi.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!==Tr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ai({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:oi.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}(this.buildingSlug,this.building,this.orgSlug),this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey(!1))&&await this.myPubnub.initializePubnub(),this.attachOnClickToLauncher(),this.shouldAutoOpenChat(this.webchatConfigHasAutoOpenChat)&&(this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp()),this.isLoading=!1))},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!an(un(t)));return!!e&&!!n&&!Un()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){ke(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.handleContactClicked=e=>{var t;this.displayPubnubChat=!1,this.hideLauncher=!1,this.showTourNextToChat=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.showTourNextToChat?null===(t=this.launcherRef.value)||void 0===t||t.onClickSSTOption(e):(this.hideLauncher?this.showTourNextToChat=!0:this.displayPubnubChat=!1,this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e))},this.handleContactTabClicked=e=>{var t;this.displayPubnubChat=!1,this.showTourNextToChat=!1,this.hideLauncher=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickPhoneOption(e)},this.adjustPositionChatAdditionalActions=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("chatAdditionalActionsPubnub");if(!r)return;const o=null===(i=null===(n=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("pubnub-chat"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.getElementById("pubnub-chat-container"),a=null==o?void 0:o.getBoundingClientRect();a&&(r.style.left=`${a.left}px`,r.style.top=`${a.bottom}px`)},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized,this.showTourNextToChat=!1},this.attachOnClickToLauncher=()=>{const e=this.launcherRef.value;e&&(e.onChatTapped=async()=>{this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0})},this.renderChatAdditionalActions=(e,t)=>k` <div
|
|
3495
|
+
`:k``}};_r.styles=[Nr],Pr([ue({attribute:!0})],_r.prototype,"onMount",void 0),Pr([ue({attribute:!0})],_r.prototype,"channel",void 0),Pr([ue({attribute:!0})],_r.prototype,"myPubnub",void 0),Pr([ue({attribute:!0})],_r.prototype,"buildingSlug",void 0),Pr([ue({attribute:!0})],_r.prototype,"building",void 0),Pr([ue({attribute:!0})],_r.prototype,"brandColor",void 0),Pr([ue({attribute:!0})],_r.prototype,"onClickExit",void 0),Pr([ue({attribute:!0})],_r.prototype,"requiresConsent",void 0),Pr([de("#message-input",!0)],_r.prototype,"messageInput",void 0),Pr([de("#conversation-body",!0)],_r.prototype,"messageBody",void 0),Pr([le()],_r.prototype,"messages",void 0),Pr([le()],_r.prototype,"isMobile",void 0),Pr([le()],_r.prototype,"isLoadingMessages",void 0),Pr([le()],_r.prototype,"hasReceivedConsent",void 0),Pr([le()],_r.prototype,"privacyPolicyUrl",void 0),Pr([le()],_r.prototype,"websitePreviewMapping",void 0),_r=Pr([ae("pubnub-chat")],_r);const Fr={};var Mr=function(e,t,n,i){var r,o=arguments.length,a=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(a=(o<3?r(a):o>3?r(t,n,a):r(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a};let Dr=class extends re{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.chatId="",this.analytics=null,this.isMobile=Un(),this.launcher=null,this.building=null,this.designConcept=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=Vn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.showTourNextToChat=!1,this.displayPubnubChat=!1,this.myPubnub=null,this.enabledChatWidgets={call:!0,chat:!0,email:!0,text:!0,sst:!0},this.webchatConfigHasAutoOpenChat=!1,this.requiresConsent=!1,this.privacyPolicyUrl="http://bit.ly/me_privacy_policy",this.launcherRef=Ae(),this.firstUpdated=async()=>{await this.setBuildingDerivedInfo(),await this.initializeChatVariables(),this.handleChatInitializeAnalytics()},this.setBuildingDerivedInfo=async()=>{var e,n,i,r,o,a,s,u,l,d,c,p,h,f,m,g,v,y;if(!this.buildingSlug||!this.orgSlug)return;const b=await hi(this.orgSlug,this.buildingSlug);if(1!==b.active)return;const[w,S,T,A,x,O,C]=await Promise.all([vi(this.buildingSlug),cr(this.buildingSlug),yi(this.buildingSlug,document.referrer),Kn(this.buildingSlug),Xn(this.buildingSlug),gi(b.id),Yn(this.buildingSlug)]);b.phoneNumber=Ne(b.phoneNumber),this.building=b,this.designConcept=null!==(e=null==w?void 0:w.abTestType)&&void 0!==e?e:"",this.leadSources=S,this.currentLeadSource=T,this.featureFlagShowDropdown=A;const I=await(async e=>{if(Fr[e])return Fr[e];try{const n=`https://app.meetelise.com/sms_management_numbers/webchat/building/${e}/numbers`,i=await t().get(n);return Fr[e]=i.data,i.data}catch(t){return ai({logTitle:"ERROR_LOADING_PHONE_NUMBERS",logData:{error:t,buildingId:e},logType:oi.error}),[]}})(b.id);this.enabledChatWidgets={call:O&&!O.isGlobalDefault?O.config.shouldShowPhone:null===(r=null===(i=null===(n=this.building)||void 0===n?void 0:n.chatWidgets)||void 0===i?void 0:i.includes("CALL"))||void 0===r||r,chat:O&&!O.isGlobalDefault?O.config.shouldShowChat:null===(s=null===(a=null===(o=this.building)||void 0===o?void 0:o.chatWidgets)||void 0===a?void 0:a.includes("CHAT"))||void 0===s||s,email:O&&!O.isGlobalDefault?O.config.shouldShowEmail:null===(d=null===(l=null===(u=this.building)||void 0===u?void 0:u.chatWidgets)||void 0===l?void 0:l.includes("EMAIL"))||void 0===d||d,text:(O&&!O.isGlobalDefault?O.config.shouldShowText:null===(h=null===(p=null===(c=this.building)||void 0===c?void 0:c.chatWidgets)||void 0===p?void 0:p.includes("SMS"))||void 0===h||h)&&I.length>0,sst:O&&!O.isGlobalDefault?O.config.shouldShowSst:null===(g=null===(m=null===(f=this.building)||void 0===f?void 0:f.chatWidgets)||void 0===m?void 0:m.includes("SST"))||void 0===g||g},O&&O.config&&(this.brandColor=null!==(v=O.config.primaryColor)&&void 0!==v?v:null,this.webchatConfigHasAutoOpenChat=O.config.autoOpenChat,this.requiresConsent=O.config.requiresConsent,this.privacyPolicyUrl=null!==(y=O.config.privacyPolicyUrl)&&void 0!==y?y:this.privacyPolicyUrl,O.config.displayStyle===fi.MINIMIZED&&(this.isMinimized=!0),O.config.displayStyle===fi.PILLS&&(this.designConcept=null),O.config.displayStyle===fi.EMOJI&&(this.designConcept=fi.EMOJI)),null===this.brandColor&&(this.brandColor=Fe);let N=null;x&&(N=await async function(e,n){try{const i=await t().get(`https://app.meetelise.com/platformApi/webchat/${e}/phone-number-by-source?source=${n}`);return i.data?{number:Ne(i.data.number),isMatch:i.data.isMatch,isPropertyWebsiteCatchall:i.data.isPropertyWebsiteCatchall}:null}catch(e){return null}}(this.buildingSlug,this.currentLeadSource)),C&&(null==N?void 0:N.number)&&Or(N.number,this.orgSlug,this.buildingSlug);const E=localStorage.getItem("eliseai_phone_number_devtest");E&&(console.info("Using dev test phone number: ",E),Or(E,this.orgSlug,this.buildingSlug)),this.phoneNumberForSource=N||{number:this.building.phoneNumber,isMatch:!1,isPropertyWebsiteCatchall:!0},this.currentLeadSource&&(this.leadSources.includes(this.currentLeadSource)||this.leadSources.push(this.currentLeadSource)),An(this.building.id)},this.initializeChatVariables=async()=>{this.building&&(this.building.conversationMaintenanceMode?console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear."):(this.myPubnub=new class{constructor(e,t,n,i=null){this.apiHost="https://app.meetelise.com",this.building=null,this.ttlHours=24,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!==Tr.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){ai({logTitle:"PUBNUB_ERROR_ADDING_LISTENER",logData:{error:e,channel:this.channel,leadUserId:this.leadUserId,website:location.href},logType:oi.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&&!await this.initializePubnub())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..."),ai({logTitle:"PUBNUB_ERROR_ELISEAI_MESSAGE_TIMEOUT",logData:{channel:this.channel,leadUserId:this.leadUserId,message:e},logType:oi.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.clearChatStorageKey=()=>localStorage.removeItem("com.eliseai.webchat.slug="+this.buildingSlug),this.createChatStorageKey=e=>{const t=tn(new Date),n=null!=e?e:`lead_${Sr()}_${this.buildingSlug}`;return localStorage.setItem("com.eliseai.webchat.slug="+this.buildingSlug,JSON.stringify({buildingSlug:this.buildingSlug,leadId:n,timestamp:t})),{leadId:n,timestamp:un(t),buildingSlug:this.buildingSlug}},this.getChatStorageKey=(e=!0)=>{const t=localStorage.getItem("com.eliseai.webchat.slug="+this.buildingSlug);if(t)try{const e=JSON.parse(t),n=e.buildingSlug,i=e.leadId,r=new Date(e.timestamp);if(this.isChatKeyValid({leadId:i,timestamp:r,buildingSlug:n}))return{leadId:i,timestamp:r,buildingSlug:n}}catch(e){console.warn("Error getting chat storage key")}return e?this.createChatStorageKey():{leadId:null,timestamp:null,buildingSlug:null}},this.isChatKeyValid=e=>!(e.buildingSlug!==this.buildingSlug||!e.leadId||!e.timestamp||function(e,t){ke(2,arguments);var n=qe(e),i=qe(t);return n.getTime()<i.getTime()}(xr(e.timestamp,this.ttlHours),Date.now())),this.buildingSlug=e,this.building=t,this.orgSlug=n,this.leadSource=i}addChatListener(e){this.chatListener=e}async initializePubnub(){const e=this.getChatStorageKey();if(!e.leadId)return void ai({logTitle:"PUBNUB_ERROR_FETCHING_STORAGE_KEY",logData:{channel:this.channel,eliseaiLocalStorageValue:e,leadUserId:this.leadUserId},logType:oi.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug});this.leadUserId=e.leadId,this.channel=`webchat_${this.leadUserId}`,e.timestamp&&function(e,t){ke(2,arguments);var n=qe(e),i=qe(t);return n.getTime()>i.getTime()}(e.timestamp,xr(new Date,this.ttlHours))&&this.createChatStorageKey(this.leadUserId);const t=await this.fetchToken(this.leadUserId,this.channel);return t?(this.pubnub=new(fr())({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){ai({logTitle:"PUBNUB_ERROR_FETCHING_TOKEN",logData:{error:e},logType:oi.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){ai({logTitle:"PUBNUB_ERROR_FETCHING_CHANNEL_EXISTS",logData:{error:e},logType:oi.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){ai({logTitle:"PUBNUB_ERROR_REFETCHING_TOKEN",logData:{retryError:e},logType:oi.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?(ai({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{channel:this.channel,status:n,response:i},logType:oi.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!==Tr.noReply)),null===(e=this.chatListener)||void 0===e||e.call(this,{messages:this.messages,isLoading:!1})}}catch(e){ai({logTitle:"PUBNUB_WARN_FETCHING_HISTORY",logData:{error:e},logType:oi.warn,buildingSlug:this.buildingSlug,orgSlug:this.orgSlug})}}}(this.buildingSlug,this.building,this.orgSlug,this.currentLeadSource),this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey(!1))&&await this.myPubnub.initializePubnub(),this.attachOnClickToLauncher(),this.shouldAutoOpenChat(this.webchatConfigHasAutoOpenChat)&&(this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0,this.updateAlreadyAutoOpenedTimestamp()),this.isLoading=!1))},this.shouldAutoOpenChat=e=>{const t=sessionStorage.getItem("alreadyAutoOpenedTimestamp"),n=!t||!(t&&!an(un(t)));return!!e&&!!n&&!Un()},this.updateAlreadyAutoOpenedTimestamp=()=>{sessionStorage.setItem("alreadyAutoOpenedTimestamp",tn(function(e,t){ke(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15)))},this.handleContactClicked=e=>{var t;this.displayPubnubChat=!1,this.hideLauncher=!1,this.showTourNextToChat=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;this.showTourNextToChat?null===(t=this.launcherRef.value)||void 0===t||t.onClickSSTOption(e):(this.hideLauncher?this.showTourNextToChat=!0:this.displayPubnubChat=!1,this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e))},this.handleContactTabClicked=e=>{var t;this.displayPubnubChat=!1,this.showTourNextToChat=!1,this.hideLauncher=!1,null===(t=this.launcherRef.value)||void 0===t||t.onClickPhoneOption(e)},this.adjustPositionChatAdditionalActions=()=>{var e,t,n,i;const r=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("chatAdditionalActionsPubnub");if(!r)return;const o=null===(i=null===(n=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("pubnub-chat"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.getElementById("pubnub-chat-container"),a=null==o?void 0:o.getBoundingClientRect();a&&(r.style.left=`${a.left}px`,r.style.top=`${a.bottom}px`)},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized,this.showTourNextToChat=!1},this.attachOnClickToLauncher=()=>{const e=this.launcherRef.value;e&&(e.onChatTapped=async()=>{this.displayPubnubChat=!0,this.hideLauncher=!0,this.hasMounted=!0})},this.renderChatAdditionalActions=(e,t)=>k` <div
|
|
3496
3496
|
id=${e}
|
|
3497
3497
|
class=${fe({showTab:t,hideTab:!t})}
|
|
3498
3498
|
>
|
package/src/MyPubnub.ts
CHANGED
|
@@ -59,6 +59,7 @@ class MyPubnub {
|
|
|
59
59
|
pubnub: Pubnub | null = null;
|
|
60
60
|
leadUserId = "";
|
|
61
61
|
channel = "";
|
|
62
|
+
leadSource: string | null = null;
|
|
62
63
|
|
|
63
64
|
chatListener:
|
|
64
65
|
| ((res: { messages: ChatMessage[]; isLoading: boolean }) => void)
|
|
@@ -96,11 +97,13 @@ class MyPubnub {
|
|
|
96
97
|
constructor(
|
|
97
98
|
buildingSlug: string,
|
|
98
99
|
buildingDetails: Building,
|
|
99
|
-
orgSlug: string
|
|
100
|
+
orgSlug: string,
|
|
101
|
+
leadSource: string | null = null
|
|
100
102
|
) {
|
|
101
103
|
this.buildingSlug = buildingSlug;
|
|
102
104
|
this.building = buildingDetails;
|
|
103
105
|
this.orgSlug = orgSlug;
|
|
106
|
+
this.leadSource = leadSource;
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
addChatListener(
|
|
@@ -369,6 +372,7 @@ class MyPubnub {
|
|
|
369
372
|
buildingId: this.building?.id,
|
|
370
373
|
buildingSlug: this.buildingSlug,
|
|
371
374
|
userId: this.building?.userId, // this userid is actually the AI user!
|
|
375
|
+
leadSource: this.leadSource,
|
|
372
376
|
},
|
|
373
377
|
});
|
|
374
378
|
});
|
|
@@ -315,7 +315,8 @@ export class MEChat extends LitElement {
|
|
|
315
315
|
this.myPubnub = new MyPubnub(
|
|
316
316
|
this.buildingSlug,
|
|
317
317
|
this.building,
|
|
318
|
-
this.orgSlug
|
|
318
|
+
this.orgSlug,
|
|
319
|
+
this.currentLeadSource
|
|
319
320
|
);
|
|
320
321
|
if (this.myPubnub.isChatKeyValid(this.myPubnub.getChatStorageKey(false))) {
|
|
321
322
|
await this.myPubnub.initializePubnub();
|
|
@@ -133,7 +133,7 @@ export const pubnubChatStyles = css`
|
|
|
133
133
|
display: none;
|
|
134
134
|
}
|
|
135
135
|
.redirect-link {
|
|
136
|
-
color:
|
|
136
|
+
color: inherit;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
#loading-message {
|
|
@@ -251,7 +251,7 @@ export const pubnubChatStyles = css`
|
|
|
251
251
|
-webkit-line-clamp: 2;
|
|
252
252
|
overflow: hidden;
|
|
253
253
|
text-overflow: ellipsis;
|
|
254
|
-
height: 24px;
|
|
254
|
+
max-height: 24px;
|
|
255
255
|
}
|
|
256
256
|
.website-preview-description {
|
|
257
257
|
font-size: 10px;
|
|
@@ -53,12 +53,11 @@ export class PubnubMessage extends LitElement {
|
|
|
53
53
|
const urlRegex = /(https?:\/\/[^\s]+)/g; // Regular expression to match URLs
|
|
54
54
|
const loadingWebsitePreviews: Promise<WebsitePreview>[] = [];
|
|
55
55
|
const imagesToDisplay: ImageToDisplay[] = [];
|
|
56
|
+
|
|
56
57
|
this.parsedMessage = html`${markedText.split("\n").map((line) => {
|
|
57
|
-
const allWords = line.
|
|
58
|
-
/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|])|(\b[\w':]+\b)|([.,;!?])/gi
|
|
59
|
-
);
|
|
58
|
+
const allWords = line.split(" ");
|
|
60
59
|
if (!allWords) return html``;
|
|
61
|
-
return html`${allWords.map((word
|
|
60
|
+
return html`${allWords.map((word) => {
|
|
62
61
|
if (hyperlinks.find((obj) => obj.id === word)) {
|
|
63
62
|
// EliseAI made hyperlink
|
|
64
63
|
const link = hyperlinks.find((obj) => obj.id === word);
|
|
@@ -77,21 +76,16 @@ export class PubnubMessage extends LitElement {
|
|
|
77
76
|
}
|
|
78
77
|
if (urlRegex.test(word)) {
|
|
79
78
|
// general url
|
|
80
|
-
|
|
79
|
+
const link = this.removeTrailingPunctuation(word);
|
|
80
|
+
loadingWebsitePreviews.push(this.getLinkData(link));
|
|
81
81
|
return html`<a
|
|
82
82
|
class="redirect-link"
|
|
83
|
-
href="${
|
|
83
|
+
href="${link}"
|
|
84
84
|
target="_blank"
|
|
85
85
|
rel="noopener noreferrer"
|
|
86
|
-
>${
|
|
86
|
+
>${link}
|
|
87
87
|
</a>`;
|
|
88
88
|
} else {
|
|
89
|
-
if (
|
|
90
|
-
// add a space only if the next word is not a punctuation
|
|
91
|
-
index + 1 < allWords.length &&
|
|
92
|
-
this.isPunctuation(allWords[index + 1])
|
|
93
|
-
)
|
|
94
|
-
return html`${word}`;
|
|
95
89
|
return html`${word} `;
|
|
96
90
|
}
|
|
97
91
|
})}<br />`;
|
|
@@ -101,10 +95,14 @@ export class PubnubMessage extends LitElement {
|
|
|
101
95
|
this.websitePreviewInfo = results;
|
|
102
96
|
});
|
|
103
97
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
|
|
99
|
+
private removeTrailingPunctuation(text: string): string {
|
|
100
|
+
const punctuation = [".", ",", "!", "?", ":", ";"];
|
|
101
|
+
if (punctuation.includes(text[text.length - 1])) {
|
|
102
|
+
return this.removeTrailingPunctuation(text.slice(0, -1));
|
|
103
|
+
}
|
|
104
|
+
return text;
|
|
105
|
+
}
|
|
108
106
|
|
|
109
107
|
private mapAndMarkHyperLinks(text: string): {
|
|
110
108
|
hyperlinks: {
|
|
@@ -129,8 +127,8 @@ export class PubnubMessage extends LitElement {
|
|
|
129
127
|
if (link && hyperlink) {
|
|
130
128
|
const uniqueKeyMark = uuid().replace(/-/g, "");
|
|
131
129
|
listHyperlinks.push({
|
|
132
|
-
link,
|
|
133
|
-
hyperlink,
|
|
130
|
+
link: this.removeTrailingPunctuation(link),
|
|
131
|
+
hyperlink: this.removeTrailingPunctuation(hyperlink),
|
|
134
132
|
mark: match[0],
|
|
135
133
|
id: uniqueKeyMark,
|
|
136
134
|
});
|
|
@@ -246,9 +244,13 @@ export class PubnubMessage extends LitElement {
|
|
|
246
244
|
|
|
247
245
|
<div class="website-preview-body">
|
|
248
246
|
<p class="message-text website-preview-title">${preview.title}</p>
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
247
|
+
${
|
|
248
|
+
preview.description
|
|
249
|
+
? html`<p class="message-text website-preview-description">
|
|
250
|
+
${preview.description}
|
|
251
|
+
</p>`
|
|
252
|
+
: ""
|
|
253
|
+
}
|
|
252
254
|
</div>
|
|
253
255
|
</div>
|
|
254
256
|
</a></div> `;
|