wineater-bot 1.7.3 → 1.7.4

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.
@@ -1,4 +1,4 @@
1
- const b = `
1
+ const y = `
2
2
  @font-face {
3
3
  font-family: 'Poppins';
4
4
  src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
@@ -278,9 +278,9 @@ const b = `
278
278
  visibility: visible;
279
279
  height: 50px;
280
280
  }`, g = document.createElement("style");
281
- g.textContent = b;
281
+ g.textContent = y;
282
282
  document.head.appendChild(g);
283
- function y() {
283
+ function x() {
284
284
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(o) {
285
285
  const t = Math.random() * 16 | 0;
286
286
  return (o === "x" ? t : t & 3 | 8).toString(16);
@@ -305,12 +305,12 @@ function s(o) {
305
305
  }
306
306
  return null;
307
307
  }
308
- function x() {
308
+ function w() {
309
309
  const o = "uniqueUserID";
310
310
  let t = s(o);
311
- return t || (t = y(), h(o, t, 365)), t;
311
+ return t || (t = x(), h(o, t, 365)), t;
312
312
  }
313
- function d(o, t) {
313
+ function c(o, t) {
314
314
  fetch("https://api.wineater.com/proxy/track", {
315
315
  method: "POST",
316
316
  headers: {
@@ -327,19 +327,19 @@ function d(o, t) {
327
327
  });
328
328
  }
329
329
  function p() {
330
- d("Chatbot Opened", { distinct_id: s("uniqueUserID"), client: s("chatbotToken") });
330
+ c("Chatbot Opened", { distinct_id: s("uniqueUserID"), client: s("chatbotToken") });
331
331
  }
332
332
  function u() {
333
- d("Chatbot Closed", { distinct_id: s("uniqueUserID"), client: s("chatbotToken") });
334
- }
335
- function w(o) {
336
- d("Message Sent", { distinct_id: s("uniqueUserID"), message_content: o, client: s("chatbotToken") });
333
+ c("Chatbot Closed", { distinct_id: s("uniqueUserID"), client: s("chatbotToken") });
337
334
  }
338
335
  function v(o) {
339
- d("Products Got", { distinct_id: s("uniqueUserID"), products: o, client: s("chatbotToken") });
336
+ c("Message Sent", { distinct_id: s("uniqueUserID"), message_content: o, client: s("chatbotToken") });
340
337
  }
341
338
  function k(o) {
342
- d("Product Clicked", { distinct_id: s("uniqueUserID"), product_id: o, client: s("chatbotToken") });
339
+ c("Products Got", { distinct_id: s("uniqueUserID"), products: o, client: s("chatbotToken") });
340
+ }
341
+ function E(o) {
342
+ c("Product Clicked", { distinct_id: s("uniqueUserID"), product_id: o, client: s("chatbotToken") });
343
343
  }
344
344
  function m() {
345
345
  const o = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
@@ -348,17 +348,17 @@ function m() {
348
348
  function I() {
349
349
  u(), document.getElementById("chat-window").classList.remove("visible");
350
350
  }
351
- function E() {
351
+ function C() {
352
352
  p(), document.getElementById("chat-window").classList.add("visible");
353
353
  }
354
354
  document.addEventListener("DOMContentLoaded", () => {
355
355
  setupCloseButton(), setupOutsideClick();
356
356
  });
357
- const C = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"], T = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
357
+ const T = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"], B = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
358
358
  class f {
359
359
  constructor(t) {
360
360
  var e;
361
- this.baseURL = "https://api.wineater.com/", this.store = C.find((n) => window.location.href.includes(n)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || T;
361
+ this.baseURL = "https://api.wineater.com/", this.store = T.find((n) => window.location.href.includes(n)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || B;
362
362
  }
363
363
  async getStoreConfig(t) {
364
364
  console.log(t);
@@ -397,7 +397,7 @@ class f {
397
397
  }
398
398
  }
399
399
  }
400
- class B {
400
+ class S {
401
401
  constructor() {
402
402
  this.api = new f(), this.language = "en", this.translations = {
403
403
  fr: {
@@ -466,8 +466,8 @@ class B {
466
466
  return this.translations[this.language][t] || t;
467
467
  }
468
468
  }
469
- const a = new B();
470
- class S {
469
+ const a = new S();
470
+ class L {
471
471
  constructor() {
472
472
  var e;
473
473
  this.api = new f();
@@ -488,7 +488,7 @@ class S {
488
488
  if (e) {
489
489
  this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
490
490
  try {
491
- w(e);
491
+ v(e);
492
492
  const n = await this.api.getWineRecommendations(e);
493
493
  this.hideTypingIndicator(), n && n.length ? this.displayResults(n) : this.displayMessage("No results found.", "api");
494
494
  } catch {
@@ -507,31 +507,33 @@ class S {
507
507
  i.textContent = t, i.className = "message " + e, n.appendChild(i), n.scrollTop = n.scrollHeight;
508
508
  }
509
509
  sendAnalytics(t) {
510
- k(t);
510
+ console.log(t), E(t);
511
511
  }
512
512
  displayResults(t) {
513
513
  const e = document.getElementById("message-container");
514
- v(t.map((n) => n.Title)), t.forEach((n) => {
514
+ k(t.map((n) => n.Title)), t.forEach((n) => {
515
515
  const i = document.createElement("div");
516
516
  i.className = "wine-item";
517
517
  const r = document.createElement("img");
518
518
  r.src = n.Image, i.appendChild(r);
519
- const c = document.createElement("div");
520
- c.innerHTML = `
519
+ const d = document.createElement("div");
520
+ d.innerHTML = `
521
521
  <strong>${n.Title}</strong><br>
522
522
  ${a.translate("price")}: ${n.Price}<br>
523
523
  ${a.translate("region")}: ${n.Region}<br>
524
524
  ${a.translate("type")}: ${n.Type}<br>
525
- <a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${a.translate("moreInfo")}</a>
526
- `, i.appendChild(c), e.appendChild(i), this.displayFirstMessage(n.Reason);
525
+ <a href="${n.Url}" target="_blank">${a.translate("moreInfo")}</a>
526
+ `, d.querySelector("a").addEventListener("click", (b) => {
527
+ b.preventDefault(), this.sendAnalytics(n.Title), window.open(n.Url, "_blank");
528
+ }), i.appendChild(d), e.appendChild(i), this.displayFirstMessage(n.Reason);
527
529
  }), e.scrollTop = e.scrollHeight;
528
530
  }
529
531
  }
530
532
  const W = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
531
533
  document.addEventListener("DOMContentLoaded", () => {
532
- window.toggleChatWindow = m, window.closeChatWindow = I, window.openChatWindow = E;
534
+ window.toggleChatWindow = m, window.closeChatWindow = I, window.openChatWindow = C;
533
535
  });
534
- function L() {
536
+ function P() {
535
537
  var e;
536
538
  const t = `
537
539
  <div id="chatbot-container">
@@ -564,10 +566,10 @@ function L() {
564
566
  `;
565
567
  document.body.insertAdjacentHTML("beforeend", t);
566
568
  }
567
- function P() {
569
+ function O() {
568
570
  document.getElementById("close-btn").addEventListener("click", m);
569
571
  }
570
- function O() {
572
+ function D() {
571
573
  window.addEventListener("click", function(o) {
572
574
  const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
573
575
  !t.contains(o.target) && !e.contains(o.target) && (t.classList.remove("visible"), e.style.display = "flex");
@@ -583,13 +585,13 @@ if (typeof window < "u") {
583
585
  let o = ((l = window == null ? void 0 : window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
584
586
  window.addEventListener("DOMContentLoaded", async () => {
585
587
  var r;
586
- const e = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"].find((c) => window.location.href.includes(c)) || null;
588
+ const e = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"].find((d) => window.location.href.includes(d)) || null;
587
589
  let n;
588
- e && (n = e.charAt(0).toUpperCase() + e.slice(1), n === "Biobio" && (o = "right-center")), await a.fetchConfig(n || "Demo"), L(), P(), O(), M(o), h("chatbotToken", ((r = window.wineaterData) == null ? void 0 : r.CLIENT_TOKEN) || W, 365), x(), new S().initialize();
590
+ e && (n = e.charAt(0).toUpperCase() + e.slice(1), n === "Biobio" && (o = "right-center")), await a.fetchConfig(n || "Demo"), P(), O(), D(), M(o), h("chatbotToken", ((r = window.wineaterData) == null ? void 0 : r.CLIENT_TOKEN) || W, 365), w(), new L().initialize();
589
591
  });
590
592
  }
591
593
  export {
592
594
  I as closeChatWindow,
593
- E as openChatWindow,
595
+ C as openChatWindow,
594
596
  m as toggleChatWindow
595
597
  };
@@ -277,13 +277,13 @@
277
277
  .typing-indicator.visible {
278
278
  visibility: visible;
279
279
  height: 50px;
280
- }`,p=document.createElement("style");p.textContent=d,document.head.appendChild(p);function v(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){const t=Math.random()*16|0;return(o==="x"?t:t&3|8).toString(16)})}function u(o,t,e){let n="";if(e){const i=new Date;i.setTime(i.getTime()+e*24*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=o+"="+(t||"")+n+"; path=/; secure; samesite=strict"}function s(o){const t=o+"=",e=document.cookie.split(";");for(let n=0;n<e.length;n++){let i=e[n];for(;i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null}function k(){const o="uniqueUserID";let t=s(o);return t||(t=v(),u(o,t,365)),t}function c(o,t){fetch("https://api.wineater.com/proxy/track",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:o,properties:t})}).then(i=>{i.ok||console.error("Mixpanel tracking failed",i)}).catch(i=>{console.error("Mixpanel tracking error",i)})}function m(){c("Chatbot Opened",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function f(){c("Chatbot Closed",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function I(o){c("Message Sent",{distinct_id:s("uniqueUserID"),message_content:o,client:s("chatbotToken")})}function E(o){c("Products Got",{distinct_id:s("uniqueUserID"),products:o,client:s("chatbotToken")})}function C(o){c("Product Clicked",{distinct_id:s("uniqueUserID"),product_id:o,client:s("chatbotToken")})}function h(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(f(),o.classList.remove("visible"),t.style.display="flex"):(m(),o.classList.add("visible"),t.style.display="none")}function b(){f(),document.getElementById("chat-window").classList.remove("visible")}function y(){m(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const T=["climats","telckel","biobio","weinpoint","vinigrandi"],B="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class w{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=T.find(n=>window.location.href.includes(n)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||B}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})}),n=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${n.message||"No additional error information"}`);return n}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class W{constructor(){this.api=new w,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",reason:"Suggestion",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:"Maridaje ideal",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",reason:"Sugerencia",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",reason:"Suggestion",moreInfo:"More info"},de:{welcomeMessage:"Verbessern Sie Ihr kulinarisches Erlebnis. Geben Sie einfach die Details Ihres Gerichts an und erhalten Sie die ideale Weinempfehlung. Was möchten Sie essen?",noResultsFound:"Keine Ergebnisse gefunden.",somethingWentWrong:"Entschuldigung, etwas ist schief gelaufen.",chatButton:"Wein zum Abendessen",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",reason:"Anregung",moreInfo:"Mehr Info"}}}async fetchConfig(t="Demo"){try{const e=await this.api.getStoreConfig(t);this.language=e.lang}catch{this.language="en"}}translate(t){return this.translations[this.language][t]||t}}const a=new W;class S{constructor(){var e;this.api=new w;const t=((e=window==null?void 0:window.wineaterData)==null?void 0:e.FIRST_MESSAGE_TEXT)||a.translate("welcomeMessage");this.displayFirstMessage(t)}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",n=>{n.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const n=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,n.appendChild(i),n.scrollTop=n.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{I(e);const n=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),n&&n.length?this.displayResults(n):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(a.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const n=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,n.appendChild(i),n.scrollTop=n.scrollHeight}sendAnalytics(t){C(t)}displayResults(t){const e=document.getElementById("message-container");E(t.map(n=>n.Title)),t.forEach(n=>{const i=document.createElement("div");i.className="wine-item";const l=document.createElement("img");l.src=n.Image,i.appendChild(l);const g=document.createElement("div");g.innerHTML=`
280
+ }`,p=document.createElement("style");p.textContent=d,document.head.appendChild(p);function v(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){const t=Math.random()*16|0;return(o==="x"?t:t&3|8).toString(16)})}function u(o,t,e){let n="";if(e){const i=new Date;i.setTime(i.getTime()+e*24*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=o+"="+(t||"")+n+"; path=/; secure; samesite=strict"}function s(o){const t=o+"=",e=document.cookie.split(";");for(let n=0;n<e.length;n++){let i=e[n];for(;i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null}function k(){const o="uniqueUserID";let t=s(o);return t||(t=v(),u(o,t,365)),t}function c(o,t){fetch("https://api.wineater.com/proxy/track",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:o,properties:t})}).then(i=>{i.ok||console.error("Mixpanel tracking failed",i)}).catch(i=>{console.error("Mixpanel tracking error",i)})}function m(){c("Chatbot Opened",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function f(){c("Chatbot Closed",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function E(o){c("Message Sent",{distinct_id:s("uniqueUserID"),message_content:o,client:s("chatbotToken")})}function I(o){c("Products Got",{distinct_id:s("uniqueUserID"),products:o,client:s("chatbotToken")})}function C(o){c("Product Clicked",{distinct_id:s("uniqueUserID"),product_id:o,client:s("chatbotToken")})}function h(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(f(),o.classList.remove("visible"),t.style.display="flex"):(m(),o.classList.add("visible"),t.style.display="none")}function b(){f(),document.getElementById("chat-window").classList.remove("visible")}function y(){m(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const T=["climats","telckel","biobio","weinpoint","vinigrandi"],B="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class w{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=T.find(n=>window.location.href.includes(n)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||B}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})}),n=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${n.message||"No additional error information"}`);return n}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class W{constructor(){this.api=new w,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",reason:"Suggestion",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:"Maridaje ideal",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",reason:"Sugerencia",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",reason:"Suggestion",moreInfo:"More info"},de:{welcomeMessage:"Verbessern Sie Ihr kulinarisches Erlebnis. Geben Sie einfach die Details Ihres Gerichts an und erhalten Sie die ideale Weinempfehlung. Was möchten Sie essen?",noResultsFound:"Keine Ergebnisse gefunden.",somethingWentWrong:"Entschuldigung, etwas ist schief gelaufen.",chatButton:"Wein zum Abendessen",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",reason:"Anregung",moreInfo:"Mehr Info"}}}async fetchConfig(t="Demo"){try{const e=await this.api.getStoreConfig(t);this.language=e.lang}catch{this.language="en"}}translate(t){return this.translations[this.language][t]||t}}const a=new W;class S{constructor(){var e;this.api=new w;const t=((e=window==null?void 0:window.wineaterData)==null?void 0:e.FIRST_MESSAGE_TEXT)||a.translate("welcomeMessage");this.displayFirstMessage(t)}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",n=>{n.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const n=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,n.appendChild(i),n.scrollTop=n.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{E(e);const n=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),n&&n.length?this.displayResults(n):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(a.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const n=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,n.appendChild(i),n.scrollTop=n.scrollHeight}sendAnalytics(t){console.log(t),C(t)}displayResults(t){const e=document.getElementById("message-container");I(t.map(n=>n.Title)),t.forEach(n=>{const i=document.createElement("div");i.className="wine-item";const l=document.createElement("img");l.src=n.Image,i.appendChild(l);const g=document.createElement("div");g.innerHTML=`
281
281
  <strong>${n.Title}</strong><br>
282
282
  ${a.translate("price")}: ${n.Price}<br>
283
283
  ${a.translate("region")}: ${n.Region}<br>
284
284
  ${a.translate("type")}: ${n.Type}<br>
285
- <a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${a.translate("moreInfo")}</a>
286
- `,i.appendChild(g),e.appendChild(i),this.displayFirstMessage(n.Reason)}),e.scrollTop=e.scrollHeight}}const L="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=b,window.openChatWindow=y});function P(){var e;const t=`
285
+ <a href="${n.Url}" target="_blank">${a.translate("moreInfo")}</a>
286
+ `,g.querySelector("a").addEventListener("click",A=>{A.preventDefault(),this.sendAnalytics(n.Title),window.open(n.Url,"_blank")}),i.appendChild(g),e.appendChild(i),this.displayFirstMessage(n.Reason)}),e.scrollTop=e.scrollHeight}}const L="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=b,window.openChatWindow=y});function P(){var e;const t=`
287
287
  <div id="chatbot-container">
288
288
  <div id="chat-icon" onclick="toggleChatWindow()">
289
289
  <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 -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/js/chatbot.js CHANGED
@@ -84,6 +84,7 @@ export class Chatbot {
84
84
  }
85
85
 
86
86
  sendAnalytics(product) {
87
+ console.log(product);
87
88
  trackProductClick(product);
88
89
  }
89
90
 
@@ -104,8 +105,16 @@ export class Chatbot {
104
105
  ${translator.translate('price')}: ${wine.Price}<br>
105
106
  ${translator.translate('region')}: ${wine.Region}<br>
106
107
  ${translator.translate('type')}: ${wine.Type}<br>
107
- <a href="${wine.Url}" onclick="sendAnalytics(${wine.Title})" target="_blank">${translator.translate('moreInfo')}</a>
108
+ <a href="${wine.Url}" target="_blank">${translator.translate('moreInfo')}</a>
108
109
  `;
110
+
111
+ // Add click event listener to the link
112
+ const link = contentDiv.querySelector('a');
113
+ link.addEventListener('click', (event) => {
114
+ event.preventDefault(); // Prevent the default link behavior
115
+ this.sendAnalytics(wine.Title); // Call sendAnalytics when clicked
116
+ window.open(wine.Url, '_blank'); // Open the link in a new tab
117
+ });
109
118
  wineDiv.appendChild(contentDiv);
110
119
  // const suggestionDiv = document.createElement('div');
111
120
  // suggestionDiv.innerHTML = `${translator.translate('reason')}: ${wine.Reason}<br>`;