wineater-bot 1.5.9 → 1.5.11
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 +124 -100
- package/dist/wineater-chatbot.umd.js +12 -8
- package/package.json +1 -1
- package/src/js/analytics.js +1 -5
- 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,34 +280,30 @@ 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",
|
|
302
|
-
|
|
303
|
-
accept: "text/plain",
|
|
304
|
-
"content-type": "application/json"
|
|
305
|
-
},
|
|
306
|
-
body: JSON.stringify(i)
|
|
306
|
+
body: i
|
|
307
307
|
}).then((s) => {
|
|
308
308
|
s.ok || console.error("Mixpanel tracking failed", s);
|
|
309
309
|
}).catch((s) => {
|
|
@@ -316,18 +316,18 @@ function h() {
|
|
|
316
316
|
function g() {
|
|
317
317
|
d("Chatbot Closed", { distinct_id: r("chatbotToken") });
|
|
318
318
|
}
|
|
319
|
-
function y(
|
|
320
|
-
d("Message Sent", { distinct_id: r("chatbotToken"), message_content:
|
|
319
|
+
function y(o) {
|
|
320
|
+
d("Message Sent", { distinct_id: r("chatbotToken"), message_content: o });
|
|
321
321
|
}
|
|
322
|
-
function w(
|
|
323
|
-
d("Message Sent", { distinct_id: r("chatbotToken"), products:
|
|
322
|
+
function w(o) {
|
|
323
|
+
d("Message Sent", { distinct_id: r("chatbotToken"), products: o });
|
|
324
324
|
}
|
|
325
|
-
function x(
|
|
326
|
-
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id:
|
|
325
|
+
function x(o) {
|
|
326
|
+
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id: o });
|
|
327
327
|
}
|
|
328
328
|
function u() {
|
|
329
|
-
const
|
|
330
|
-
|
|
329
|
+
const o = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
330
|
+
o.classList.contains("visible") ? (g(), o.classList.remove("visible"), t.style.display = "flex") : (h(), o.classList.add("visible"), t.style.display = "none");
|
|
331
331
|
}
|
|
332
332
|
function v() {
|
|
333
333
|
g(), document.getElementById("chat-window").classList.remove("visible");
|
|
@@ -338,50 +338,50 @@ function k() {
|
|
|
338
338
|
document.addEventListener("DOMContentLoaded", () => {
|
|
339
339
|
setupCloseButton(), setupOutsideClick();
|
|
340
340
|
});
|
|
341
|
-
const
|
|
341
|
+
const E = ["climats", "telckel", "biobio", "weinpoint"], I = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
342
342
|
class m {
|
|
343
|
-
constructor(
|
|
344
|
-
var
|
|
345
|
-
this.baseURL = "https://api.wineater.com/", this.store =
|
|
343
|
+
constructor(t) {
|
|
344
|
+
var e;
|
|
345
|
+
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;
|
|
346
346
|
}
|
|
347
|
-
async getStoreConfig(
|
|
348
|
-
console.log(
|
|
347
|
+
async getStoreConfig(t) {
|
|
348
|
+
console.log(t);
|
|
349
349
|
try {
|
|
350
|
-
const
|
|
350
|
+
const e = await fetch(`${this.baseURL}stores/store`, {
|
|
351
351
|
method: "POST",
|
|
352
352
|
headers: {
|
|
353
353
|
"Content-Type": "application/json",
|
|
354
354
|
Authorization: `Bearer ${this.token}`
|
|
355
355
|
},
|
|
356
|
-
body: JSON.stringify({ store:
|
|
356
|
+
body: JSON.stringify({ store: t })
|
|
357
357
|
});
|
|
358
|
-
if (!
|
|
359
|
-
throw new Error(`HTTP error! Status: ${
|
|
360
|
-
return await
|
|
361
|
-
} catch (
|
|
362
|
-
throw console.error("Error fetching store configuration:",
|
|
358
|
+
if (!e.ok)
|
|
359
|
+
throw new Error(`HTTP error! Status: ${e.status}`);
|
|
360
|
+
return await e.json();
|
|
361
|
+
} catch (e) {
|
|
362
|
+
throw console.error("Error fetching store configuration:", e), e;
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
|
-
async getWineRecommendations(
|
|
365
|
+
async getWineRecommendations(t) {
|
|
366
366
|
console.log(window.location.href);
|
|
367
367
|
try {
|
|
368
|
-
const
|
|
368
|
+
const e = await fetch(`${this.baseURL}dish/recommendations`, {
|
|
369
369
|
method: "POST",
|
|
370
370
|
headers: {
|
|
371
371
|
"Content-Type": "application/json",
|
|
372
372
|
Authorization: `Bearer ${this.token}`
|
|
373
373
|
},
|
|
374
|
-
body: JSON.stringify({ text:
|
|
375
|
-
}),
|
|
376
|
-
if (!
|
|
377
|
-
throw new Error(`API call failed with status ${
|
|
378
|
-
return
|
|
379
|
-
} catch (
|
|
380
|
-
throw console.error("Fetching wine recommendations failed:",
|
|
374
|
+
body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
|
|
375
|
+
}), n = await e.json();
|
|
376
|
+
if (!e.ok)
|
|
377
|
+
throw new Error(`API call failed with status ${e.status}: ${n.message || "No additional error information"}`);
|
|
378
|
+
return n;
|
|
379
|
+
} catch (e) {
|
|
380
|
+
throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
|
-
class
|
|
384
|
+
class C {
|
|
385
385
|
constructor() {
|
|
386
386
|
this.api = new m(), this.language = "en", this.translations = {
|
|
387
387
|
fr: {
|
|
@@ -396,6 +396,18 @@ class I {
|
|
|
396
396
|
type: "Type",
|
|
397
397
|
moreInfo: "Plus d'infos"
|
|
398
398
|
},
|
|
399
|
+
de: {
|
|
400
|
+
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?",
|
|
401
|
+
noResultsFound: "Aucun résultat trouvé.",
|
|
402
|
+
somethingWentWrong: "Désolé, quelque chose a mal tourné.",
|
|
403
|
+
chatButton: "Accorder le vin au dîner",
|
|
404
|
+
inputPlaceholder: "ex., Salade de thon",
|
|
405
|
+
sendButton: "Accorder",
|
|
406
|
+
price: "Prix",
|
|
407
|
+
region: "Région",
|
|
408
|
+
type: "Type",
|
|
409
|
+
moreInfo: "Plus d'infos"
|
|
410
|
+
},
|
|
399
411
|
es: {
|
|
400
412
|
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?",
|
|
401
413
|
noResultsFound: "No se encontraron resultados.",
|
|
@@ -419,41 +431,53 @@ class I {
|
|
|
419
431
|
region: "Region",
|
|
420
432
|
type: "Type",
|
|
421
433
|
moreInfo: "More info"
|
|
434
|
+
},
|
|
435
|
+
de: {
|
|
436
|
+
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?",
|
|
437
|
+
noResultsFound: "Keine Ergebnisse gefunden.",
|
|
438
|
+
somethingWentWrong: "Entschuldigung, etwas ist schief gelaufen.",
|
|
439
|
+
chatButton: "Wein zum Abendessen kombinieren",
|
|
440
|
+
inputPlaceholder: "z.B., Thunfischsalat",
|
|
441
|
+
sendButton: "Kombinieren",
|
|
442
|
+
price: "Preis",
|
|
443
|
+
region: "Region",
|
|
444
|
+
type: "Typ",
|
|
445
|
+
moreInfo: "Mehr Info"
|
|
422
446
|
}
|
|
423
447
|
};
|
|
424
448
|
}
|
|
425
|
-
async fetchConfig(
|
|
426
|
-
if (
|
|
427
|
-
const
|
|
428
|
-
this.language =
|
|
449
|
+
async fetchConfig(t) {
|
|
450
|
+
if (t) {
|
|
451
|
+
const e = await this.api.getStoreConfig(t);
|
|
452
|
+
this.language = e.lang;
|
|
429
453
|
}
|
|
430
454
|
}
|
|
431
|
-
translate(
|
|
432
|
-
return this.translations[this.language][
|
|
455
|
+
translate(t) {
|
|
456
|
+
return this.translations[this.language][t] || t;
|
|
433
457
|
}
|
|
434
458
|
}
|
|
435
|
-
const a = new
|
|
459
|
+
const a = new C();
|
|
436
460
|
class T {
|
|
437
461
|
constructor() {
|
|
438
462
|
this.api = new m(), this.displayFirstMessage(a.translate("welcomeMessage"));
|
|
439
463
|
}
|
|
440
464
|
initialize() {
|
|
441
|
-
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (
|
|
442
|
-
|
|
465
|
+
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (n) => {
|
|
466
|
+
n.key === "Enter" && this.handleUserInput();
|
|
443
467
|
});
|
|
444
468
|
}
|
|
445
|
-
displayFirstMessage(
|
|
446
|
-
const
|
|
447
|
-
i.className = `message ${
|
|
469
|
+
displayFirstMessage(t, e = "api") {
|
|
470
|
+
const n = document.getElementById("message-container"), i = document.createElement("div");
|
|
471
|
+
i.className = `message ${e}`, i.textContent = t, n.appendChild(i), n.scrollTop = n.scrollHeight;
|
|
448
472
|
}
|
|
449
473
|
async handleUserInput() {
|
|
450
|
-
const
|
|
451
|
-
if (
|
|
452
|
-
this.displayMessage(
|
|
474
|
+
const t = document.getElementById("user-input"), e = t.value.trim();
|
|
475
|
+
if (e) {
|
|
476
|
+
this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
|
|
453
477
|
try {
|
|
454
|
-
y(
|
|
455
|
-
const
|
|
456
|
-
this.hideTypingIndicator(),
|
|
478
|
+
y(e);
|
|
479
|
+
const n = await this.api.getWineRecommendations(e);
|
|
480
|
+
this.hideTypingIndicator(), n && n.length ? this.displayResults(n) : this.displayMessage("No results found.", "api");
|
|
457
481
|
} catch {
|
|
458
482
|
this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
|
|
459
483
|
}
|
|
@@ -465,37 +489,37 @@ class T {
|
|
|
465
489
|
hideTypingIndicator() {
|
|
466
490
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
467
491
|
}
|
|
468
|
-
displayMessage(
|
|
469
|
-
const
|
|
470
|
-
i.textContent =
|
|
492
|
+
displayMessage(t, e) {
|
|
493
|
+
const n = document.getElementById("message-container"), i = document.createElement("div");
|
|
494
|
+
i.textContent = t, i.className = "message " + e, n.appendChild(i), n.scrollTop = n.scrollHeight;
|
|
471
495
|
}
|
|
472
|
-
sendAnalytics(
|
|
473
|
-
x(
|
|
496
|
+
sendAnalytics(t) {
|
|
497
|
+
x(t);
|
|
474
498
|
}
|
|
475
|
-
displayResults(
|
|
476
|
-
const
|
|
477
|
-
w(
|
|
499
|
+
displayResults(t) {
|
|
500
|
+
const e = document.getElementById("message-container");
|
|
501
|
+
w(t.map((n) => n.Title)), t.forEach((n) => {
|
|
478
502
|
const i = document.createElement("div");
|
|
479
503
|
i.className = "wine-item";
|
|
480
504
|
const s = document.createElement("img");
|
|
481
|
-
s.src =
|
|
505
|
+
s.src = n.Image, i.appendChild(s);
|
|
482
506
|
const c = document.createElement("div");
|
|
483
507
|
c.innerHTML = `
|
|
484
|
-
<strong>${
|
|
485
|
-
${a.translate("price")}: ${
|
|
486
|
-
${a.translate("region")}: ${
|
|
487
|
-
${a.translate("type")}: ${
|
|
488
|
-
<a href="${
|
|
489
|
-
`, i.appendChild(c),
|
|
490
|
-
}),
|
|
508
|
+
<strong>${n.Title}</strong><br>
|
|
509
|
+
${a.translate("price")}: ${n.Price}<br>
|
|
510
|
+
${a.translate("region")}: ${n.Region}<br>
|
|
511
|
+
${a.translate("type")}: ${n.Type}<br>
|
|
512
|
+
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
513
|
+
`, i.appendChild(c), e.appendChild(i);
|
|
514
|
+
}), e.scrollTop = e.scrollHeight;
|
|
491
515
|
}
|
|
492
516
|
}
|
|
493
517
|
const B = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
494
518
|
document.addEventListener("DOMContentLoaded", () => {
|
|
495
519
|
window.toggleChatWindow = u, window.closeChatWindow = v, window.openChatWindow = k;
|
|
496
520
|
});
|
|
497
|
-
function
|
|
498
|
-
const
|
|
521
|
+
function W() {
|
|
522
|
+
const o = `
|
|
499
523
|
<div id="chatbot-container">
|
|
500
524
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
501
525
|
<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 -->
|
|
@@ -522,30 +546,30 @@ function L() {
|
|
|
522
546
|
</div>
|
|
523
547
|
</div>
|
|
524
548
|
`;
|
|
525
|
-
document.body.insertAdjacentHTML("beforeend",
|
|
549
|
+
document.body.insertAdjacentHTML("beforeend", o);
|
|
526
550
|
}
|
|
527
551
|
function P() {
|
|
528
552
|
document.getElementById("close-btn").addEventListener("click", u);
|
|
529
553
|
}
|
|
530
|
-
function
|
|
531
|
-
window.addEventListener("click", function(
|
|
532
|
-
const
|
|
533
|
-
!
|
|
554
|
+
function L() {
|
|
555
|
+
window.addEventListener("click", function(o) {
|
|
556
|
+
const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
557
|
+
!t.contains(o.target) && !e.contains(o.target) && (t.classList.remove("visible"), e.style.display = "flex");
|
|
534
558
|
});
|
|
535
559
|
}
|
|
536
|
-
function
|
|
537
|
-
console.log(
|
|
538
|
-
const
|
|
539
|
-
|
|
560
|
+
function S(o) {
|
|
561
|
+
console.log(o);
|
|
562
|
+
const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
|
|
563
|
+
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");
|
|
540
564
|
}
|
|
541
565
|
var l;
|
|
542
566
|
if (typeof window < "u") {
|
|
543
|
-
const
|
|
567
|
+
const o = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
544
568
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
545
569
|
var s;
|
|
546
|
-
const
|
|
547
|
-
let
|
|
548
|
-
|
|
570
|
+
const e = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
|
|
571
|
+
let n;
|
|
572
|
+
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();
|
|
549
573
|
});
|
|
550
574
|
}
|
|
551
575
|
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",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=`
|
|
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
|
@@ -30,11 +30,7 @@ function setCookie(name, value, days) {
|
|
|
30
30
|
|
|
31
31
|
fetch(endpoint, {
|
|
32
32
|
method: 'POST',
|
|
33
|
-
|
|
34
|
-
'accept': 'text/plain',
|
|
35
|
-
'content-type': 'application/json'
|
|
36
|
-
},
|
|
37
|
-
body: JSON.stringify(data)
|
|
33
|
+
body: data
|
|
38
34
|
}).then(response => {
|
|
39
35
|
if (!response.ok) {
|
|
40
36
|
console.error('Mixpanel tracking failed', response);
|
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