@meetelise/chat 1.20.70 → 1.20.71
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 +1 -1
- package/public/dist/index.js +2 -2
- package/src/MEChat.ts +199 -0
- package/src/WebComponent/me-chat.ts +0 -151
- package/src/fetchFeatureFlag.ts +22 -0
package/package.json
CHANGED
package/public/dist/index.js
CHANGED
|
@@ -2841,7 +2841,7 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
2841
2841
|
cursor: pointer;
|
|
2842
2842
|
filter: brightness(90%);
|
|
2843
2843
|
}
|
|
2844
|
-
`],pr([de({attribute:!0})],fr.prototype,"onClick",void 0),pr([de({attribute:!0})],fr.prototype,"brandColor",void 0),pr([de({attribute:!0})],fr.prototype,"toExpand",void 0),fr=pr([ue("minimize-expand-button")],fr);var hr,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 vr=hr=class extends ae{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.themeId="Glass",this.useMiniWidget=!0,this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.popup=null,this.theme=ui({themeId:this.themeId,brandColor:this.brandColor}),this.chatId="",this.analytics=null,this.isMobile=r(),this.launcher=null,this.building=null,this.buildingABTestType=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=Mn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.talkjsPopupElement=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{await this.setBuildingDerivedInfo(),await this.initializeLaunchJS(),this.attachOnClickToLauncher(),this.isLoading=!1
|
|
2844
|
+
`],pr([de({attribute:!0})],fr.prototype,"onClick",void 0),pr([de({attribute:!0})],fr.prototype,"brandColor",void 0),pr([de({attribute:!0})],fr.prototype,"toExpand",void 0),fr=pr([ue("minimize-expand-button")],fr);var hr,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 vr=hr=class extends ae{constructor(){super(...arguments),this.buildingSlug="",this.orgSlug="",this.themeId="Glass",this.useMiniWidget=!0,this.launcherStyles={},this.isMinimized=!1,this.brandColor=null,this.popup=null,this.theme=ui({themeId:this.themeId,brandColor:this.brandColor}),this.chatId="",this.analytics=null,this.isMobile=r(),this.launcher=null,this.building=null,this.buildingABTestType=null,this.leadSources=null,this.currentLeadSource=null,this.featureFlagShowDropdown=Mn.always,this.phoneNumberForSource=null,this.hasMounted=!1,this.hideLauncher=!1,this.isLoading=!0,this.talkjsPopupElement=null,this.yardiDNIScriptInterval=null,this.launcherRef=Oe(),this.initializeInstanceVariables=async()=>{await this.setBuildingDerivedInfo(),await this.initializeLaunchJS(),this.attachOnClickToLauncher(),this.isLoading=!1},this.setBuildingDerivedInfo=async()=>{var e,n,i,r;if(!this.buildingSlug||!this.orgSlug)return;const[o,a,s,u,l,d,c]=await Promise.all([di(this.orgSlug,this.buildingSlug),fi(this.buildingSlug),cr(this.buildingSlug),hi(this.buildingSlug,document.referrer),Pn(this.buildingSlug),Dn(this.buildingSlug),ci(this.buildingSlug)]);o.phoneNumber=Fe(o.phoneNumber),this.building=o,this.buildingABTestType=null!==(e=null==a?void 0:a.abTestType)&&void 0!==e?e:"",this.leadSources=s,this.currentLeadSource=u,this.featureFlagShowDropdown=l,c&&(null===this.brandColor&&(this.brandColor=null!==(n=c.primaryColor)&&void 0!==n?n:null),null===this.buildingABTestType&&(this.buildingABTestType=null!==(i=c.designConcept)&&void 0!==i?i:null)),null===this.brandColor&&(this.brandColor=ri);let p=null;d&&(p=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:Fe(i.data.number),isMatch:i.data.isMatch,isPropertyWebsiteCatchall:i.data.isPropertyWebsiteCatchall}:null}catch(e){return null}}(this.buildingSlug,this.currentLeadSource)),this.phoneNumberForSource=p||{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.chatId=function(e,t){const n=ei(e,t),i=localStorage.getItem(n);return i&&!function(e,t){const n=ti(e,t),i=localStorage.getItem(n)||$n(e,t),r=new Date(new Date(i).getTime()+216e5);return new Date>r}(e,t)?i:Zn(e,t)}(this.orgSlug,this.buildingSlug),this.avatarSrc=this.avatarSrc||this.building.avatarSrc,this.theme=ui({themeId:null!==(r=this.themeId)&&void 0!==r?r:this.building.themeId,brandColor:this.brandColor}),this.analytics=new jn(this.orgSlug,this.buildingSlug,this.chatId),this.analytics.ping("webchat_heartbeat")},this.initializeLaunchJS=async()=>{var e;if(!this.building||!this.theme)return;if(this.popup&&this.launcher)return;const[t,n,i,r]=await Promise.all([this.building,this.theme,this.avatarSrc,hr.session]);if(t.conversationMaintenanceMode)return new Promise((()=>{console.warn("MeetElise Chat is in maintenance mode. Chat icon will not appear.")}));await this.configureTalkJSPopup(t,n,r,i),this.configureLauncherElement(),null===(e=this.analytics)||void 0===e||e.ping("load"),this.yardiDNIScriptInterval=setInterval((()=>this.pollForYardiCampaignSource()),1e3),setTimeout(clearInterval,15e3,this.yardiDNIScriptInterval)},this.configureLauncherElement=()=>{this.popup&&this.launcherRef.value&&(this.launcher=this.launcherRef.value)},this.configureTalkJSPopup=async(e,t,n,i)=>{var o;const a=n.createPopup(li(n,e,t,i||e.avatarSrc,this.chatId,this.isMobile),{launcher:"never",showCloseInHeader:!0,messageField:{placeholder:"Ask a question..."}});await a.mount({show:!1}),a.on("close",(()=>{this.hideLauncher=!1}));const s=document.querySelector(".__talkjs_popup");if(this.talkjsPopupElement=s,!s)throw new Error("Failed to find chat window");s.classList.add("meetelise-chat","pane"),this.isMobile||s.classList.add("launcher__desktop"),s.style.zIndex="99999999999",this.popup=a;const u=sessionStorage.getItem("autoOpenedTimestamp"),l=!u||u&&an(un(u));e.autoOpenChatWidget&&l&&!r()&&(this.popup.show(),this.hideLauncher=!0,this.hasMounted=!0,sessionStorage.setItem("autoOpenedTimestamp",tn(function(e,t){Ue(2,arguments);var n=et(t);return tt(e,6e4*n)}(new Date,15))),null===(o=this.analytics)||void 0===o||o.ping("autoOpen"))},this.firstUpdated=()=>{this.initializeInstanceVariables()},this.handleContactClicked=e=>{var t,n;null===(t=this.popup)||void 0===t||t.hide(),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickEmailOption(e)},this.handleTourClicked=e=>{var t,n;null===(t=this.popup)||void 0===t||t.hide(),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickSSTOption(e)},this.handleContactTabClicked=e=>{var t,n;null===(t=this.popup)||void 0===t||t.hide(),this.hideLauncher=!1,null===(n=this.launcherRef.value)||void 0===n||n.onClickPhoneOption(e)},this.adjustTopHeaderContactCoords=()=>{var e;if(this.talkjsPopupElement){const t=this.talkjsPopupElement.getBoundingClientRect(),n=null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("chatAdditionalActions");if(!n)return;n.style.left=`${t.left+20}px`,n.style.top=t.bottom-24+"px"}},this.onClickMinimize=e=>{e.preventDefault(),e.stopPropagation(),this.isMinimized=!this.isMinimized},this.attachOnClickToLauncher=()=>{const e=this.launcherRef.value;e&&(e.onChatTapped=async()=>{var e;this.popup&&(this.popup.show(),null===(e=this.analytics)||void 0===e||e.ping("open"),this.hideLauncher=!0,this.hasMounted=!0)})}}pollForYardiCampaignSource(){var e,t,n;(null===(t=null===(e=window.RCTPCampaign)||void 0===e?void 0:e.CampaignDetails)||void 0===t?void 0:t.Source)&&(null===(n=this.analytics)||void 0===n||n.ping("yardi-DNI-init"),this.yardiDNIScriptInterval&&clearInterval(this.yardiDNIScriptInterval))}async restartConversation(){if(!(this.analytics&&this.analytics.chatId&&this.building&&this.popup&&hr.session))return;this.chatId=Zn(this.orgSlug,this.buildingSlug);const e=await hr.session;this.analytics.chatId=this.chatId,this.popup.select(li(e,this.building,this.theme,this.avatarSrc||this.building.avatarSrc,this.chatId,this.isMobile))}remove(){var e;null===(e=this.popup)||void 0===e||e.destroy()}open(){var e;null===(e=this.popup)||void 0===e||e.show()}close(){var e;null===(e=this.popup)||void 0===e||e.hide()}show(){this.launcher&&(this.launcher.style.display="")}hide(){this.launcher&&(this.launcher.style.display="none")}connectedCallback(){super.connectedCallback(),window.addEventListener("resize",this.adjustTopHeaderContactCoords)}disconnectedCallback(){window.removeEventListener("resize",this.adjustTopHeaderContactCoords),super.disconnectedCallback()}updated(){this.adjustTopHeaderContactCoords()}render(){var e,t,n,i,r,o,a,s,u,l,d,c,p,f,h,m,v,g,y,b,w,S,T,A,x,O,C,I,N,R,E,F,_,M,P,D,q,U,B,k,L,j;window.customElements.get("meetelise-launcher")||window.customElements.define("meetelise-launcher",Yi);const H=this.hideLauncher&&!this.isLoading&&!this.isMobile;return J`
|
|
2845
2845
|
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=1">
|
|
2846
2846
|
<div id="aria-describe-info" style="display: none;">
|
|
2847
2847
|
EliseAI widget that allows you to chat with a virtual assistant, book
|
|
@@ -2956,4 +2956,4 @@ var e={8005:function(e,t,n){var i,r=this&&this.__extends||(i=function(e,t){retur
|
|
|
2956
2956
|
border-bottom: 22px solid transparent;
|
|
2957
2957
|
border-right: 30px solid black;
|
|
2958
2958
|
}
|
|
2959
|
-
`,vr.session=Re.ready.then((()=>{const e=new Re.User({id:"anonymous",name:"Me",email:null,role:"Default"});return new Re.Session({appId:"ogKIvCor",me:e})})),mr([de({type:String})],vr.prototype,"buildingSlug",void 0),mr([de({type:String})],vr.prototype,"orgSlug",void 0),mr([de({type:String})],vr.prototype,"themeId",void 0),mr([de({attribute:!1})],vr.prototype,"avatarSrc",void 0),mr([de({type:Boolean})],vr.prototype,"useMiniWidget",void 0),mr([de({type:Object})],vr.prototype,"launcherStyles",void 0),mr([de({type:Boolean})],vr.prototype,"isMinimized",void 0),mr([de({type:String})],vr.prototype,"brandColor",void 0),mr([ce()],vr.prototype,"popup",void 0),mr([ce()],vr.prototype,"theme",void 0),mr([ce()],vr.prototype,"chatId",void 0),mr([ce()],vr.prototype,"analytics",void 0),mr([ce()],vr.prototype,"isMobile",void 0),mr([ce()],vr.prototype,"launcher",void 0),mr([ce()],vr.prototype,"building",void 0),mr([ce()],vr.prototype,"buildingABTestType",void 0),mr([ce()],vr.prototype,"leadSources",void 0),mr([ce()],vr.prototype,"currentLeadSource",void 0),mr([ce()],vr.prototype,"featureFlagShowDropdown",void 0),mr([ce()],vr.prototype,"phoneNumberForSource",void 0),mr([ce()],vr.prototype,"hasMounted",void 0),mr([ce()],vr.prototype,"hideLauncher",void 0),mr([ce()],vr.prototype,"isLoading",void 0),mr([ce()],vr.prototype,"talkjsPopupElement",void 0),vr=hr=mr([ue("me-chat")],vr);class gr{static start(e,t=!0){if(window.location.pathname.includes("residentservices")||window.location.pathname.includes("onlineleasing"))return;t&&(this.orgSlug=e.organization,this.hasBuildingSlug=!!e.building),yr(),br();const n=document.createElement("me-chat");n.setAttribute("orgSlug",e.organization),this.handleBuildingslug(n,e.building),n.setAttribute("class","meetelise-chat"),n.setAttribute("role","dialog"),n.setAttribute("aria-label","EliseAI Widget"),n.setAttribute("aria-describedby","aria-describe-info"),n.setAttribute("aria-modal","true"),e.themeId&&n.setAttribute("themeId",e.themeId),e.avatarSrc&&n.setAttribute("avatarSrc",e.avatarSrc),void 0!==e.mini&&(n.useMiniWidget=e.mini),e.launcherStyles&&(n.launcherStyles=e.launcherStyles),e.brandColor&&(this.brandColor=e.brandColor,n.setAttribute("brandColor",((e,t)=>{const n=(r=e,{r:parseInt(r.substring(1,3),16),g:parseInt(r.substring(3,5),16),b:parseInt(r.substring(5,7),16)}),i={r:n.r+Math.round(.3*(0-n.r)),g:n.g+Math.round(.3*(0-n.g)),b:n.b+Math.round(.3*(0-n.b))};var r;return((e,t,n)=>"#"+[e,t,n].map((e=>{const t=e.toString(16);return 1===t.length?"0"+t:t})).join(""))(i.r,i.g,i.b)})(e.brandColor))),document.body.appendChild(n),gr.meChat=n}static async restartConversation(){this.meChat&&await this.meChat.restartConversation()}static async remove(){this.meChat&&(await this.meChat.remove(),document.body.removeChild(this.meChat),gr.meChat=null)}static async handleBuildingslug(e,t){t?e.setAttribute("buildingSlug",t):this.mutationObserver||(this.handleSingleFamilyUrl(),this.previousUrl=window.location.href,document.body.addEventListener("click",(()=>{requestAnimationFrame((()=>{this.previousUrl===window.location.href||this.hasBuildingSlug||(this.previousUrl=window.location.href,this.handleSingleFamilyUrl())}))}),!0))}static async handleSingleFamilyUrl(){if(this.hasBuildingSlug)return;this.remove();const e=window.location.href,n=`https://app.meetelise.com/platformApi/webchat/microsite_slug?uri=${encodeURIComponent(e)}`,i=await t().get(n,{headers:{"org-slug":this.orgSlug}});if(!i||!i.data)return;const r={organization:this.orgSlug,building:i.data,brandColor:this.brandColor};this.start(r,!1)}}gr.meChat=null,gr.orgSlug="",gr.mutationObserver=null,gr.previousUrl="",gr.hasBuildingSlug=null,gr.brandColor="";const yr=()=>{const e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),document.head.appendChild(e)},br=()=>{const e=document.createElement("meta");e.setAttribute("name","viewport"),e.setAttribute("content","width=device-width, initial-scale=1, maximum-scale=2"),document.head.appendChild(e)}})();var r=i.Z;export{r as default};
|
|
2959
|
+
`,vr.session=Re.ready.then((()=>{const e=new Re.User({id:"anonymous",name:"Me",email:null,role:"Default"});return new Re.Session({appId:"ogKIvCor",me:e})})),mr([de({type:String})],vr.prototype,"buildingSlug",void 0),mr([de({type:String})],vr.prototype,"orgSlug",void 0),mr([de({type:String})],vr.prototype,"themeId",void 0),mr([de({attribute:!1})],vr.prototype,"avatarSrc",void 0),mr([de({type:Boolean})],vr.prototype,"useMiniWidget",void 0),mr([de({type:Object})],vr.prototype,"launcherStyles",void 0),mr([de({type:Boolean})],vr.prototype,"isMinimized",void 0),mr([de({type:String})],vr.prototype,"brandColor",void 0),mr([ce()],vr.prototype,"popup",void 0),mr([ce()],vr.prototype,"theme",void 0),mr([ce()],vr.prototype,"chatId",void 0),mr([ce()],vr.prototype,"analytics",void 0),mr([ce()],vr.prototype,"isMobile",void 0),mr([ce()],vr.prototype,"launcher",void 0),mr([ce()],vr.prototype,"building",void 0),mr([ce()],vr.prototype,"buildingABTestType",void 0),mr([ce()],vr.prototype,"leadSources",void 0),mr([ce()],vr.prototype,"currentLeadSource",void 0),mr([ce()],vr.prototype,"featureFlagShowDropdown",void 0),mr([ce()],vr.prototype,"phoneNumberForSource",void 0),mr([ce()],vr.prototype,"hasMounted",void 0),mr([ce()],vr.prototype,"hideLauncher",void 0),mr([ce()],vr.prototype,"isLoading",void 0),mr([ce()],vr.prototype,"talkjsPopupElement",void 0),vr=hr=mr([ue("me-chat")],vr);class gr{static start(e,t=!0){if(window.location.pathname.includes("residentservices")||window.location.pathname.includes("onlineleasing"))return;t&&(this.orgSlug=e.organization,this.hasBuildingSlug=!!e.building),yr(),br();const n=document.createElement("me-chat");n.setAttribute("orgSlug",e.organization),this.handleBuildingslug(n,e.building),n.setAttribute("class","meetelise-chat"),n.setAttribute("role","dialog"),n.setAttribute("aria-label","EliseAI Widget"),n.setAttribute("aria-describedby","aria-describe-info"),n.setAttribute("aria-modal","true"),e.themeId&&n.setAttribute("themeId",e.themeId),e.avatarSrc&&n.setAttribute("avatarSrc",e.avatarSrc),void 0!==e.mini&&(n.useMiniWidget=e.mini),e.launcherStyles&&(n.launcherStyles=e.launcherStyles),e.brandColor&&(this.brandColor=e.brandColor,n.setAttribute("brandColor",((e,t)=>{const n=(r=e,{r:parseInt(r.substring(1,3),16),g:parseInt(r.substring(3,5),16),b:parseInt(r.substring(5,7),16)}),i={r:n.r+Math.round(.3*(0-n.r)),g:n.g+Math.round(.3*(0-n.g)),b:n.b+Math.round(.3*(0-n.b))};var r;return((e,t,n)=>"#"+[e,t,n].map((e=>{const t=e.toString(16);return 1===t.length?"0"+t:t})).join(""))(i.r,i.g,i.b)})(e.brandColor))),document.body.appendChild(n),gr.meChat=n,e.building&&e.organization&&wr(e.organization,e.building)}static async restartConversation(){this.meChat&&await this.meChat.restartConversation()}static async remove(){this.meChat&&(await this.meChat.remove(),document.body.removeChild(this.meChat),gr.meChat=null)}static async handleBuildingslug(e,t){t?e.setAttribute("buildingSlug",t):this.mutationObserver||(this.handleSingleFamilyUrl(),this.previousUrl=window.location.href,document.body.addEventListener("click",(()=>{requestAnimationFrame((()=>{this.previousUrl===window.location.href||this.hasBuildingSlug||(this.previousUrl=window.location.href,this.handleSingleFamilyUrl())}))}),!0))}static async handleSingleFamilyUrl(){if(this.hasBuildingSlug)return;this.remove();const e=window.location.href,n=`https://app.meetelise.com/platformApi/webchat/microsite_slug?uri=${encodeURIComponent(e)}`,i=await t().get(n,{headers:{"org-slug":this.orgSlug}});if(!i||!i.data)return;const r={organization:this.orgSlug,building:i.data,brandColor:this.brandColor};this.start(r,!1)}}gr.meChat=null,gr.orgSlug="",gr.mutationObserver=null,gr.previousUrl="",gr.hasBuildingSlug=null,gr.brandColor="";const yr=()=>{const e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),document.head.appendChild(e)},br=()=>{const e=document.createElement("meta");e.setAttribute("name","viewport"),e.setAttribute("content","width=device-width, initial-scale=1, maximum-scale=2"),document.head.appendChild(e)},wr=async(e,n)=>{var i;if("true"!==localStorage.getItem("overrideContactUsForm"))return;const r=await async function(e){try{return(await t().get(_n(e),{params:{building_slug:e,flag_type:"bool",feature_flag:"webchat-use-override-contact-us-form",default_str:null,default_bool:!1}})).data}catch(e){return!1}}(n);if(!r)return;const o=document.getElementById("myContactForm");let a;if(!(o&&o instanceof HTMLFormElement))return void(window.location.pathname.toLowerCase().includes("contactus")&&Sr(n,e,"Could not find form"));for(let e=0;e<o.elements.length;e++){const t=o.elements[e];if("button"===t.tagName.toLowerCase()&&"fakebutton"===t.getAttribute("data-selenium-id")){a=t;break}}if(!a)return Sr(n,e,"Could not find submit button");const s=()=>({firstName:document.getElementById("firstname"),lastName:document.getElementById("lastname"),email:document.getElementById("email"),phone:document.getElementById("phonenumber"),message:document.getElementById("message")});if(Object.values(s()).some((e=>null===e))){const t=Object.entries(s()).filter((([,e])=>null===e)).map((([e])=>e));return Sr(n,e,"Missing the following form elements: "+t.join(", "))}const u=a.cloneNode(!0);null===(i=a.parentNode)||void 0===i||i.replaceChild(u,a),u.textContent="Elise Submit",u.onclick=async function(t){if(!Object.values(s()).every((t=>null!==t&&(null===t.getAttribute("aria-invalid")&&Sr(n,e,"Missing aria-invalid attribute on "+t.id),"true"!==t.getAttribute("aria-invalid")))))return;t.preventDefault();const i={};Object.entries(s()).forEach((([e,t])=>i[e]=null==t?void 0:t.value));const r=await di(e,n),a=await hi(n,document.referrer);if(!r)return Sr(n,e,"Could not find building"),null;const l={email_address:i.email,first_name:i.firstName,last_name:i.lastName,phone_number:i.phone,first_message:i.message,building_id:r.id,is_external_form:!0,lead_sources:[...new Set(a?[a,"property-website"]:["property-website"])]},d=JSON.stringify(l);fetch("https://app.meetelise.com/platformApi/state/create/contactMe",{method:"POST",headers:{"Content-Type":"application/json","building-slug":n,"org-slug":e},body:d}).then((e=>{if(!e.ok)throw new Error(`HTTP error ${e.status}`);return o.reset(),Object.values(s()).forEach((e=>{e&&(e.disabled=!0)})),u.textContent="Submitted",u.disabled=!0,e.json()}))}},Sr=(e,t,n)=>{const i=JSON.stringify({orgSlug:t,buildingSlug:e,reason:n});fetch("https://app.meetelise.com/platformApi/webchat/form-override-error",{method:"POST",headers:{"Content-Type":"application/json","building-slug":e,"org-slug":t},body:i})}})();var r=i.Z;export{r as default};
|
package/src/MEChat.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { ThemeIdString } from "./themes";
|
|
|
4
4
|
import { tintColor } from "./utils";
|
|
5
5
|
import "./WebComponent/me-chat";
|
|
6
6
|
import { MEChat as MEChatLitElement } from "./WebComponent/me-chat";
|
|
7
|
+
import fetchBuildingInfo from "./fetchBuildingInfo";
|
|
8
|
+
import { fetchFeatureFlagUseOverrideContactUsForm } from "./fetchFeatureFlag";
|
|
9
|
+
import fetchCurrentParsedLeadSource from "./fetchCurrentParsedLeadSource";
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* The interface to MeetElise chat.
|
|
@@ -68,6 +71,10 @@ export default class MEChat {
|
|
|
68
71
|
}
|
|
69
72
|
document.body.appendChild(meChat);
|
|
70
73
|
MEChat.meChat = meChat;
|
|
74
|
+
|
|
75
|
+
if (opts.building && opts.organization) {
|
|
76
|
+
overrideContactUsForm(opts.organization, opts.building);
|
|
77
|
+
}
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
static async restartConversation(): Promise<void> {
|
|
@@ -171,3 +178,195 @@ const installTalkjsMobileStyleFix = () => {
|
|
|
171
178
|
);
|
|
172
179
|
document.head.appendChild(metaTag);
|
|
173
180
|
};
|
|
181
|
+
|
|
182
|
+
const overrideContactUsForm = async (
|
|
183
|
+
orgSlug: string,
|
|
184
|
+
buildingSlug: string
|
|
185
|
+
): Promise<void> => {
|
|
186
|
+
// TODO: Remove after testing in production
|
|
187
|
+
if (localStorage.getItem("overrideContactUsForm") !== "true") return;
|
|
188
|
+
const shouldUseOverrideContactUsForm =
|
|
189
|
+
await fetchFeatureFlagUseOverrideContactUsForm(buildingSlug);
|
|
190
|
+
if (!shouldUseOverrideContactUsForm) return;
|
|
191
|
+
|
|
192
|
+
const form = document.getElementById(
|
|
193
|
+
"myContactForm"
|
|
194
|
+
) as HTMLFormElement | null;
|
|
195
|
+
let btn = undefined;
|
|
196
|
+
|
|
197
|
+
if (!form || !(form instanceof HTMLFormElement)) {
|
|
198
|
+
if (window.location.pathname.toLowerCase().includes("contactus")) {
|
|
199
|
+
logContactUsFormError(buildingSlug, orgSlug, "Could not find form");
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Loop through the elements of the form
|
|
205
|
+
for (let i = 0; i < form.elements.length; i++) {
|
|
206
|
+
const element = form.elements[i];
|
|
207
|
+
if (
|
|
208
|
+
element.tagName.toLowerCase() === "button" &&
|
|
209
|
+
element.getAttribute("data-selenium-id") === "fakebutton"
|
|
210
|
+
) {
|
|
211
|
+
btn = element;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!btn) {
|
|
217
|
+
return logContactUsFormError(
|
|
218
|
+
buildingSlug,
|
|
219
|
+
orgSlug,
|
|
220
|
+
"Could not find submit button"
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const eliseUrl =
|
|
225
|
+
"https://app.meetelise.com/platformApi/state/create/contactMe";
|
|
226
|
+
|
|
227
|
+
const getFormElements = () => {
|
|
228
|
+
const firstName = document.getElementById(
|
|
229
|
+
"firstname"
|
|
230
|
+
) as HTMLInputElement | null;
|
|
231
|
+
const lastName = document.getElementById(
|
|
232
|
+
"lastname"
|
|
233
|
+
) as HTMLInputElement | null;
|
|
234
|
+
const email = document.getElementById("email") as HTMLInputElement | null;
|
|
235
|
+
const phone = document.getElementById(
|
|
236
|
+
"phonenumber"
|
|
237
|
+
) as HTMLInputElement | null;
|
|
238
|
+
const message = document.getElementById(
|
|
239
|
+
"message"
|
|
240
|
+
) as HTMLTextAreaElement | null;
|
|
241
|
+
|
|
242
|
+
const formElements = { firstName, lastName, email, phone, message };
|
|
243
|
+
|
|
244
|
+
return formElements;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const isMissingFormElements = () => {
|
|
248
|
+
if (Object.values(getFormElements()).some((el) => el === null)) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const isValid = () => {
|
|
255
|
+
return Object.values(getFormElements()).every((el) => {
|
|
256
|
+
if (el === null) return false;
|
|
257
|
+
if (el.getAttribute("aria-invalid") === null) {
|
|
258
|
+
logContactUsFormError(
|
|
259
|
+
buildingSlug,
|
|
260
|
+
orgSlug,
|
|
261
|
+
"Missing aria-invalid attribute on " + el.id
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return el.getAttribute("aria-invalid") !== "true";
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
if (isMissingFormElements()) {
|
|
269
|
+
const missingElements = Object.entries(getFormElements())
|
|
270
|
+
.filter(([, val]) => val === null)
|
|
271
|
+
.map(([key]) => key);
|
|
272
|
+
return logContactUsFormError(
|
|
273
|
+
buildingSlug,
|
|
274
|
+
orgSlug,
|
|
275
|
+
"Missing the following form elements: " + missingElements.join(", ")
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Replace the original form element with the cloned one
|
|
280
|
+
const clonedButton = btn.cloneNode(true) as HTMLButtonElement;
|
|
281
|
+
btn.parentNode?.replaceChild(clonedButton, btn);
|
|
282
|
+
|
|
283
|
+
// TODO: Remove after testing in production
|
|
284
|
+
clonedButton.textContent = "Elise Submit";
|
|
285
|
+
|
|
286
|
+
clonedButton.onclick = async function (event) {
|
|
287
|
+
if (!isValid()) return;
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
|
|
290
|
+
const formValues: { [key: string]: string | undefined } = {};
|
|
291
|
+
Object.entries(getFormElements()).forEach(
|
|
292
|
+
([key, val]) => (formValues[key] = val?.value)
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const building = await fetchBuildingInfo(orgSlug, buildingSlug);
|
|
296
|
+
const currentLeadSource = await fetchCurrentParsedLeadSource(
|
|
297
|
+
buildingSlug,
|
|
298
|
+
document.referrer
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
if (!building) {
|
|
302
|
+
logContactUsFormError(buildingSlug, orgSlug, "Could not find building");
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const data = {
|
|
307
|
+
email_address: formValues.email,
|
|
308
|
+
first_name: formValues.firstName,
|
|
309
|
+
last_name: formValues.lastName,
|
|
310
|
+
phone_number: formValues.phone,
|
|
311
|
+
first_message: formValues.message,
|
|
312
|
+
building_id: building.id,
|
|
313
|
+
is_external_form: true,
|
|
314
|
+
lead_sources: [
|
|
315
|
+
...new Set(
|
|
316
|
+
currentLeadSource
|
|
317
|
+
? [currentLeadSource, "property-website"]
|
|
318
|
+
: ["property-website"]
|
|
319
|
+
),
|
|
320
|
+
],
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const jsonData = JSON.stringify(data);
|
|
324
|
+
|
|
325
|
+
fetch(eliseUrl, {
|
|
326
|
+
method: "POST",
|
|
327
|
+
headers: {
|
|
328
|
+
"Content-Type": "application/json",
|
|
329
|
+
"building-slug": buildingSlug,
|
|
330
|
+
"org-slug": orgSlug,
|
|
331
|
+
},
|
|
332
|
+
body: jsonData,
|
|
333
|
+
}).then((response) => {
|
|
334
|
+
if (!response.ok) {
|
|
335
|
+
throw new Error(`HTTP error ${response.status}`);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
form.reset();
|
|
339
|
+
Object.values(getFormElements()).forEach((el) => {
|
|
340
|
+
if (!el) return;
|
|
341
|
+
el.disabled = true;
|
|
342
|
+
});
|
|
343
|
+
clonedButton.textContent = "Submitted";
|
|
344
|
+
clonedButton.disabled = true;
|
|
345
|
+
|
|
346
|
+
return response.json();
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
const logContactUsFormError = (
|
|
352
|
+
buildingSlug: string,
|
|
353
|
+
orgSlug: string,
|
|
354
|
+
reason?: string
|
|
355
|
+
) => {
|
|
356
|
+
const url = `https://app.meetelise.com/platformApi/webchat/form-override-error`;
|
|
357
|
+
const body = JSON.stringify({
|
|
358
|
+
orgSlug,
|
|
359
|
+
buildingSlug,
|
|
360
|
+
reason,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
fetch(url, {
|
|
364
|
+
method: "POST",
|
|
365
|
+
headers: {
|
|
366
|
+
"Content-Type": "application/json",
|
|
367
|
+
"building-slug": buildingSlug,
|
|
368
|
+
"org-slug": orgSlug,
|
|
369
|
+
},
|
|
370
|
+
body,
|
|
371
|
+
});
|
|
372
|
+
};
|
|
@@ -161,16 +161,6 @@ export class MEChat extends LitElement {
|
|
|
161
161
|
await this.initializeLaunchJS();
|
|
162
162
|
this.attachOnClickToLauncher();
|
|
163
163
|
this.isLoading = false;
|
|
164
|
-
if (localStorage.getItem("overrideContactUsForm") === "true") {
|
|
165
|
-
this
|
|
166
|
-
.overrideContactUsForm
|
|
167
|
-
// {
|
|
168
|
-
// orgSlug: this.orgSlug,
|
|
169
|
-
// buildingSlug: this.buildingSlug,
|
|
170
|
-
// buildingId: this.building?.id ?? null,
|
|
171
|
-
// }
|
|
172
|
-
();
|
|
173
|
-
}
|
|
174
164
|
};
|
|
175
165
|
|
|
176
166
|
setBuildingDerivedInfo = async (): Promise<void> => {
|
|
@@ -621,147 +611,6 @@ export class MEChat extends LitElement {
|
|
|
621
611
|
this.hasMounted = true;
|
|
622
612
|
};
|
|
623
613
|
};
|
|
624
|
-
|
|
625
|
-
private overrideContactUsForm = (): // {
|
|
626
|
-
// orgSlug,
|
|
627
|
-
// buildingSlug,
|
|
628
|
-
// buildingId,
|
|
629
|
-
// }: {
|
|
630
|
-
// orgSlug: MEChat["orgSlug"];
|
|
631
|
-
// buildingSlug: MEChat["buildingSlug"];
|
|
632
|
-
// buildingId: Building["id"] | null;
|
|
633
|
-
// }
|
|
634
|
-
void => {
|
|
635
|
-
const form = document.getElementById(
|
|
636
|
-
"myContactForm"
|
|
637
|
-
) as HTMLFormElement | null;
|
|
638
|
-
let btn = undefined;
|
|
639
|
-
if (!form || !(form instanceof HTMLFormElement)) {
|
|
640
|
-
// TODO: Add log
|
|
641
|
-
// return console.log("No Contact Us Form Found");
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// Loop through the elements of the form
|
|
646
|
-
for (let i = 0; i < form.elements.length; i++) {
|
|
647
|
-
const element = form.elements[i];
|
|
648
|
-
if (
|
|
649
|
-
element.tagName.toLowerCase() === "button" &&
|
|
650
|
-
element.getAttribute("data-selenium-id") === "fakebutton"
|
|
651
|
-
) {
|
|
652
|
-
btn = element;
|
|
653
|
-
break;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
if (!btn) {
|
|
658
|
-
// TODO: Add log
|
|
659
|
-
// return console.log('No button with data-selenium-id="fakebutton" found');
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// Replace the original form element with the cloned one
|
|
664
|
-
const clonedButton = btn.cloneNode(true) as HTMLButtonElement;
|
|
665
|
-
btn.parentNode?.replaceChild(clonedButton, btn);
|
|
666
|
-
//TODO: Remove textContent after testing
|
|
667
|
-
clonedButton.textContent = "Elise Submit";
|
|
668
|
-
|
|
669
|
-
const eliseUrl =
|
|
670
|
-
"https://app.meetelise.com/platformApi/state/create/contactMe";
|
|
671
|
-
|
|
672
|
-
const getFormElements = () => {
|
|
673
|
-
const firstName = document.getElementById(
|
|
674
|
-
"firstname"
|
|
675
|
-
) as HTMLInputElement | null;
|
|
676
|
-
const lastName = document.getElementById(
|
|
677
|
-
"lastname"
|
|
678
|
-
) as HTMLInputElement | null;
|
|
679
|
-
const email = document.getElementById("email") as HTMLInputElement | null;
|
|
680
|
-
const phone = document.getElementById(
|
|
681
|
-
"phonenumber"
|
|
682
|
-
) as HTMLInputElement | null;
|
|
683
|
-
const message = document.getElementById(
|
|
684
|
-
"message"
|
|
685
|
-
) as HTMLTextAreaElement | null;
|
|
686
|
-
|
|
687
|
-
const formElements = { firstName, lastName, email, phone, message };
|
|
688
|
-
|
|
689
|
-
if (Object.values(formElements).some((el) => el === null)) {
|
|
690
|
-
// console.log("Form is missing elements");
|
|
691
|
-
// TODO: Add logger to log that form scraper is boken on el.name in current route or buildingId
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
return formElements;
|
|
695
|
-
};
|
|
696
|
-
const getFormValues = () => {
|
|
697
|
-
const formValues: { [key: string]: string | undefined } = {};
|
|
698
|
-
Object.entries(getFormElements()).forEach(
|
|
699
|
-
([key, val]) => (formValues[key] = val?.value)
|
|
700
|
-
);
|
|
701
|
-
return formValues;
|
|
702
|
-
};
|
|
703
|
-
|
|
704
|
-
const isValid = () => {
|
|
705
|
-
return Object.values(getFormElements()).every((el) => {
|
|
706
|
-
if (el === null) return false;
|
|
707
|
-
//TODO: May need to not depend on aria-invalid
|
|
708
|
-
return el.getAttribute("aria-invalid") !== "true";
|
|
709
|
-
});
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
clonedButton.onclick = function (event) {
|
|
713
|
-
if (!isValid()) return;
|
|
714
|
-
event.preventDefault();
|
|
715
|
-
const formValues = getFormValues();
|
|
716
|
-
|
|
717
|
-
const data = {
|
|
718
|
-
email_address: formValues.email,
|
|
719
|
-
first_name: formValues.firstName,
|
|
720
|
-
last_name: formValues.lastName,
|
|
721
|
-
phone_number: formValues.phone,
|
|
722
|
-
first_message: formValues.message,
|
|
723
|
-
|
|
724
|
-
//TODO: Replace after testing is done
|
|
725
|
-
building_id: 3660,
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
// Convert the data object to a JSON string
|
|
729
|
-
const jsonData = JSON.stringify(data);
|
|
730
|
-
|
|
731
|
-
fetch(eliseUrl, {
|
|
732
|
-
method: "POST",
|
|
733
|
-
headers: {
|
|
734
|
-
"Content-Type": "application/json",
|
|
735
|
-
"building-slug": "e2e-test-yardi-building",
|
|
736
|
-
"org-slug": "test-company",
|
|
737
|
-
//TODO: Replace org and building slugs
|
|
738
|
-
},
|
|
739
|
-
body: jsonData,
|
|
740
|
-
}).then((response) => {
|
|
741
|
-
// TODO: What's needed here?
|
|
742
|
-
// console.log(response);
|
|
743
|
-
// Check if the request was successful
|
|
744
|
-
if (!response.ok) {
|
|
745
|
-
throw new Error(`HTTP error ${response.status}`);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
form.reset();
|
|
749
|
-
|
|
750
|
-
// Parse the response as JSON
|
|
751
|
-
return response.json();
|
|
752
|
-
});
|
|
753
|
-
// .then((responseData) => {
|
|
754
|
-
// // Handle the JSON response data
|
|
755
|
-
// // TODO: What's needed here?
|
|
756
|
-
// // console.log("Response data:", responseData);
|
|
757
|
-
// })
|
|
758
|
-
// .catch((error) => {
|
|
759
|
-
// // Handle any errors that occurred during the request
|
|
760
|
-
// // TODO: What's needed here?
|
|
761
|
-
// // console.error("Error:", error);
|
|
762
|
-
// });
|
|
763
|
-
};
|
|
764
|
-
};
|
|
765
614
|
}
|
|
766
615
|
|
|
767
616
|
declare global {
|
package/src/fetchFeatureFlag.ts
CHANGED
|
@@ -60,3 +60,25 @@ export async function fetchFeatureFlagUsePhoneNumberBySource(
|
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
export async function fetchFeatureFlagUseOverrideContactUsForm(
|
|
65
|
+
buildingSlug: string
|
|
66
|
+
): Promise<boolean> {
|
|
67
|
+
try {
|
|
68
|
+
const featureFlagResponse = await axios.get(
|
|
69
|
+
featureFlagEndpoint(buildingSlug),
|
|
70
|
+
{
|
|
71
|
+
params: {
|
|
72
|
+
building_slug: buildingSlug,
|
|
73
|
+
flag_type: "bool",
|
|
74
|
+
feature_flag: "webchat-use-override-contact-us-form",
|
|
75
|
+
default_str: null,
|
|
76
|
+
default_bool: false,
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
return featureFlagResponse.data;
|
|
81
|
+
} catch (_) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|