wineater-bot 1.5.10 → 1.5.12

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.
@@ -303,10 +303,6 @@ function d(o, t) {
303
303
  }];
304
304
  fetch(n, {
305
305
  method: "POST",
306
- headers: {
307
- accept: "text/plain",
308
- "content-type": "application/json"
309
- },
310
306
  body: JSON.stringify(i)
311
307
  }).then((s) => {
312
308
  s.ok || console.error("Mixpanel tracking failed", s);
@@ -450,7 +446,7 @@ class C {
450
446
  }
451
447
  };
452
448
  }
453
- async fetchConfig(t) {
449
+ async fetchConfig(t = "Demo") {
454
450
  if (t) {
455
451
  const e = await this.api.getStoreConfig(t);
456
452
  this.language = e.lang;
@@ -277,7 +277,7 @@
277
277
  .typing-indicator.visible {
278
278
  visibility: visible;
279
279
  height: 50px;
280
- }`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function x(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 c(o){const e=`; ${document.cookie}`.split(`; ${o}=`);if(e.length===2)return e.pop().split(";").shift()}function l(o,t){const e="6f3d90d5b02720f58de3663e3ef675fe",n="https://api.mixpanel.com/track",i=[{event:o,properties:{token:e,...t}}];fetch(n,{method:"POST",headers:{accept:"text/plain","content-type":"application/json"},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(o){l("Message Sent",{distinct_id:c("chatbotToken"),message_content:o})}function k(o){l("Message Sent",{distinct_id:c("chatbotToken"),products:o})}function E(o){l("Product Clicked",{distinct_id:c("chatbotToken"),product_id:o})}function h(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(m(),o.classList.remove("visible"),t.style.display="flex"):(u(),o.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 C=["climats","telckel","biobio","weinpoint"],I="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;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)||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})}),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 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"},de:{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"},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 kombinieren",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",moreInfo:"Mehr 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 W{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",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{v(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(s.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){E(t)}displayResults(t){const e=document.getElementById("message-container");k(t.map(n=>n.Title)),t.forEach(n=>{const i=document.createElement("div");i.className="wine-item";const a=document.createElement("img");a.src=n.Image,i.appendChild(a);const p=document.createElement("div");p.innerHTML=`
280
+ }`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function x(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 c(o){const e=`; ${document.cookie}`.split(`; ${o}=`);if(e.length===2)return e.pop().split(";").shift()}function l(o,t){const e="6f3d90d5b02720f58de3663e3ef675fe",n="https://api.mixpanel.com/track",i=[{event:o,properties:{token:e,...t}}];fetch(n,{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(o){l("Message Sent",{distinct_id:c("chatbotToken"),message_content:o})}function k(o){l("Message Sent",{distinct_id:c("chatbotToken"),products:o})}function E(o){l("Product Clicked",{distinct_id:c("chatbotToken"),product_id:o})}function h(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(m(),o.classList.remove("visible"),t.style.display="flex"):(u(),o.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 C=["climats","telckel","biobio","weinpoint"],I="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;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)||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})}),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 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"},de:{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"},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 kombinieren",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",moreInfo:"Mehr Info"}}}async fetchConfig(t="Demo"){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 W{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",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{v(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(s.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){E(t)}displayResults(t){const e=document.getElementById("message-container");k(t.map(n=>n.Title)),t.forEach(n=>{const i=document.createElement("div");i.className="wine-item";const a=document.createElement("img");a.src=n.Image,i.appendChild(a);const p=document.createElement("div");p.innerHTML=`
281
281
  <strong>${n.Title}</strong><br>
282
282
  ${s.translate("price")}: ${n.Price}<br>
283
283
  ${s.translate("region")}: ${n.Region}<br>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.5.10",
3
+ "version": "1.5.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
@@ -23,17 +23,13 @@ function setCookie(name, value, days) {
23
23
  const data = [{
24
24
  event,
25
25
  properties: {
26
- token: token,
26
+ token,
27
27
  ...properties
28
28
  }
29
29
  }];
30
30
 
31
31
  fetch(endpoint, {
32
32
  method: 'POST',
33
- headers: {
34
- 'accept': 'text/plain',
35
- 'content-type': 'application/json'
36
- },
37
33
  body: JSON.stringify(data)
38
34
  }).then(response => {
39
35
  if (!response.ok) {
package/src/js/i18n.js CHANGED
@@ -68,7 +68,7 @@ class Translator {
68
68
  };
69
69
  }
70
70
 
71
- async fetchConfig(storeName) {
71
+ async fetchConfig(storeName = 'Demo') {
72
72
  if (storeName) {
73
73
  const config = await this.api.getStoreConfig(storeName);
74
74
  this.language = config.lang;