@meetelise/chat 1.20.112 → 1.20.113

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetelise/chat",
3
- "version": "1.20.112",
3
+ "version": "1.20.113",
4
4
  "description": "",
5
5
  "main": "public/dist/index.js",
6
6
  "type": "module",
@@ -3565,4 +3565,4 @@ otherwise there's some empty space at the bottom of the button, which interferes
3565
3565
  position: fixed;
3566
3566
  bottom: 0;
3567
3567
  }
3568
- `,to.session=null,eo([be({type:String})],to.prototype,"buildingSlug",void 0),eo([be({type:String})],to.prototype,"orgSlug",void 0),eo([be({type:String})],to.prototype,"themeId",void 0),eo([be({attribute:!1})],to.prototype,"avatarSrc",void 0),eo([be({type:Boolean})],to.prototype,"useMiniWidget",void 0),eo([be({type:Object})],to.prototype,"launcherStyles",void 0),eo([be({type:Boolean})],to.prototype,"isMinimized",void 0),eo([be({type:String})],to.prototype,"brandColor",void 0),eo([we()],to.prototype,"popup",void 0),eo([we()],to.prototype,"theme",void 0),eo([we()],to.prototype,"chatId",void 0),eo([we()],to.prototype,"analytics",void 0),eo([we()],to.prototype,"isMobile",void 0),eo([we()],to.prototype,"launcher",void 0),eo([we()],to.prototype,"building",void 0),eo([we()],to.prototype,"designConcept",void 0),eo([we()],to.prototype,"leadSources",void 0),eo([we()],to.prototype,"currentLeadSource",void 0),eo([we()],to.prototype,"featureFlagShowDropdown",void 0),eo([we()],to.prototype,"phoneNumberForSource",void 0),eo([we()],to.prototype,"hasMounted",void 0),eo([we()],to.prototype,"hideLauncher",void 0),eo([we()],to.prototype,"isLoading",void 0),eo([we()],to.prototype,"talkjsPopupElement",void 0),eo([we()],to.prototype,"chatProvider",void 0),eo([we()],to.prototype,"showTourNextToChat",void 0),eo([we()],to.prototype,"displayPubnubChat",void 0),eo([we()],to.prototype,"myPubnub",void 0),eo([we()],to.prototype,"enabledChatWidgets",void 0),eo([we()],to.prototype,"webchatConfigHasAutoOpenChat",void 0),eo([we()],to.prototype,"requiresConsent",void 0),to=Zr=eo([ve("me-chat")],to);class no{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),io(),ro();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),no.meChat=n,e.building&&e.organization&&oo(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),no.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)}}no.meChat=null,no.orgSlug="",no.mutationObserver=null,no.previousUrl="",no.hasBuildingSlug=null,no.brandColor="";const io=()=>{const e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),document.head.appendChild(e)},ro=()=>{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)},oo=async(e,n)=>{var i;if(!n||!e)return;const r=await async function(e){if(!e)return!1;try{return(await t().get(ei(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;let o,a=document.getElementById("myContactForm");if(a||(a=document.getElementById("contactus")),!(a&&a instanceof HTMLFormElement))return void(window.location.pathname.toLowerCase().includes("contactus")&&ao(n,e,"Could not find form"));for(let e=0;e<a.elements.length;e++){const t=a.elements[e];if("button"===t.tagName.toLowerCase()&&"fakebutton"===t.getAttribute("data-selenium-id")){o=t;break}}if(!o)return ao(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 ao(n,e,"Missing the following form elements: "+t.join(", "))}const u=o.textContent,l=o.cloneNode(!0);null===(i=o.parentNode)||void 0===i||i.replaceChild(l,o),l.onclick=async function(t){if(Object.values(s()).forEach((e=>{"true"!==(null==e?void 0:e.getAttribute("aria-required"))||e.value||(e.className="form-control required is-invalid")})),!Object.values(s()).every((e=>null!==e&&!("true"===e.getAttribute("aria-required")&&!e.value)&&("email"!==e.id&&"phonenumber"!==e.id||"true"!==e.getAttribute("aria-invalid")))))return;t.preventDefault(),l.textContent="Processing request...",l.disabled=!0;const i={};Object.entries(s()).forEach((([e,t])=>i[e]=null==t?void 0:t.value));const r=await Mi(e,n),o=await Bi(n,document.referrer);if(!r)return ao(n,e,"Could not find building"),null;const d={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(o?[o,"property-website"]:["property-website"])]},c=JSON.stringify(d);fetch("https://app.meetelise.com/platformApi/state/create/contactMe",{method:"POST",headers:{"Content-Type":"application/json","building-slug":n,"org-slug":e},body:c}).then((e=>{if(!e.ok)throw new Error(`HTTP error ${e.status}`);return a&&a.reset(),Object.values(s()).forEach((e=>{e&&(e.disabled=!0)})),l.textContent="Submitted",l.disabled=!0,e.json()})).catch((()=>{l.textContent=u}))}},ao=(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};
3568
+ `,to.session=null,eo([be({type:String})],to.prototype,"buildingSlug",void 0),eo([be({type:String})],to.prototype,"orgSlug",void 0),eo([be({type:String})],to.prototype,"themeId",void 0),eo([be({attribute:!1})],to.prototype,"avatarSrc",void 0),eo([be({type:Boolean})],to.prototype,"useMiniWidget",void 0),eo([be({type:Object})],to.prototype,"launcherStyles",void 0),eo([be({type:Boolean})],to.prototype,"isMinimized",void 0),eo([be({type:String})],to.prototype,"brandColor",void 0),eo([we()],to.prototype,"popup",void 0),eo([we()],to.prototype,"theme",void 0),eo([we()],to.prototype,"chatId",void 0),eo([we()],to.prototype,"analytics",void 0),eo([we()],to.prototype,"isMobile",void 0),eo([we()],to.prototype,"launcher",void 0),eo([we()],to.prototype,"building",void 0),eo([we()],to.prototype,"designConcept",void 0),eo([we()],to.prototype,"leadSources",void 0),eo([we()],to.prototype,"currentLeadSource",void 0),eo([we()],to.prototype,"featureFlagShowDropdown",void 0),eo([we()],to.prototype,"phoneNumberForSource",void 0),eo([we()],to.prototype,"hasMounted",void 0),eo([we()],to.prototype,"hideLauncher",void 0),eo([we()],to.prototype,"isLoading",void 0),eo([we()],to.prototype,"talkjsPopupElement",void 0),eo([we()],to.prototype,"chatProvider",void 0),eo([we()],to.prototype,"showTourNextToChat",void 0),eo([we()],to.prototype,"displayPubnubChat",void 0),eo([we()],to.prototype,"myPubnub",void 0),eo([we()],to.prototype,"enabledChatWidgets",void 0),eo([we()],to.prototype,"webchatConfigHasAutoOpenChat",void 0),eo([we()],to.prototype,"requiresConsent",void 0),to=Zr=eo([ve("me-chat")],to);class no{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),io(),ro();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),no.meChat=n,e.building&&e.organization&&ao(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),no.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)}}no.meChat=null,no.orgSlug="",no.mutationObserver=null,no.previousUrl="",no.hasBuildingSlug=null,no.brandColor="";const io=()=>{const e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("type","text/css"),document.head.appendChild(e)},ro=()=>{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)},oo=e=>{for(const t of e){const e=document.getElementById(t);if(e)return e}return null},ao=async(e,n)=>{var i;if(!n||!e)return;const r=await async function(e){if(!e)return!1;try{return(await t().get(ei(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=oo(["myContactForm","contactus"]);let a;if(!(o&&o instanceof HTMLFormElement))return void(window.location.pathname.toLowerCase().includes("contactus")&&so(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 so(n,e,"Could not find submit button");const s=()=>({firstName:oo(["firstname","txtName"]),lastName:oo(["lastname","txtName2"]),email:oo(["email","txtEmail"]),phone:oo(["phonenumber","txtPhone"]),message:oo(["message","txtComments"])});if(Object.values(s()).some((e=>null===e))){const t=Object.entries(s()).filter((([,e])=>null===e)).map((([e])=>e));return so(n,e,"Missing the following form elements: "+t.join(", "))}const u=a.textContent,l=a.cloneNode(!0);null===(i=a.parentNode)||void 0===i||i.replaceChild(l,a),l.onclick=async function(t){if(Object.values(s()).forEach((e=>{"true"!==(null==e?void 0:e.getAttribute("aria-required"))||e.value||(e.className="form-control required is-invalid")})),!Object.values(s()).every((e=>null!==e&&!("true"===e.getAttribute("aria-required")&&!e.value)&&("email"!==e.id&&"phonenumber"!==e.id||"true"!==e.getAttribute("aria-invalid")))))return;t.preventDefault(),l.textContent="Processing request...",l.disabled=!0;const i={};Object.entries(s()).forEach((([e,t])=>i[e]=null==t?void 0:t.value));const r=await Mi(e,n),a=await Bi(n,document.referrer);if(!r)return so(n,e,"Could not find building"),null;const d={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"])]},c=JSON.stringify(d);fetch("https://app.meetelise.com/platformApi/state/create/contactMe",{method:"POST",headers:{"Content-Type":"application/json","building-slug":n,"org-slug":e},body:c}).then((e=>{if(!e.ok)throw new Error(`HTTP error ${e.status}`);return o&&o.reset(),Object.values(s()).forEach((e=>{e&&(e.disabled=!0)})),l.textContent="Submitted",l.disabled=!0,e.json()})).catch((()=>{l.textContent=u}))}},so=(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
@@ -179,6 +179,16 @@ const installTalkjsMobileStyleFix = () => {
179
179
  document.head.appendChild(metaTag);
180
180
  };
181
181
 
182
+ const findElementById = (priorityIds: string[]): HTMLElement | null => {
183
+ for (const id of priorityIds) {
184
+ const element = document.getElementById(id);
185
+ if (element) {
186
+ return element;
187
+ }
188
+ }
189
+ return null;
190
+ };
191
+
182
192
  const overrideContactUsForm = async (
183
193
  orgSlug: string,
184
194
  buildingSlug?: string
@@ -188,10 +198,7 @@ const overrideContactUsForm = async (
188
198
  await fetchFeatureFlagUseOverrideContactUsForm(buildingSlug);
189
199
  if (!shouldUseOverrideContactUsForm) return;
190
200
 
191
- let form = document.getElementById("myContactForm") as HTMLFormElement | null;
192
- if (!form) {
193
- form = document.getElementById("contactus") as HTMLFormElement | null;
194
- }
201
+ const form = findElementById(["myContactForm", "contactus"]);
195
202
  let btn = undefined;
196
203
 
197
204
  if (!form || !(form instanceof HTMLFormElement)) {
@@ -225,19 +232,26 @@ const overrideContactUsForm = async (
225
232
  "https://app.meetelise.com/platformApi/state/create/contactMe";
226
233
 
227
234
  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;
235
+ const firstName = findElementById([
236
+ "firstname",
237
+ "txtName",
238
+ ]) as HTMLInputElement | null;
239
+ const lastName = findElementById([
240
+ "lastname",
241
+ "txtName2",
242
+ ]) as HTMLInputElement | null;
243
+ const email = findElementById([
244
+ "email",
245
+ "txtEmail",
246
+ ]) as HTMLInputElement | null;
247
+ const phone = findElementById([
248
+ "phonenumber",
249
+ "txtPhone",
250
+ ]) as HTMLInputElement | null;
251
+ const message = findElementById([
252
+ "message",
253
+ "txtComments",
254
+ ]) as HTMLTextAreaElement | null;
241
255
 
242
256
  const formElements = { firstName, lastName, email, phone, message };
243
257