wineater-bot 1.5.2 → 1.5.3

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.
@@ -276,30 +276,30 @@ const f = `
276
276
  }`, p = document.createElement("style");
277
277
  p.textContent = f;
278
278
  document.head.appendChild(p);
279
- function b(n, t, e) {
279
+ function b(n, e, t) {
280
280
  let o = "";
281
- if (e) {
281
+ if (t) {
282
282
  const i = /* @__PURE__ */ new Date();
283
- i.setTime(i.getTime() + e * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
283
+ i.setTime(i.getTime() + t * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
284
284
  }
285
- document.cookie = n + "=" + (t || "") + o + "; path=/; secure; samesite=strict";
285
+ document.cookie = n + "=" + (e || "") + o + "; path=/; secure; samesite=strict";
286
286
  }
287
287
  function r(n) {
288
- const e = `; ${document.cookie}`.split(`; ${n}=`);
289
- if (e.length === 2)
290
- return e.pop().split(";").shift();
288
+ const t = `; ${document.cookie}`.split(`; ${n}=`);
289
+ if (t.length === 2)
290
+ return t.pop().split(";").shift();
291
291
  }
292
- function d(n, t) {
293
- const e = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api-eu.mixpanel.com/track", i = {
292
+ function d(n, e) {
293
+ const t = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api-eu.mixpanel.com/track", i = {
294
294
  event: n,
295
295
  properties: {
296
- token: e,
297
- ...t
296
+ token: t,
297
+ ...e
298
298
  }
299
299
  };
300
300
  fetch(o, {
301
301
  method: "POST",
302
- body: JSON.stringify([i])
302
+ body: JSON.stringify(i)
303
303
  }).then((s) => {
304
304
  s.ok || console.error("Mixpanel tracking failed", s);
305
305
  }).catch((s) => {
@@ -322,8 +322,8 @@ function x(n) {
322
322
  d("Product Clicked", { distinct_id: r("chatbotToken"), product_id: n });
323
323
  }
324
324
  function u() {
325
- const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
326
- n.classList.contains("visible") ? (h(), n.classList.remove("visible"), t.style.display = "flex") : (g(), n.classList.add("visible"), t.style.display = "none");
325
+ const n = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
326
+ n.classList.contains("visible") ? (h(), n.classList.remove("visible"), e.style.display = "flex") : (g(), n.classList.add("visible"), e.style.display = "none");
327
327
  }
328
328
  function v() {
329
329
  h(), document.getElementById("chat-window").classList.remove("visible");
@@ -336,44 +336,44 @@ document.addEventListener("DOMContentLoaded", () => {
336
336
  });
337
337
  const C = ["climats", "telckel", "biobio", "weinpoint"], E = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
338
338
  class m {
339
- constructor(t) {
340
- var e;
341
- this.baseURL = "https://api.wineater.com/", this.store = C.find((o) => window.location.href.includes(o)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || E;
339
+ constructor(e) {
340
+ var t;
341
+ this.baseURL = "https://api.wineater.com/", this.store = C.find((o) => window.location.href.includes(o)), this.token = ((t = window == null ? void 0 : window.wineaterData) == null ? void 0 : t.CLIENT_TOKEN) || E;
342
342
  }
343
- async getStoreConfig(t) {
344
- console.log(t);
343
+ async getStoreConfig(e) {
344
+ console.log(e);
345
345
  try {
346
- const e = await fetch(`${this.baseURL}stores/store`, {
346
+ const t = await fetch(`${this.baseURL}stores/store`, {
347
347
  method: "POST",
348
348
  headers: {
349
349
  "Content-Type": "application/json",
350
350
  Authorization: `Bearer ${this.token}`
351
351
  },
352
- body: JSON.stringify({ store: t })
352
+ body: JSON.stringify({ store: e })
353
353
  });
354
- if (!e.ok)
355
- throw new Error(`HTTP error! Status: ${e.status}`);
356
- return await e.json();
357
- } catch (e) {
358
- throw console.error("Error fetching store configuration:", e), e;
354
+ if (!t.ok)
355
+ throw new Error(`HTTP error! Status: ${t.status}`);
356
+ return await t.json();
357
+ } catch (t) {
358
+ throw console.error("Error fetching store configuration:", t), t;
359
359
  }
360
360
  }
361
- async getWineRecommendations(t) {
361
+ async getWineRecommendations(e) {
362
362
  console.log(window.location.href);
363
363
  try {
364
- const e = await fetch(`${this.baseURL}dish/recommendations`, {
364
+ const t = await fetch(`${this.baseURL}dish/recommendations`, {
365
365
  method: "POST",
366
366
  headers: {
367
367
  "Content-Type": "application/json",
368
368
  Authorization: `Bearer ${this.token}`
369
369
  },
370
- body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
371
- }), o = await e.json();
372
- if (!e.ok)
373
- throw new Error(`API call failed with status ${e.status}: ${o.message || "No additional error information"}`);
370
+ body: JSON.stringify({ text: e, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
371
+ }), o = await t.json();
372
+ if (!t.ok)
373
+ throw new Error(`API call failed with status ${t.status}: ${o.message || "No additional error information"}`);
374
374
  return o;
375
- } catch (e) {
376
- throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
375
+ } catch (t) {
376
+ throw console.error("Fetching wine recommendations failed:", t.message), new Error(`Error in getWineRecommendations: ${t.message}`);
377
377
  }
378
378
  }
379
379
  }
@@ -418,14 +418,14 @@ class I {
418
418
  }
419
419
  };
420
420
  }
421
- async fetchConfig(t) {
422
- if (t) {
423
- const e = await this.api.getStoreConfig(t);
424
- this.language = e.lang;
421
+ async fetchConfig(e) {
422
+ if (e) {
423
+ const t = await this.api.getStoreConfig(e);
424
+ this.language = t.lang;
425
425
  }
426
426
  }
427
- translate(t) {
428
- return this.translations[this.language][t] || t;
427
+ translate(e) {
428
+ return this.translations[this.language][e] || e;
429
429
  }
430
430
  }
431
431
  const a = new I();
@@ -438,17 +438,17 @@ class T {
438
438
  o.key === "Enter" && this.handleUserInput();
439
439
  });
440
440
  }
441
- displayFirstMessage(t, e = "api") {
441
+ displayFirstMessage(e, t = "api") {
442
442
  const o = document.getElementById("message-container"), i = document.createElement("div");
443
- i.className = `message ${e}`, i.textContent = t, o.appendChild(i), o.scrollTop = o.scrollHeight;
443
+ i.className = `message ${t}`, i.textContent = e, o.appendChild(i), o.scrollTop = o.scrollHeight;
444
444
  }
445
445
  async handleUserInput() {
446
- const t = document.getElementById("user-input"), e = t.value.trim();
447
- if (e) {
448
- this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
446
+ const e = document.getElementById("user-input"), t = e.value.trim();
447
+ if (t) {
448
+ this.displayMessage(t, "user"), e.value = "", this.showTypingIndicator();
449
449
  try {
450
- y(e);
451
- const o = await this.api.getWineRecommendations(e);
450
+ y(t);
451
+ const o = await this.api.getWineRecommendations(t);
452
452
  this.hideTypingIndicator(), o && o.length ? this.displayResults(o) : this.displayMessage("No results found.", "api");
453
453
  } catch {
454
454
  this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
@@ -461,16 +461,16 @@ class T {
461
461
  hideTypingIndicator() {
462
462
  document.getElementById("typing-indicator").classList.remove("visible");
463
463
  }
464
- displayMessage(t, e) {
464
+ displayMessage(e, t) {
465
465
  const o = document.getElementById("message-container"), i = document.createElement("div");
466
- i.textContent = t, i.className = "message " + e, o.appendChild(i), o.scrollTop = o.scrollHeight;
466
+ i.textContent = e, i.className = "message " + t, o.appendChild(i), o.scrollTop = o.scrollHeight;
467
467
  }
468
- sendAnalytics(t) {
469
- x(t);
468
+ sendAnalytics(e) {
469
+ x(e);
470
470
  }
471
- displayResults(t) {
472
- const e = document.getElementById("message-container");
473
- w(t.map((o) => o.Title)), t.forEach((o) => {
471
+ displayResults(e) {
472
+ const t = document.getElementById("message-container");
473
+ w(e.map((o) => o.Title)), e.forEach((o) => {
474
474
  const i = document.createElement("div");
475
475
  i.className = "wine-item";
476
476
  const s = document.createElement("img");
@@ -482,14 +482,15 @@ class T {
482
482
  ${a.translate("region")}: ${o.Region}<br>
483
483
  ${a.translate("type")}: ${o.Type}<br>
484
484
  <a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${a.translate("moreInfo")}</a>
485
- `, i.appendChild(c), e.appendChild(i);
486
- }), e.scrollTop = e.scrollHeight;
485
+ `, i.appendChild(c), t.appendChild(i);
486
+ }), t.scrollTop = t.scrollHeight;
487
487
  }
488
488
  }
489
+ const B = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
489
490
  document.addEventListener("DOMContentLoaded", () => {
490
491
  window.toggleChatWindow = u, window.closeChatWindow = v, window.openChatWindow = k;
491
492
  });
492
- function B() {
493
+ function L() {
493
494
  const n = `
494
495
  <div id="chatbot-container">
495
496
  <div id="chat-icon" onclick="toggleChatWindow()">
@@ -519,28 +520,28 @@ function B() {
519
520
  `;
520
521
  document.body.insertAdjacentHTML("beforeend", n);
521
522
  }
522
- function L() {
523
+ function P() {
523
524
  document.getElementById("close-btn").addEventListener("click", u);
524
525
  }
525
- function P() {
526
+ function W() {
526
527
  window.addEventListener("click", function(n) {
527
- const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
528
- !t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
528
+ const e = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
529
+ !e.contains(n.target) && !t.contains(n.target) && (e.classList.remove("visible"), t.style.display = "flex");
529
530
  });
530
531
  }
531
- function W(n) {
532
+ function O(n) {
532
533
  console.log(n);
533
- const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
534
- t.className = "", e.className = "", n === "right-center" ? (t.classList.add("chat-icon-right-center"), e.classList.add("right-center-aligned")) : t.classList.add("chat-icon-bottom-right");
534
+ const e = document.getElementById("chat-icon"), t = document.getElementById("chat-window");
535
+ e.className = "", t.className = "", n === "right-center" ? (e.classList.add("chat-icon-right-center"), t.classList.add("right-center-aligned")) : e.classList.add("chat-icon-bottom-right");
535
536
  }
536
537
  var l;
537
538
  if (typeof window < "u") {
538
539
  const n = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
539
540
  window.addEventListener("DOMContentLoaded", async () => {
540
541
  var s;
541
- const e = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
542
+ const t = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
542
543
  let o;
543
- e && (o = e.charAt(0).toUpperCase() + e.slice(1)), await a.fetchConfig(o || null), B(), L(), P(), W(n), b("chatbotToken", (s = window.wineaterData) == null ? void 0 : s.CLIENT_TOKEN, 365), new T().initialize();
544
+ t && (o = t.charAt(0).toUpperCase() + t.slice(1)), await a.fetchConfig(o || null), L(), P(), W(), O(n), b("chatbotToken", ((s = window.wineaterData) == null ? void 0 : s.CLIENT_TOKEN) || B, 365), new T().initialize();
544
545
  });
545
546
  }
546
547
  export {
@@ -273,13 +273,13 @@
273
273
  .typing-indicator.visible {
274
274
  visibility: visible;
275
275
  height: 50px;
276
- }`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function x(n,t,e){let o="";if(e){const i=new Date;i.setTime(i.getTime()+e*24*60*60*1e3),o="; expires="+i.toUTCString()}document.cookie=n+"="+(t||"")+o+"; path=/; secure; samesite=strict"}function c(n){const e=`; ${document.cookie}`.split(`; ${n}=`);if(e.length===2)return e.pop().split(";").shift()}function l(n,t){const e="6f3d90d5b02720f58de3663e3ef675fe",o="https://api-eu.mixpanel.com/track",i={event:n,properties:{token:e,...t}};fetch(o,{method:"POST",body:JSON.stringify([i])}).then(a=>{a.ok||console.error("Mixpanel tracking failed",a)}).catch(a=>{console.error("Mixpanel tracking error",a)})}function u(){l("Chatbot Opened",{distinct_id:c("chatbotToken")})}function m(){l("Chatbot Closed",{distinct_id:c("chatbotToken")})}function v(n){l("Message Sent",{distinct_id:c("chatbotToken"),message_content:n})}function k(n){l("Message Sent",{distinct_id:c("chatbotToken"),products:n})}function C(n){l("Product Clicked",{distinct_id:c("chatbotToken"),product_id:n})}function h(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(m(),n.classList.remove("visible"),t.style.display="flex"):(u(),n.classList.add("visible"),t.style.display="none")}function f(){m(),document.getElementById("chat-window").classList.remove("visible")}function b(){u(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const E=["climats","telckel","biobio","weinpoint"],I="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=E.find(o=>window.location.href.includes(o)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||I}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),o=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${o.message||"No additional error information"}`);return o}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class T{constructor(){this.api=new y,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"}}}async fetchConfig(t){if(t){const e=await this.api.getStoreConfig(t);this.language=e.lang}}translate(t){return this.translations[this.language][t]||t}}const s=new T;class B{constructor(){this.api=new y,this.displayFirstMessage(s.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",o=>{o.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const o=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,o.appendChild(i),o.scrollTop=o.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{v(e);const o=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),o&&o.length?this.displayResults(o):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(s.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const o=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,o.appendChild(i),o.scrollTop=o.scrollHeight}sendAnalytics(t){C(t)}displayResults(t){const e=document.getElementById("message-container");k(t.map(o=>o.Title)),t.forEach(o=>{const i=document.createElement("div");i.className="wine-item";const a=document.createElement("img");a.src=o.Image,i.appendChild(a);const p=document.createElement("div");p.innerHTML=`
276
+ }`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function x(n,t,e){let o="";if(e){const i=new Date;i.setTime(i.getTime()+e*24*60*60*1e3),o="; expires="+i.toUTCString()}document.cookie=n+"="+(t||"")+o+"; path=/; secure; samesite=strict"}function c(n){const e=`; ${document.cookie}`.split(`; ${n}=`);if(e.length===2)return e.pop().split(";").shift()}function l(n,t){const e="6f3d90d5b02720f58de3663e3ef675fe",o="https://api-eu.mixpanel.com/track",i={event:n,properties:{token:e,...t}};fetch(o,{method:"POST",body:JSON.stringify(i)}).then(a=>{a.ok||console.error("Mixpanel tracking failed",a)}).catch(a=>{console.error("Mixpanel tracking error",a)})}function u(){l("Chatbot Opened",{distinct_id:c("chatbotToken")})}function m(){l("Chatbot Closed",{distinct_id:c("chatbotToken")})}function v(n){l("Message Sent",{distinct_id:c("chatbotToken"),message_content:n})}function k(n){l("Message Sent",{distinct_id:c("chatbotToken"),products:n})}function C(n){l("Product Clicked",{distinct_id:c("chatbotToken"),product_id:n})}function h(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(m(),n.classList.remove("visible"),t.style.display="flex"):(u(),n.classList.add("visible"),t.style.display="none")}function f(){m(),document.getElementById("chat-window").classList.remove("visible")}function b(){u(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const E=["climats","telckel","biobio","weinpoint"],I="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=E.find(o=>window.location.href.includes(o)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||I}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),o=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${o.message||"No additional error information"}`);return o}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class T{constructor(){this.api=new y,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"}}}async fetchConfig(t){if(t){const e=await this.api.getStoreConfig(t);this.language=e.lang}}translate(t){return this.translations[this.language][t]||t}}const s=new T;class B{constructor(){this.api=new y,this.displayFirstMessage(s.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",o=>{o.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const o=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,o.appendChild(i),o.scrollTop=o.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{v(e);const o=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),o&&o.length?this.displayResults(o):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(s.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const o=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,o.appendChild(i),o.scrollTop=o.scrollHeight}sendAnalytics(t){C(t)}displayResults(t){const e=document.getElementById("message-container");k(t.map(o=>o.Title)),t.forEach(o=>{const i=document.createElement("div");i.className="wine-item";const a=document.createElement("img");a.src=o.Image,i.appendChild(a);const p=document.createElement("div");p.innerHTML=`
277
277
  <strong>${o.Title}</strong><br>
278
278
  ${s.translate("price")}: ${o.Price}<br>
279
279
  ${s.translate("region")}: ${o.Region}<br>
280
280
  ${s.translate("type")}: ${o.Type}<br>
281
281
  <a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${s.translate("moreInfo")}</a>
282
- `,i.appendChild(p),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=f,window.openChatWindow=b});function L(){const n=`
282
+ `,i.appendChild(p),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}const L="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=f,window.openChatWindow=b});function W(){const n=`
283
283
  <div id="chatbot-container">
284
284
  <div id="chat-icon" onclick="toggleChatWindow()">
285
285
  <img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon"> <!-- Update the path to your logo image -->
@@ -305,4 +305,4 @@
305
305
  </div>
306
306
  </div>
307
307
  </div>
308
- `;document.body.insertAdjacentHTML("beforeend",n)}function W(){document.getElementById("close-btn").addEventListener("click",h)}function P(){window.addEventListener("click",function(n){const t=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!t.contains(n.target)&&!e.contains(n.target)&&(t.classList.remove("visible"),e.style.display="flex")})}function S(n){console.log(n);const t=document.getElementById("chat-icon"),e=document.getElementById("chat-window");t.className="",e.className="",n==="right-center"?(t.classList.add("chat-icon-right-center"),e.classList.add("right-center-aligned")):t.classList.add("chat-icon-bottom-right")}if(typeof window<"u"){const n=((w=window.wineaterData)==null?void 0:w.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var a;const e=["climats","telckel","biobio","weinpoint"].find(p=>window.location.href.includes(p))||null;let o;e&&(o=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(o||null),L(),W(),P(),S(n),x("chatbotToken",(a=window.wineaterData)==null?void 0:a.CLIENT_TOKEN,365),new B().initialize()})}r.closeChatWindow=f,r.openChatWindow=b,r.toggleChatWindow=h,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
308
+ `;document.body.insertAdjacentHTML("beforeend",n)}function P(){document.getElementById("close-btn").addEventListener("click",h)}function O(){window.addEventListener("click",function(n){const t=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!t.contains(n.target)&&!e.contains(n.target)&&(t.classList.remove("visible"),e.style.display="flex")})}function S(n){console.log(n);const t=document.getElementById("chat-icon"),e=document.getElementById("chat-window");t.className="",e.className="",n==="right-center"?(t.classList.add("chat-icon-right-center"),e.classList.add("right-center-aligned")):t.classList.add("chat-icon-bottom-right")}if(typeof window<"u"){const n=((w=window.wineaterData)==null?void 0:w.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var a;const e=["climats","telckel","biobio","weinpoint"].find(p=>window.location.href.includes(p))||null;let o;e&&(o=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(o||null),W(),P(),O(),S(n),x("chatbotToken",((a=window.wineaterData)==null?void 0:a.CLIENT_TOKEN)||L,365),new B().initialize()})}r.closeChatWindow=f,r.openChatWindow=b,r.toggleChatWindow=h,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/index.js CHANGED
@@ -10,6 +10,9 @@ import { Chatbot } from './js/chatbot.js';
10
10
  import './js/api.js';
11
11
  import translator from './js/i18n.js';
12
12
 
13
+ const DEMO_TOKEN='OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL';
14
+
15
+
13
16
  document.addEventListener('DOMContentLoaded', () => {
14
17
  // Attach any necessary initialization code here
15
18
  // For example, expose functions to global scope if absolutely necessary
@@ -105,7 +108,7 @@ if (typeof window !== 'undefined') {
105
108
  setupCloseButton();
106
109
  setupOutsideClick();
107
110
  toggleChatIconPosition(position);
108
- setCookie('chatbotToken', window.wineaterData?.CLIENT_TOKEN, 365);
111
+ setCookie('chatbotToken', window.wineaterData?.CLIENT_TOKEN || DEMO_TOKEN, 365);
109
112
  const myChatbot = new Chatbot();
110
113
  myChatbot.initialize();
111
114
  });
@@ -30,7 +30,7 @@ function setCookie(name, value, days) {
30
30
 
31
31
  fetch(endpoint, {
32
32
  method: 'POST',
33
- body: JSON.stringify([data])
33
+ body: JSON.stringify(data)
34
34
  }).then(response => {
35
35
  if (!response.ok) {
36
36
  console.error('Mixpanel tracking failed', response);