wineater-bot 1.5.4 → 1.5.6

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 f = `
1
+ const m = `
2
2
  @font-face {
3
3
  font-family: 'Poppins';
4
4
  src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
@@ -273,32 +273,27 @@ const f = `
273
273
  .typing-indicator.visible {
274
274
  visibility: visible;
275
275
  height: 50px;
276
- }`, p = document.createElement("style");
277
- p.textContent = f;
278
- document.head.appendChild(p);
279
- function b(n, e, t) {
276
+ }`, l = document.createElement("style");
277
+ l.textContent = m;
278
+ document.head.appendChild(l);
279
+ function f(n, t, e) {
280
280
  let o = "";
281
- if (t) {
281
+ if (e) {
282
282
  const i = /* @__PURE__ */ new Date();
283
- i.setTime(i.getTime() + t * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
283
+ i.setTime(i.getTime() + e * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
284
284
  }
285
- document.cookie = n + "=" + (e || "") + o + "; path=/; secure; samesite=strict";
285
+ document.cookie = n + "=" + (t || "") + o + "; path=/; secure; samesite=strict";
286
286
  }
287
- function r(n) {
288
- const t = `; ${document.cookie}`.split(`; ${n}=`);
289
- if (t.length === 2)
290
- return t.pop().split(";").shift();
291
- }
292
- function d(n, e) {
293
- const t = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api-eu.mixpanel.com/track", i = {
287
+ function r(n, t) {
288
+ const e = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api-eu.mixpanel.com/track", i = {
294
289
  event: n,
295
- properties: e
290
+ properties: {
291
+ token: e,
292
+ ...t
293
+ }
296
294
  };
297
295
  fetch(o, {
298
296
  method: "POST",
299
- headers: {
300
- Authorization: "Basic " + btoa(`${t}:`)
301
- },
302
297
  body: JSON.stringify(i)
303
298
  }).then((s) => {
304
299
  s.ok || console.error("Mixpanel tracking failed", s);
@@ -306,80 +301,80 @@ function d(n, e) {
306
301
  console.error("Mixpanel tracking error", s);
307
302
  });
308
303
  }
309
- function h() {
310
- d("Chatbot Opened", { distinct_id: r("chatbotToken") });
304
+ function p() {
305
+ r("Chatbot Opened", {});
311
306
  }
312
307
  function g() {
313
- d("Chatbot Closed", { distinct_id: r("chatbotToken") });
308
+ r("Chatbot Closed", {});
314
309
  }
315
310
  function y(n) {
316
- d("Message Sent", { distinct_id: r("chatbotToken"), message_content: n });
311
+ r("Message Sent", { message_content: n });
317
312
  }
318
- function w(n) {
319
- d("Message Sent", { distinct_id: r("chatbotToken"), products: n });
313
+ function b(n) {
314
+ r("Message Sent", { products: n });
320
315
  }
321
- function x(n) {
322
- d("Product Clicked", { distinct_id: r("chatbotToken"), product_id: n });
316
+ function w(n) {
317
+ r("Product Clicked", { product_id: n });
323
318
  }
324
- function u() {
325
- const n = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
326
- n.classList.contains("visible") ? (g(), n.classList.remove("visible"), e.style.display = "flex") : (h(), n.classList.add("visible"), e.style.display = "none");
319
+ function h() {
320
+ const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
321
+ n.classList.contains("visible") ? (g(), n.classList.remove("visible"), t.style.display = "flex") : (p(), n.classList.add("visible"), t.style.display = "none");
327
322
  }
328
- function v() {
323
+ function x() {
329
324
  g(), document.getElementById("chat-window").classList.remove("visible");
330
325
  }
331
- function k() {
332
- h(), document.getElementById("chat-window").classList.add("visible");
326
+ function v() {
327
+ p(), document.getElementById("chat-window").classList.add("visible");
333
328
  }
334
329
  document.addEventListener("DOMContentLoaded", () => {
335
330
  setupCloseButton(), setupOutsideClick();
336
331
  });
337
- const C = ["climats", "telckel", "biobio", "weinpoint"], E = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
338
- class m {
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;
332
+ const k = ["climats", "telckel", "biobio", "weinpoint"], E = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
333
+ class u {
334
+ constructor(t) {
335
+ var e;
336
+ this.baseURL = "https://api.wineater.com/", this.store = k.find((o) => window.location.href.includes(o)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || E;
342
337
  }
343
- async getStoreConfig(e) {
344
- console.log(e);
338
+ async getStoreConfig(t) {
339
+ console.log(t);
345
340
  try {
346
- const t = await fetch(`${this.baseURL}stores/store`, {
341
+ const e = await fetch(`${this.baseURL}stores/store`, {
347
342
  method: "POST",
348
343
  headers: {
349
344
  "Content-Type": "application/json",
350
345
  Authorization: `Bearer ${this.token}`
351
346
  },
352
- body: JSON.stringify({ store: e })
347
+ body: JSON.stringify({ store: t })
353
348
  });
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;
349
+ if (!e.ok)
350
+ throw new Error(`HTTP error! Status: ${e.status}`);
351
+ return await e.json();
352
+ } catch (e) {
353
+ throw console.error("Error fetching store configuration:", e), e;
359
354
  }
360
355
  }
361
- async getWineRecommendations(e) {
356
+ async getWineRecommendations(t) {
362
357
  console.log(window.location.href);
363
358
  try {
364
- const t = await fetch(`${this.baseURL}dish/recommendations`, {
359
+ const e = await fetch(`${this.baseURL}dish/recommendations`, {
365
360
  method: "POST",
366
361
  headers: {
367
362
  "Content-Type": "application/json",
368
363
  Authorization: `Bearer ${this.token}`
369
364
  },
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"}`);
365
+ body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
366
+ }), o = await e.json();
367
+ if (!e.ok)
368
+ throw new Error(`API call failed with status ${e.status}: ${o.message || "No additional error information"}`);
374
369
  return o;
375
- } catch (t) {
376
- throw console.error("Fetching wine recommendations failed:", t.message), new Error(`Error in getWineRecommendations: ${t.message}`);
370
+ } catch (e) {
371
+ throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
377
372
  }
378
373
  }
379
374
  }
380
- class I {
375
+ class C {
381
376
  constructor() {
382
- this.api = new m(), this.language = "en", this.translations = {
377
+ this.api = new u(), this.language = "en", this.translations = {
383
378
  fr: {
384
379
  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?",
385
380
  noResultsFound: "Aucun résultat trouvé.",
@@ -418,37 +413,37 @@ class I {
418
413
  }
419
414
  };
420
415
  }
421
- async fetchConfig(e) {
422
- if (e) {
423
- const t = await this.api.getStoreConfig(e);
424
- this.language = t.lang;
416
+ async fetchConfig(t) {
417
+ if (t) {
418
+ const e = await this.api.getStoreConfig(t);
419
+ this.language = e.lang;
425
420
  }
426
421
  }
427
- translate(e) {
428
- return this.translations[this.language][e] || e;
422
+ translate(t) {
423
+ return this.translations[this.language][t] || t;
429
424
  }
430
425
  }
431
- const a = new I();
432
- class T {
426
+ const a = new C();
427
+ class I {
433
428
  constructor() {
434
- this.api = new m(), this.displayFirstMessage(a.translate("welcomeMessage"));
429
+ this.api = new u(), this.displayFirstMessage(a.translate("welcomeMessage"));
435
430
  }
436
431
  initialize() {
437
432
  document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (o) => {
438
433
  o.key === "Enter" && this.handleUserInput();
439
434
  });
440
435
  }
441
- displayFirstMessage(e, t = "api") {
436
+ displayFirstMessage(t, e = "api") {
442
437
  const o = document.getElementById("message-container"), i = document.createElement("div");
443
- i.className = `message ${t}`, i.textContent = e, o.appendChild(i), o.scrollTop = o.scrollHeight;
438
+ i.className = `message ${e}`, i.textContent = t, o.appendChild(i), o.scrollTop = o.scrollHeight;
444
439
  }
445
440
  async handleUserInput() {
446
- const e = document.getElementById("user-input"), t = e.value.trim();
447
- if (t) {
448
- this.displayMessage(t, "user"), e.value = "", this.showTypingIndicator();
441
+ const t = document.getElementById("user-input"), e = t.value.trim();
442
+ if (e) {
443
+ this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
449
444
  try {
450
- y(t);
451
- const o = await this.api.getWineRecommendations(t);
445
+ y(e);
446
+ const o = await this.api.getWineRecommendations(e);
452
447
  this.hideTypingIndicator(), o && o.length ? this.displayResults(o) : this.displayMessage("No results found.", "api");
453
448
  } catch {
454
449
  this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
@@ -461,36 +456,36 @@ class T {
461
456
  hideTypingIndicator() {
462
457
  document.getElementById("typing-indicator").classList.remove("visible");
463
458
  }
464
- displayMessage(e, t) {
459
+ displayMessage(t, e) {
465
460
  const o = document.getElementById("message-container"), i = document.createElement("div");
466
- i.textContent = e, i.className = "message " + t, o.appendChild(i), o.scrollTop = o.scrollHeight;
461
+ i.textContent = t, i.className = "message " + e, o.appendChild(i), o.scrollTop = o.scrollHeight;
467
462
  }
468
- sendAnalytics(e) {
469
- x(e);
463
+ sendAnalytics(t) {
464
+ w(t);
470
465
  }
471
- displayResults(e) {
472
- const t = document.getElementById("message-container");
473
- w(e.map((o) => o.Title)), e.forEach((o) => {
466
+ displayResults(t) {
467
+ const e = document.getElementById("message-container");
468
+ b(t.map((o) => o.Title)), t.forEach((o) => {
474
469
  const i = document.createElement("div");
475
470
  i.className = "wine-item";
476
471
  const s = document.createElement("img");
477
472
  s.src = o.Image, i.appendChild(s);
478
- const c = document.createElement("div");
479
- c.innerHTML = `
473
+ const d = document.createElement("div");
474
+ d.innerHTML = `
480
475
  <strong>${o.Title}</strong><br>
481
476
  ${a.translate("price")}: ${o.Price}<br>
482
477
  ${a.translate("region")}: ${o.Region}<br>
483
478
  ${a.translate("type")}: ${o.Type}<br>
484
479
  <a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${a.translate("moreInfo")}</a>
485
- `, i.appendChild(c), t.appendChild(i);
486
- }), t.scrollTop = t.scrollHeight;
480
+ `, i.appendChild(d), e.appendChild(i);
481
+ }), e.scrollTop = e.scrollHeight;
487
482
  }
488
483
  }
489
484
  const B = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
490
485
  document.addEventListener("DOMContentLoaded", () => {
491
- window.toggleChatWindow = u, window.closeChatWindow = v, window.openChatWindow = k;
486
+ window.toggleChatWindow = h, window.closeChatWindow = x, window.openChatWindow = v;
492
487
  });
493
- function L() {
488
+ function T() {
494
489
  const n = `
495
490
  <div id="chatbot-container">
496
491
  <div id="chat-icon" onclick="toggleChatWindow()">
@@ -520,32 +515,32 @@ function L() {
520
515
  `;
521
516
  document.body.insertAdjacentHTML("beforeend", n);
522
517
  }
523
- function P() {
524
- document.getElementById("close-btn").addEventListener("click", u);
518
+ function L() {
519
+ document.getElementById("close-btn").addEventListener("click", h);
525
520
  }
526
- function W() {
521
+ function P() {
527
522
  window.addEventListener("click", function(n) {
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");
523
+ const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
524
+ !t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
530
525
  });
531
526
  }
532
- function O(n) {
527
+ function W(n) {
533
528
  console.log(n);
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");
529
+ const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
530
+ 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");
536
531
  }
537
- var l;
532
+ var c;
538
533
  if (typeof window < "u") {
539
- const n = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
534
+ const n = ((c = window.wineaterData) == null ? void 0 : c.POSITION) || "bottom-right";
540
535
  window.addEventListener("DOMContentLoaded", async () => {
541
536
  var s;
542
- const t = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
537
+ const e = ["climats", "telckel", "biobio", "weinpoint"].find((d) => window.location.href.includes(d)) || null;
543
538
  let o;
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();
539
+ e && (o = e.charAt(0).toUpperCase() + e.slice(1)), await a.fetchConfig(o || null), T(), L(), P(), W(n), f("chatbotToken", ((s = window.wineaterData) == null ? void 0 : s.CLIENT_TOKEN) || B, 365), new I().initialize();
545
540
  });
546
541
  }
547
542
  export {
548
- v as closeChatWindow,
549
- k as openChatWindow,
550
- u as toggleChatWindow
543
+ x as closeChatWindow,
544
+ v as openChatWindow,
545
+ h as toggleChatWindow
551
546
  };
@@ -1,4 +1,4 @@
1
- (function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.WineaterChatbot={}))})(this,function(r){"use strict";var w;const d=`
1
+ (function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.WineaterChatbot={}))})(this,function(r){"use strict";var b;const d=`
2
2
  @font-face {
3
3
  font-family: 'Poppins';
4
4
  src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
@@ -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:t};fetch(o,{method:"POST",headers:{Authorization:"Basic "+btoa(`${e}:`)},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 w(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,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 h(){c("Chatbot Opened",{})}function u(){c("Chatbot Closed",{})}function x(n){c("Message Sent",{message_content:n})}function v(n){c("Message Sent",{products:n})}function k(n){c("Product Clicked",{product_id:n})}function p(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(u(),n.classList.remove("visible"),t.style.display="flex"):(h(),n.classList.add("visible"),t.style.display="none")}function m(){u(),document.getElementById("chat-window").classList.remove("visible")}function f(){h(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const C=["climats","telckel","biobio","weinpoint"],E="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;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}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 I{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 I;class T{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{x(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){k(t)}displayResults(t){const e=document.getElementById("message-container");v(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 l=document.createElement("div");l.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}}const L="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=f,window.openChatWindow=b});function W(){const n=`
282
+ `,i.appendChild(l),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}const B="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=p,window.closeChatWindow=m,window.openChatWindow=f});function L(){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 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"})});
308
+ `;document.body.insertAdjacentHTML("beforeend",n)}function W(){document.getElementById("close-btn").addEventListener("click",p)}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 O(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=((b=window.wineaterData)==null?void 0:b.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var a;const e=["climats","telckel","biobio","weinpoint"].find(l=>window.location.href.includes(l))||null;let o;e&&(o=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(o||null),L(),W(),P(),O(n),w("chatbotToken",((a=window.wineaterData)==null?void 0:a.CLIENT_TOKEN)||B,365),new T().initialize()})}r.closeChatWindow=m,r.openChatWindow=f,r.toggleChatWindow=p,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.4",
3
+ "version": "1.5.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
@@ -22,14 +22,14 @@ function setCookie(name, value, days) {
22
22
  const endpoint = 'https://api-eu.mixpanel.com/track';
23
23
  const data = {
24
24
  event: event,
25
- properties
25
+ properties: {
26
+ token: token,
27
+ ...properties
28
+ }
26
29
  };
27
30
 
28
31
  fetch(endpoint, {
29
32
  method: 'POST',
30
- headers: {
31
- 'Authorization': 'Basic ' + btoa(`${token}:`)
32
- },
33
33
  body: JSON.stringify(data)
34
34
  }).then(response => {
35
35
  if (!response.ok) {
@@ -41,23 +41,23 @@ function setCookie(name, value, days) {
41
41
  }
42
42
 
43
43
  function trackChatbotOpen() {
44
- trackEvent('Chatbot Opened', { distinct_id: getCookie('chatbotToken') });
44
+ trackEvent('Chatbot Opened', {});
45
45
  }
46
46
 
47
47
  function trackChatbotClose() {
48
- trackEvent('Chatbot Closed', { distinct_id: getCookie('chatbotToken') });
48
+ trackEvent('Chatbot Closed', {});
49
49
  }
50
50
 
51
51
  function trackMessageSent(message) {
52
- trackEvent('Message Sent', { distinct_id: getCookie('chatbotToken'), message_content: message });
52
+ trackEvent('Message Sent', { message_content: message });
53
53
  }
54
54
 
55
55
  function trackRecommendationsGet(products) {
56
- trackEvent('Message Sent', { distinct_id: getCookie('chatbotToken'), products: products });
56
+ trackEvent('Message Sent', { products: products });
57
57
  }
58
58
 
59
59
  function trackProductClick(productId) {
60
- trackEvent('Product Clicked', { distinct_id: getCookie('chatbotToken'), product_id: productId });
60
+ trackEvent('Product Clicked', { product_id: productId });
61
61
  }
62
62
 
63
63
  export { setCookie, getCookie, trackChatbotOpen, trackMessageSent, trackProductClick, trackChatbotClose, trackRecommendationsGet };