wineater-bot 1.5.11 → 1.5.13
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.
- package/dist/wineater-chatbot.mjs +52 -49
- package/dist/wineater-chatbot.umd.js +1 -1
- package/package.json +1 -1
- package/src/js/analytics.js +5 -2
- package/src/js/i18n.js +1 -1
|
@@ -280,30 +280,33 @@ const f = `
|
|
|
280
280
|
}`, p = document.createElement("style");
|
|
281
281
|
p.textContent = f;
|
|
282
282
|
document.head.appendChild(p);
|
|
283
|
-
function b(
|
|
284
|
-
let
|
|
283
|
+
function b(n, t, e) {
|
|
284
|
+
let o = "";
|
|
285
285
|
if (e) {
|
|
286
286
|
const i = /* @__PURE__ */ new Date();
|
|
287
|
-
i.setTime(i.getTime() + e * 24 * 60 * 60 * 1e3),
|
|
287
|
+
i.setTime(i.getTime() + e * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
|
|
288
288
|
}
|
|
289
|
-
document.cookie =
|
|
289
|
+
document.cookie = n + "=" + (t || "") + o + "; path=/; secure; samesite=strict";
|
|
290
290
|
}
|
|
291
|
-
function r(
|
|
292
|
-
const e = `; ${document.cookie}`.split(`; ${
|
|
291
|
+
function r(n) {
|
|
292
|
+
const e = `; ${document.cookie}`.split(`; ${n}=`);
|
|
293
293
|
if (e.length === 2)
|
|
294
294
|
return e.pop().split(";").shift();
|
|
295
295
|
}
|
|
296
|
-
function d(
|
|
297
|
-
const e = "6f3d90d5b02720f58de3663e3ef675fe",
|
|
298
|
-
event:
|
|
296
|
+
function d(n, t) {
|
|
297
|
+
const e = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api.mixpanel.com/track", i = [{
|
|
298
|
+
event: n,
|
|
299
299
|
properties: {
|
|
300
300
|
token: e,
|
|
301
301
|
...t
|
|
302
302
|
}
|
|
303
303
|
}];
|
|
304
|
-
fetch(
|
|
304
|
+
fetch(o, {
|
|
305
305
|
method: "POST",
|
|
306
|
-
|
|
306
|
+
headers: {
|
|
307
|
+
"access-control-allow-origin": "*"
|
|
308
|
+
},
|
|
309
|
+
body: JSON.stringify(i)
|
|
307
310
|
}).then((s) => {
|
|
308
311
|
s.ok || console.error("Mixpanel tracking failed", s);
|
|
309
312
|
}).catch((s) => {
|
|
@@ -316,18 +319,18 @@ function h() {
|
|
|
316
319
|
function g() {
|
|
317
320
|
d("Chatbot Closed", { distinct_id: r("chatbotToken") });
|
|
318
321
|
}
|
|
319
|
-
function y(
|
|
320
|
-
d("Message Sent", { distinct_id: r("chatbotToken"), message_content:
|
|
322
|
+
function y(n) {
|
|
323
|
+
d("Message Sent", { distinct_id: r("chatbotToken"), message_content: n });
|
|
321
324
|
}
|
|
322
|
-
function w(
|
|
323
|
-
d("Message Sent", { distinct_id: r("chatbotToken"), products:
|
|
325
|
+
function w(n) {
|
|
326
|
+
d("Message Sent", { distinct_id: r("chatbotToken"), products: n });
|
|
324
327
|
}
|
|
325
|
-
function x(
|
|
326
|
-
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id:
|
|
328
|
+
function x(n) {
|
|
329
|
+
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id: n });
|
|
327
330
|
}
|
|
328
331
|
function u() {
|
|
329
|
-
const
|
|
330
|
-
|
|
332
|
+
const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
333
|
+
n.classList.contains("visible") ? (g(), n.classList.remove("visible"), t.style.display = "flex") : (h(), n.classList.add("visible"), t.style.display = "none");
|
|
331
334
|
}
|
|
332
335
|
function v() {
|
|
333
336
|
g(), document.getElementById("chat-window").classList.remove("visible");
|
|
@@ -342,7 +345,7 @@ const E = ["climats", "telckel", "biobio", "weinpoint"], I = "OuhXJRleF6sROjsQZP
|
|
|
342
345
|
class m {
|
|
343
346
|
constructor(t) {
|
|
344
347
|
var e;
|
|
345
|
-
this.baseURL = "https://api.wineater.com/", this.store = E.find((
|
|
348
|
+
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;
|
|
346
349
|
}
|
|
347
350
|
async getStoreConfig(t) {
|
|
348
351
|
console.log(t);
|
|
@@ -372,10 +375,10 @@ class m {
|
|
|
372
375
|
Authorization: `Bearer ${this.token}`
|
|
373
376
|
},
|
|
374
377
|
body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
|
|
375
|
-
}),
|
|
378
|
+
}), o = await e.json();
|
|
376
379
|
if (!e.ok)
|
|
377
|
-
throw new Error(`API call failed with status ${e.status}: ${
|
|
378
|
-
return
|
|
380
|
+
throw new Error(`API call failed with status ${e.status}: ${o.message || "No additional error information"}`);
|
|
381
|
+
return o;
|
|
379
382
|
} catch (e) {
|
|
380
383
|
throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
|
|
381
384
|
}
|
|
@@ -446,7 +449,7 @@ class C {
|
|
|
446
449
|
}
|
|
447
450
|
};
|
|
448
451
|
}
|
|
449
|
-
async fetchConfig(t) {
|
|
452
|
+
async fetchConfig(t = "Demo") {
|
|
450
453
|
if (t) {
|
|
451
454
|
const e = await this.api.getStoreConfig(t);
|
|
452
455
|
this.language = e.lang;
|
|
@@ -462,13 +465,13 @@ class T {
|
|
|
462
465
|
this.api = new m(), this.displayFirstMessage(a.translate("welcomeMessage"));
|
|
463
466
|
}
|
|
464
467
|
initialize() {
|
|
465
|
-
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (
|
|
466
|
-
|
|
468
|
+
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (o) => {
|
|
469
|
+
o.key === "Enter" && this.handleUserInput();
|
|
467
470
|
});
|
|
468
471
|
}
|
|
469
472
|
displayFirstMessage(t, e = "api") {
|
|
470
|
-
const
|
|
471
|
-
i.className = `message ${e}`, i.textContent = t,
|
|
473
|
+
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
474
|
+
i.className = `message ${e}`, i.textContent = t, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
472
475
|
}
|
|
473
476
|
async handleUserInput() {
|
|
474
477
|
const t = document.getElementById("user-input"), e = t.value.trim();
|
|
@@ -476,8 +479,8 @@ class T {
|
|
|
476
479
|
this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
|
|
477
480
|
try {
|
|
478
481
|
y(e);
|
|
479
|
-
const
|
|
480
|
-
this.hideTypingIndicator(),
|
|
482
|
+
const o = await this.api.getWineRecommendations(e);
|
|
483
|
+
this.hideTypingIndicator(), o && o.length ? this.displayResults(o) : this.displayMessage("No results found.", "api");
|
|
481
484
|
} catch {
|
|
482
485
|
this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
|
|
483
486
|
}
|
|
@@ -490,26 +493,26 @@ class T {
|
|
|
490
493
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
491
494
|
}
|
|
492
495
|
displayMessage(t, e) {
|
|
493
|
-
const
|
|
494
|
-
i.textContent = t, i.className = "message " + e,
|
|
496
|
+
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
497
|
+
i.textContent = t, i.className = "message " + e, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
495
498
|
}
|
|
496
499
|
sendAnalytics(t) {
|
|
497
500
|
x(t);
|
|
498
501
|
}
|
|
499
502
|
displayResults(t) {
|
|
500
503
|
const e = document.getElementById("message-container");
|
|
501
|
-
w(t.map((
|
|
504
|
+
w(t.map((o) => o.Title)), t.forEach((o) => {
|
|
502
505
|
const i = document.createElement("div");
|
|
503
506
|
i.className = "wine-item";
|
|
504
507
|
const s = document.createElement("img");
|
|
505
|
-
s.src =
|
|
508
|
+
s.src = o.Image, i.appendChild(s);
|
|
506
509
|
const c = document.createElement("div");
|
|
507
510
|
c.innerHTML = `
|
|
508
|
-
<strong>${
|
|
509
|
-
${a.translate("price")}: ${
|
|
510
|
-
${a.translate("region")}: ${
|
|
511
|
-
${a.translate("type")}: ${
|
|
512
|
-
<a href="${
|
|
511
|
+
<strong>${o.Title}</strong><br>
|
|
512
|
+
${a.translate("price")}: ${o.Price}<br>
|
|
513
|
+
${a.translate("region")}: ${o.Region}<br>
|
|
514
|
+
${a.translate("type")}: ${o.Type}<br>
|
|
515
|
+
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
513
516
|
`, i.appendChild(c), e.appendChild(i);
|
|
514
517
|
}), e.scrollTop = e.scrollHeight;
|
|
515
518
|
}
|
|
@@ -519,7 +522,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
519
522
|
window.toggleChatWindow = u, window.closeChatWindow = v, window.openChatWindow = k;
|
|
520
523
|
});
|
|
521
524
|
function W() {
|
|
522
|
-
const
|
|
525
|
+
const n = `
|
|
523
526
|
<div id="chatbot-container">
|
|
524
527
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
525
528
|
<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 -->
|
|
@@ -546,30 +549,30 @@ function W() {
|
|
|
546
549
|
</div>
|
|
547
550
|
</div>
|
|
548
551
|
`;
|
|
549
|
-
document.body.insertAdjacentHTML("beforeend",
|
|
552
|
+
document.body.insertAdjacentHTML("beforeend", n);
|
|
550
553
|
}
|
|
551
554
|
function P() {
|
|
552
555
|
document.getElementById("close-btn").addEventListener("click", u);
|
|
553
556
|
}
|
|
554
557
|
function L() {
|
|
555
|
-
window.addEventListener("click", function(
|
|
558
|
+
window.addEventListener("click", function(n) {
|
|
556
559
|
const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
557
|
-
!t.contains(
|
|
560
|
+
!t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
|
|
558
561
|
});
|
|
559
562
|
}
|
|
560
|
-
function S(
|
|
561
|
-
console.log(
|
|
563
|
+
function S(n) {
|
|
564
|
+
console.log(n);
|
|
562
565
|
const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
|
|
563
|
-
t.className = "", e.className = "",
|
|
566
|
+
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");
|
|
564
567
|
}
|
|
565
568
|
var l;
|
|
566
569
|
if (typeof window < "u") {
|
|
567
|
-
const
|
|
570
|
+
const n = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
568
571
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
569
572
|
var s;
|
|
570
573
|
const e = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
|
|
571
|
-
let
|
|
572
|
-
e && (
|
|
574
|
+
let o;
|
|
575
|
+
e && (o = e.charAt(0).toUpperCase() + e.slice(1)), await a.fetchConfig(o || null), W(), P(), L(), S(n), b("chatbotToken", ((s = window.wineaterData) == null ? void 0 : s.CLIENT_TOKEN) || B, 365), new T().initialize();
|
|
573
576
|
});
|
|
574
577
|
}
|
|
575
578
|
export {
|
|
@@ -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",body: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",headers:{"access-control-allow-origin":"*"},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
package/src/js/analytics.js
CHANGED
|
@@ -23,14 +23,17 @@ function setCookie(name, value, days) {
|
|
|
23
23
|
const data = [{
|
|
24
24
|
event,
|
|
25
25
|
properties: {
|
|
26
|
-
token
|
|
26
|
+
token,
|
|
27
27
|
...properties
|
|
28
28
|
}
|
|
29
29
|
}];
|
|
30
30
|
|
|
31
31
|
fetch(endpoint, {
|
|
32
32
|
method: 'POST',
|
|
33
|
-
|
|
33
|
+
headers: {
|
|
34
|
+
'access-control-allow-origin': '*'
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify(data)
|
|
34
37
|
}).then(response => {
|
|
35
38
|
if (!response.ok) {
|
|
36
39
|
console.error('Mixpanel tracking failed', response);
|