wineater-bot 1.5.6 → 1.5.8

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