wineater-bot 1.5.8 → 1.5.10
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 +131 -99
- package/dist/wineater-chatbot.umd.js +12 -8
- package/package.json +1 -1
- package/src/js/analytics.js +1 -1
- package/src/js/i18n.js +25 -1
- package/src/js/styles.js +4 -0
|
@@ -190,6 +190,10 @@ const f = `
|
|
|
190
190
|
background: white; /* White background for wine items */
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
.wine-item a {
|
|
194
|
+
color: #7E27ED;
|
|
195
|
+
}
|
|
196
|
+
|
|
193
197
|
.wine-item img {
|
|
194
198
|
width: 80px; /* Smaller wine image size */
|
|
195
199
|
height: auto;
|
|
@@ -276,29 +280,33 @@ const f = `
|
|
|
276
280
|
}`, p = document.createElement("style");
|
|
277
281
|
p.textContent = f;
|
|
278
282
|
document.head.appendChild(p);
|
|
279
|
-
function b(
|
|
280
|
-
let
|
|
281
|
-
if (
|
|
283
|
+
function b(o, t, e) {
|
|
284
|
+
let n = "";
|
|
285
|
+
if (e) {
|
|
282
286
|
const i = /* @__PURE__ */ new Date();
|
|
283
|
-
i.setTime(i.getTime() +
|
|
287
|
+
i.setTime(i.getTime() + e * 24 * 60 * 60 * 1e3), n = "; expires=" + i.toUTCString();
|
|
284
288
|
}
|
|
285
|
-
document.cookie =
|
|
289
|
+
document.cookie = o + "=" + (t || "") + n + "; path=/; secure; samesite=strict";
|
|
286
290
|
}
|
|
287
|
-
function r(
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
return
|
|
291
|
+
function r(o) {
|
|
292
|
+
const e = `; ${document.cookie}`.split(`; ${o}=`);
|
|
293
|
+
if (e.length === 2)
|
|
294
|
+
return e.pop().split(";").shift();
|
|
291
295
|
}
|
|
292
|
-
function d(
|
|
293
|
-
const
|
|
294
|
-
event:
|
|
296
|
+
function d(o, t) {
|
|
297
|
+
const e = "6f3d90d5b02720f58de3663e3ef675fe", n = "https://api.mixpanel.com/track", i = [{
|
|
298
|
+
event: o,
|
|
295
299
|
properties: {
|
|
296
|
-
token:
|
|
297
|
-
...
|
|
300
|
+
token: e,
|
|
301
|
+
...t
|
|
298
302
|
}
|
|
299
303
|
}];
|
|
300
|
-
fetch(
|
|
304
|
+
fetch(n, {
|
|
301
305
|
method: "POST",
|
|
306
|
+
headers: {
|
|
307
|
+
accept: "text/plain",
|
|
308
|
+
"content-type": "application/json"
|
|
309
|
+
},
|
|
302
310
|
body: JSON.stringify(i)
|
|
303
311
|
}).then((s) => {
|
|
304
312
|
s.ok || console.error("Mixpanel tracking failed", s);
|
|
@@ -306,78 +314,78 @@ function d(n, e) {
|
|
|
306
314
|
console.error("Mixpanel tracking error", s);
|
|
307
315
|
});
|
|
308
316
|
}
|
|
309
|
-
function
|
|
317
|
+
function h() {
|
|
310
318
|
d("Chatbot Opened", { distinct_id: r("chatbotToken") });
|
|
311
319
|
}
|
|
312
|
-
function
|
|
320
|
+
function g() {
|
|
313
321
|
d("Chatbot Closed", { distinct_id: r("chatbotToken") });
|
|
314
322
|
}
|
|
315
|
-
function y(
|
|
316
|
-
d("Message Sent", { distinct_id: r("chatbotToken"), message_content:
|
|
323
|
+
function y(o) {
|
|
324
|
+
d("Message Sent", { distinct_id: r("chatbotToken"), message_content: o });
|
|
317
325
|
}
|
|
318
|
-
function w(
|
|
319
|
-
d("Message Sent", { distinct_id: r("chatbotToken"), products:
|
|
326
|
+
function w(o) {
|
|
327
|
+
d("Message Sent", { distinct_id: r("chatbotToken"), products: o });
|
|
320
328
|
}
|
|
321
|
-
function x(
|
|
322
|
-
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id:
|
|
329
|
+
function x(o) {
|
|
330
|
+
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id: o });
|
|
323
331
|
}
|
|
324
332
|
function u() {
|
|
325
|
-
const
|
|
326
|
-
|
|
333
|
+
const o = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
334
|
+
o.classList.contains("visible") ? (g(), o.classList.remove("visible"), t.style.display = "flex") : (h(), o.classList.add("visible"), t.style.display = "none");
|
|
327
335
|
}
|
|
328
336
|
function v() {
|
|
329
|
-
|
|
337
|
+
g(), document.getElementById("chat-window").classList.remove("visible");
|
|
330
338
|
}
|
|
331
339
|
function k() {
|
|
332
|
-
|
|
340
|
+
h(), document.getElementById("chat-window").classList.add("visible");
|
|
333
341
|
}
|
|
334
342
|
document.addEventListener("DOMContentLoaded", () => {
|
|
335
343
|
setupCloseButton(), setupOutsideClick();
|
|
336
344
|
});
|
|
337
|
-
const
|
|
345
|
+
const E = ["climats", "telckel", "biobio", "weinpoint"], I = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
338
346
|
class m {
|
|
339
|
-
constructor(
|
|
340
|
-
var
|
|
341
|
-
this.baseURL = "https://api.wineater.com/", this.store =
|
|
347
|
+
constructor(t) {
|
|
348
|
+
var e;
|
|
349
|
+
this.baseURL = "https://api.wineater.com/", this.store = E.find((n) => window.location.href.includes(n)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || I;
|
|
342
350
|
}
|
|
343
|
-
async getStoreConfig(
|
|
344
|
-
console.log(
|
|
351
|
+
async getStoreConfig(t) {
|
|
352
|
+
console.log(t);
|
|
345
353
|
try {
|
|
346
|
-
const
|
|
354
|
+
const e = await fetch(`${this.baseURL}stores/store`, {
|
|
347
355
|
method: "POST",
|
|
348
356
|
headers: {
|
|
349
357
|
"Content-Type": "application/json",
|
|
350
358
|
Authorization: `Bearer ${this.token}`
|
|
351
359
|
},
|
|
352
|
-
body: JSON.stringify({ store:
|
|
360
|
+
body: JSON.stringify({ store: t })
|
|
353
361
|
});
|
|
354
|
-
if (!
|
|
355
|
-
throw new Error(`HTTP error! Status: ${
|
|
356
|
-
return await
|
|
357
|
-
} catch (
|
|
358
|
-
throw console.error("Error fetching store configuration:",
|
|
362
|
+
if (!e.ok)
|
|
363
|
+
throw new Error(`HTTP error! Status: ${e.status}`);
|
|
364
|
+
return await e.json();
|
|
365
|
+
} catch (e) {
|
|
366
|
+
throw console.error("Error fetching store configuration:", e), e;
|
|
359
367
|
}
|
|
360
368
|
}
|
|
361
|
-
async getWineRecommendations(
|
|
369
|
+
async getWineRecommendations(t) {
|
|
362
370
|
console.log(window.location.href);
|
|
363
371
|
try {
|
|
364
|
-
const
|
|
372
|
+
const e = await fetch(`${this.baseURL}dish/recommendations`, {
|
|
365
373
|
method: "POST",
|
|
366
374
|
headers: {
|
|
367
375
|
"Content-Type": "application/json",
|
|
368
376
|
Authorization: `Bearer ${this.token}`
|
|
369
377
|
},
|
|
370
|
-
body: JSON.stringify({ text:
|
|
371
|
-
}),
|
|
372
|
-
if (!
|
|
373
|
-
throw new Error(`API call failed with status ${
|
|
374
|
-
return
|
|
375
|
-
} catch (
|
|
376
|
-
throw console.error("Fetching wine recommendations failed:",
|
|
378
|
+
body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
|
|
379
|
+
}), n = await e.json();
|
|
380
|
+
if (!e.ok)
|
|
381
|
+
throw new Error(`API call failed with status ${e.status}: ${n.message || "No additional error information"}`);
|
|
382
|
+
return n;
|
|
383
|
+
} catch (e) {
|
|
384
|
+
throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
|
|
377
385
|
}
|
|
378
386
|
}
|
|
379
387
|
}
|
|
380
|
-
class
|
|
388
|
+
class C {
|
|
381
389
|
constructor() {
|
|
382
390
|
this.api = new m(), this.language = "en", this.translations = {
|
|
383
391
|
fr: {
|
|
@@ -392,6 +400,18 @@ class I {
|
|
|
392
400
|
type: "Type",
|
|
393
401
|
moreInfo: "Plus d'infos"
|
|
394
402
|
},
|
|
403
|
+
de: {
|
|
404
|
+
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?",
|
|
405
|
+
noResultsFound: "Aucun résultat trouvé.",
|
|
406
|
+
somethingWentWrong: "Désolé, quelque chose a mal tourné.",
|
|
407
|
+
chatButton: "Accorder le vin au dîner",
|
|
408
|
+
inputPlaceholder: "ex., Salade de thon",
|
|
409
|
+
sendButton: "Accorder",
|
|
410
|
+
price: "Prix",
|
|
411
|
+
region: "Région",
|
|
412
|
+
type: "Type",
|
|
413
|
+
moreInfo: "Plus d'infos"
|
|
414
|
+
},
|
|
395
415
|
es: {
|
|
396
416
|
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?",
|
|
397
417
|
noResultsFound: "No se encontraron resultados.",
|
|
@@ -415,41 +435,53 @@ class I {
|
|
|
415
435
|
region: "Region",
|
|
416
436
|
type: "Type",
|
|
417
437
|
moreInfo: "More info"
|
|
438
|
+
},
|
|
439
|
+
de: {
|
|
440
|
+
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?",
|
|
441
|
+
noResultsFound: "Keine Ergebnisse gefunden.",
|
|
442
|
+
somethingWentWrong: "Entschuldigung, etwas ist schief gelaufen.",
|
|
443
|
+
chatButton: "Wein zum Abendessen kombinieren",
|
|
444
|
+
inputPlaceholder: "z.B., Thunfischsalat",
|
|
445
|
+
sendButton: "Kombinieren",
|
|
446
|
+
price: "Preis",
|
|
447
|
+
region: "Region",
|
|
448
|
+
type: "Typ",
|
|
449
|
+
moreInfo: "Mehr Info"
|
|
418
450
|
}
|
|
419
451
|
};
|
|
420
452
|
}
|
|
421
|
-
async fetchConfig(
|
|
422
|
-
if (
|
|
423
|
-
const
|
|
424
|
-
this.language =
|
|
453
|
+
async fetchConfig(t) {
|
|
454
|
+
if (t) {
|
|
455
|
+
const e = await this.api.getStoreConfig(t);
|
|
456
|
+
this.language = e.lang;
|
|
425
457
|
}
|
|
426
458
|
}
|
|
427
|
-
translate(
|
|
428
|
-
return this.translations[this.language][
|
|
459
|
+
translate(t) {
|
|
460
|
+
return this.translations[this.language][t] || t;
|
|
429
461
|
}
|
|
430
462
|
}
|
|
431
|
-
const a = new
|
|
463
|
+
const a = new C();
|
|
432
464
|
class T {
|
|
433
465
|
constructor() {
|
|
434
466
|
this.api = new m(), this.displayFirstMessage(a.translate("welcomeMessage"));
|
|
435
467
|
}
|
|
436
468
|
initialize() {
|
|
437
|
-
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (
|
|
438
|
-
|
|
469
|
+
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (n) => {
|
|
470
|
+
n.key === "Enter" && this.handleUserInput();
|
|
439
471
|
});
|
|
440
472
|
}
|
|
441
|
-
displayFirstMessage(
|
|
442
|
-
const
|
|
443
|
-
i.className = `message ${
|
|
473
|
+
displayFirstMessage(t, e = "api") {
|
|
474
|
+
const n = document.getElementById("message-container"), i = document.createElement("div");
|
|
475
|
+
i.className = `message ${e}`, i.textContent = t, n.appendChild(i), n.scrollTop = n.scrollHeight;
|
|
444
476
|
}
|
|
445
477
|
async handleUserInput() {
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
448
|
-
this.displayMessage(
|
|
478
|
+
const t = document.getElementById("user-input"), e = t.value.trim();
|
|
479
|
+
if (e) {
|
|
480
|
+
this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
|
|
449
481
|
try {
|
|
450
|
-
y(
|
|
451
|
-
const
|
|
452
|
-
this.hideTypingIndicator(),
|
|
482
|
+
y(e);
|
|
483
|
+
const n = await this.api.getWineRecommendations(e);
|
|
484
|
+
this.hideTypingIndicator(), n && n.length ? this.displayResults(n) : this.displayMessage("No results found.", "api");
|
|
453
485
|
} catch {
|
|
454
486
|
this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
|
|
455
487
|
}
|
|
@@ -461,37 +493,37 @@ class T {
|
|
|
461
493
|
hideTypingIndicator() {
|
|
462
494
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
463
495
|
}
|
|
464
|
-
displayMessage(
|
|
465
|
-
const
|
|
466
|
-
i.textContent =
|
|
496
|
+
displayMessage(t, e) {
|
|
497
|
+
const n = document.getElementById("message-container"), i = document.createElement("div");
|
|
498
|
+
i.textContent = t, i.className = "message " + e, n.appendChild(i), n.scrollTop = n.scrollHeight;
|
|
467
499
|
}
|
|
468
|
-
sendAnalytics(
|
|
469
|
-
x(
|
|
500
|
+
sendAnalytics(t) {
|
|
501
|
+
x(t);
|
|
470
502
|
}
|
|
471
|
-
displayResults(
|
|
472
|
-
const
|
|
473
|
-
w(
|
|
503
|
+
displayResults(t) {
|
|
504
|
+
const e = document.getElementById("message-container");
|
|
505
|
+
w(t.map((n) => n.Title)), t.forEach((n) => {
|
|
474
506
|
const i = document.createElement("div");
|
|
475
507
|
i.className = "wine-item";
|
|
476
508
|
const s = document.createElement("img");
|
|
477
|
-
s.src =
|
|
509
|
+
s.src = n.Image, i.appendChild(s);
|
|
478
510
|
const c = document.createElement("div");
|
|
479
511
|
c.innerHTML = `
|
|
480
|
-
<strong>${
|
|
481
|
-
${a.translate("price")}: ${
|
|
482
|
-
${a.translate("region")}: ${
|
|
483
|
-
${a.translate("type")}: ${
|
|
484
|
-
<a href="${
|
|
485
|
-
`, i.appendChild(c),
|
|
486
|
-
}),
|
|
512
|
+
<strong>${n.Title}</strong><br>
|
|
513
|
+
${a.translate("price")}: ${n.Price}<br>
|
|
514
|
+
${a.translate("region")}: ${n.Region}<br>
|
|
515
|
+
${a.translate("type")}: ${n.Type}<br>
|
|
516
|
+
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
517
|
+
`, i.appendChild(c), e.appendChild(i);
|
|
518
|
+
}), e.scrollTop = e.scrollHeight;
|
|
487
519
|
}
|
|
488
520
|
}
|
|
489
521
|
const B = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
490
522
|
document.addEventListener("DOMContentLoaded", () => {
|
|
491
523
|
window.toggleChatWindow = u, window.closeChatWindow = v, window.openChatWindow = k;
|
|
492
524
|
});
|
|
493
|
-
function
|
|
494
|
-
const
|
|
525
|
+
function W() {
|
|
526
|
+
const o = `
|
|
495
527
|
<div id="chatbot-container">
|
|
496
528
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
497
529
|
<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 -->
|
|
@@ -518,30 +550,30 @@ function L() {
|
|
|
518
550
|
</div>
|
|
519
551
|
</div>
|
|
520
552
|
`;
|
|
521
|
-
document.body.insertAdjacentHTML("beforeend",
|
|
553
|
+
document.body.insertAdjacentHTML("beforeend", o);
|
|
522
554
|
}
|
|
523
555
|
function P() {
|
|
524
556
|
document.getElementById("close-btn").addEventListener("click", u);
|
|
525
557
|
}
|
|
526
|
-
function
|
|
527
|
-
window.addEventListener("click", function(
|
|
528
|
-
const
|
|
529
|
-
!
|
|
558
|
+
function L() {
|
|
559
|
+
window.addEventListener("click", function(o) {
|
|
560
|
+
const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
561
|
+
!t.contains(o.target) && !e.contains(o.target) && (t.classList.remove("visible"), e.style.display = "flex");
|
|
530
562
|
});
|
|
531
563
|
}
|
|
532
|
-
function
|
|
533
|
-
console.log(
|
|
534
|
-
const
|
|
535
|
-
|
|
564
|
+
function S(o) {
|
|
565
|
+
console.log(o);
|
|
566
|
+
const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
|
|
567
|
+
t.className = "", e.className = "", o === "right-center" ? (t.classList.add("chat-icon-right-center"), e.classList.add("right-center-aligned")) : t.classList.add("chat-icon-bottom-right");
|
|
536
568
|
}
|
|
537
569
|
var l;
|
|
538
570
|
if (typeof window < "u") {
|
|
539
|
-
const
|
|
571
|
+
const o = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
540
572
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
541
573
|
var s;
|
|
542
|
-
const
|
|
543
|
-
let
|
|
544
|
-
|
|
574
|
+
const e = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
|
|
575
|
+
let n;
|
|
576
|
+
e && (n = e.charAt(0).toUpperCase() + e.slice(1)), await a.fetchConfig(n || null), W(), P(), L(), S(o), b("chatbotToken", ((s = window.wineaterData) == null ? void 0 : s.CLIENT_TOKEN) || B, 365), new T().initialize();
|
|
545
577
|
});
|
|
546
578
|
}
|
|
547
579
|
export {
|
|
@@ -190,6 +190,10 @@
|
|
|
190
190
|
background: white; /* White background for wine items */
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
.wine-item a {
|
|
194
|
+
color: #7E27ED;
|
|
195
|
+
}
|
|
196
|
+
|
|
193
197
|
.wine-item img {
|
|
194
198
|
width: 80px; /* Smaller wine image size */
|
|
195
199
|
height: auto;
|
|
@@ -273,13 +277,13 @@
|
|
|
273
277
|
.typing-indicator.visible {
|
|
274
278
|
visibility: visible;
|
|
275
279
|
height: 50px;
|
|
276
|
-
}`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function x(
|
|
277
|
-
<strong>${
|
|
278
|
-
${s.translate("price")}: ${
|
|
279
|
-
${s.translate("region")}: ${
|
|
280
|
-
${s.translate("type")}: ${
|
|
281
|
-
<a href="${
|
|
282
|
-
`,i.appendChild(p),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}const
|
|
280
|
+
}`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function x(o,t,e){let n="";if(e){const i=new Date;i.setTime(i.getTime()+e*24*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=o+"="+(t||"")+n+"; path=/; secure; samesite=strict"}function c(o){const e=`; ${document.cookie}`.split(`; ${o}=`);if(e.length===2)return e.pop().split(";").shift()}function l(o,t){const e="6f3d90d5b02720f58de3663e3ef675fe",n="https://api.mixpanel.com/track",i=[{event:o,properties:{token:e,...t}}];fetch(n,{method:"POST",headers:{accept:"text/plain","content-type":"application/json"},body:JSON.stringify(i)}).then(a=>{a.ok||console.error("Mixpanel tracking failed",a)}).catch(a=>{console.error("Mixpanel tracking error",a)})}function u(){l("Chatbot Opened",{distinct_id:c("chatbotToken")})}function m(){l("Chatbot Closed",{distinct_id:c("chatbotToken")})}function v(o){l("Message Sent",{distinct_id:c("chatbotToken"),message_content:o})}function k(o){l("Message Sent",{distinct_id:c("chatbotToken"),products:o})}function E(o){l("Product Clicked",{distinct_id:c("chatbotToken"),product_id:o})}function h(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(m(),o.classList.remove("visible"),t.style.display="flex"):(u(),o.classList.add("visible"),t.style.display="none")}function f(){m(),document.getElementById("chat-window").classList.remove("visible")}function b(){u(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const C=["climats","telckel","biobio","weinpoint"],I="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=C.find(n=>window.location.href.includes(n)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||I}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),n=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${n.message||"No additional error information"}`);return n}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class T{constructor(){this.api=new y,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},de:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"},de:{welcomeMessage:"Verbessern Sie Ihr kulinarisches Erlebnis. Geben Sie einfach die Details Ihres Gerichts an und erhalten Sie die ideale Weinempfehlung. Was möchten Sie essen?",noResultsFound:"Keine Ergebnisse gefunden.",somethingWentWrong:"Entschuldigung, etwas ist schief gelaufen.",chatButton:"Wein zum Abendessen kombinieren",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",moreInfo:"Mehr Info"}}}async fetchConfig(t){if(t){const e=await this.api.getStoreConfig(t);this.language=e.lang}}translate(t){return this.translations[this.language][t]||t}}const s=new T;class W{constructor(){this.api=new y,this.displayFirstMessage(s.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",n=>{n.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const n=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,n.appendChild(i),n.scrollTop=n.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{v(e);const n=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),n&&n.length?this.displayResults(n):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(s.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const n=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,n.appendChild(i),n.scrollTop=n.scrollHeight}sendAnalytics(t){E(t)}displayResults(t){const e=document.getElementById("message-container");k(t.map(n=>n.Title)),t.forEach(n=>{const i=document.createElement("div");i.className="wine-item";const a=document.createElement("img");a.src=n.Image,i.appendChild(a);const p=document.createElement("div");p.innerHTML=`
|
|
281
|
+
<strong>${n.Title}</strong><br>
|
|
282
|
+
${s.translate("price")}: ${n.Price}<br>
|
|
283
|
+
${s.translate("region")}: ${n.Region}<br>
|
|
284
|
+
${s.translate("type")}: ${n.Type}<br>
|
|
285
|
+
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${s.translate("moreInfo")}</a>
|
|
286
|
+
`,i.appendChild(p),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}const B="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=f,window.openChatWindow=b});function P(){const o=`
|
|
283
287
|
<div id="chatbot-container">
|
|
284
288
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
285
289
|
<img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon"> <!-- Update the path to your logo image -->
|
|
@@ -305,4 +309,4 @@
|
|
|
305
309
|
</div>
|
|
306
310
|
</div>
|
|
307
311
|
</div>
|
|
308
|
-
`;document.body.insertAdjacentHTML("beforeend",
|
|
312
|
+
`;document.body.insertAdjacentHTML("beforeend",o)}function L(){document.getElementById("close-btn").addEventListener("click",h)}function S(){window.addEventListener("click",function(o){const t=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!t.contains(o.target)&&!e.contains(o.target)&&(t.classList.remove("visible"),e.style.display="flex")})}function O(o){console.log(o);const t=document.getElementById("chat-icon"),e=document.getElementById("chat-window");t.className="",e.className="",o==="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 o=((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 n;e&&(n=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(n||null),P(),L(),S(),O(o),x("chatbotToken",((a=window.wineaterData)==null?void 0:a.CLIENT_TOKEN)||B,365),new W().initialize()})}r.closeChatWindow=f,r.openChatWindow=b,r.toggleChatWindow=h,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/js/analytics.js
CHANGED
|
@@ -21,7 +21,7 @@ function setCookie(name, value, days) {
|
|
|
21
21
|
const token = '6f3d90d5b02720f58de3663e3ef675fe'; // Замените на ваш Mixpanel токен
|
|
22
22
|
const endpoint = 'https://api.mixpanel.com/track';
|
|
23
23
|
const data = [{
|
|
24
|
-
event
|
|
24
|
+
event,
|
|
25
25
|
properties: {
|
|
26
26
|
token: token,
|
|
27
27
|
...properties
|
package/src/js/i18n.js
CHANGED
|
@@ -17,6 +17,18 @@ class Translator {
|
|
|
17
17
|
type: "Type",
|
|
18
18
|
moreInfo: "Plus d'infos"
|
|
19
19
|
},
|
|
20
|
+
de: {
|
|
21
|
+
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?",
|
|
22
|
+
noResultsFound: "Aucun résultat trouvé.",
|
|
23
|
+
somethingWentWrong: "Désolé, quelque chose a mal tourné.",
|
|
24
|
+
chatButton: "Accorder le vin au dîner",
|
|
25
|
+
inputPlaceholder: "ex., Salade de thon",
|
|
26
|
+
sendButton: "Accorder",
|
|
27
|
+
price: "Prix",
|
|
28
|
+
region: "Région",
|
|
29
|
+
type: "Type",
|
|
30
|
+
moreInfo: "Plus d'infos"
|
|
31
|
+
},
|
|
20
32
|
es: {
|
|
21
33
|
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?",
|
|
22
34
|
noResultsFound: "No se encontraron resultados.",
|
|
@@ -40,7 +52,19 @@ class Translator {
|
|
|
40
52
|
region: "Region",
|
|
41
53
|
type: "Type",
|
|
42
54
|
moreInfo: "More info"
|
|
43
|
-
}
|
|
55
|
+
},
|
|
56
|
+
de: {
|
|
57
|
+
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?",
|
|
58
|
+
noResultsFound: "Keine Ergebnisse gefunden.",
|
|
59
|
+
somethingWentWrong: "Entschuldigung, etwas ist schief gelaufen.",
|
|
60
|
+
chatButton: "Wein zum Abendessen kombinieren",
|
|
61
|
+
inputPlaceholder: "z.B., Thunfischsalat",
|
|
62
|
+
sendButton: "Kombinieren",
|
|
63
|
+
price: "Preis",
|
|
64
|
+
region: "Region",
|
|
65
|
+
type: "Typ",
|
|
66
|
+
moreInfo: "Mehr Info"
|
|
67
|
+
}
|
|
44
68
|
};
|
|
45
69
|
}
|
|
46
70
|
|
package/src/js/styles.js
CHANGED