wineater-bot 1.5.1 → 1.5.3
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 +66 -65
- package/dist/wineater-chatbot.umd.js +2 -2
- package/package.json +1 -1
- package/src/index.js +4 -1
|
@@ -276,25 +276,25 @@ const f = `
|
|
|
276
276
|
}`, p = document.createElement("style");
|
|
277
277
|
p.textContent = f;
|
|
278
278
|
document.head.appendChild(p);
|
|
279
|
-
function b(n,
|
|
279
|
+
function b(n, e, t) {
|
|
280
280
|
let o = "";
|
|
281
|
-
if (
|
|
281
|
+
if (t) {
|
|
282
282
|
const i = /* @__PURE__ */ new Date();
|
|
283
|
-
i.setTime(i.getTime() +
|
|
283
|
+
i.setTime(i.getTime() + t * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
|
|
284
284
|
}
|
|
285
|
-
document.cookie = n + "=" + (
|
|
285
|
+
document.cookie = n + "=" + (e || "") + o + "; path=/; secure; samesite=strict";
|
|
286
286
|
}
|
|
287
287
|
function r(n) {
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
return
|
|
288
|
+
const t = `; ${document.cookie}`.split(`; ${n}=`);
|
|
289
|
+
if (t.length === 2)
|
|
290
|
+
return t.pop().split(";").shift();
|
|
291
291
|
}
|
|
292
|
-
function d(n,
|
|
293
|
-
const
|
|
292
|
+
function d(n, e) {
|
|
293
|
+
const t = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api-eu.mixpanel.com/track", i = {
|
|
294
294
|
event: n,
|
|
295
295
|
properties: {
|
|
296
|
-
token:
|
|
297
|
-
...
|
|
296
|
+
token: t,
|
|
297
|
+
...e
|
|
298
298
|
}
|
|
299
299
|
};
|
|
300
300
|
fetch(o, {
|
|
@@ -322,8 +322,8 @@ function x(n) {
|
|
|
322
322
|
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id: n });
|
|
323
323
|
}
|
|
324
324
|
function u() {
|
|
325
|
-
const n = document.getElementById("chat-window"),
|
|
326
|
-
n.classList.contains("visible") ? (h(), n.classList.remove("visible"),
|
|
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");
|
|
327
327
|
}
|
|
328
328
|
function v() {
|
|
329
329
|
h(), document.getElementById("chat-window").classList.remove("visible");
|
|
@@ -336,44 +336,44 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
336
336
|
});
|
|
337
337
|
const C = ["climats", "telckel", "biobio", "weinpoint"], E = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
338
338
|
class m {
|
|
339
|
-
constructor(
|
|
340
|
-
var
|
|
341
|
-
this.baseURL = "https://api.wineater.com/", this.store = C.find((o) => window.location.href.includes(o)), this.token = ((
|
|
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;
|
|
342
342
|
}
|
|
343
|
-
async getStoreConfig(
|
|
344
|
-
console.log(
|
|
343
|
+
async getStoreConfig(e) {
|
|
344
|
+
console.log(e);
|
|
345
345
|
try {
|
|
346
|
-
const
|
|
346
|
+
const t = await fetch(`${this.baseURL}stores/store`, {
|
|
347
347
|
method: "POST",
|
|
348
348
|
headers: {
|
|
349
349
|
"Content-Type": "application/json",
|
|
350
350
|
Authorization: `Bearer ${this.token}`
|
|
351
351
|
},
|
|
352
|
-
body: JSON.stringify({ store:
|
|
352
|
+
body: JSON.stringify({ store: e })
|
|
353
353
|
});
|
|
354
|
-
if (!
|
|
355
|
-
throw new Error(`HTTP error! Status: ${
|
|
356
|
-
return await
|
|
357
|
-
} catch (
|
|
358
|
-
throw console.error("Error fetching store configuration:",
|
|
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;
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
async getWineRecommendations(
|
|
361
|
+
async getWineRecommendations(e) {
|
|
362
362
|
console.log(window.location.href);
|
|
363
363
|
try {
|
|
364
|
-
const
|
|
364
|
+
const t = await fetch(`${this.baseURL}dish/recommendations`, {
|
|
365
365
|
method: "POST",
|
|
366
366
|
headers: {
|
|
367
367
|
"Content-Type": "application/json",
|
|
368
368
|
Authorization: `Bearer ${this.token}`
|
|
369
369
|
},
|
|
370
|
-
body: JSON.stringify({ text:
|
|
371
|
-
}), o = await
|
|
372
|
-
if (!
|
|
373
|
-
throw new Error(`API call failed with status ${
|
|
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"}`);
|
|
374
374
|
return o;
|
|
375
|
-
} catch (
|
|
376
|
-
throw console.error("Fetching wine recommendations failed:",
|
|
375
|
+
} catch (t) {
|
|
376
|
+
throw console.error("Fetching wine recommendations failed:", t.message), new Error(`Error in getWineRecommendations: ${t.message}`);
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
}
|
|
@@ -418,14 +418,14 @@ class I {
|
|
|
418
418
|
}
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
|
-
async fetchConfig(
|
|
422
|
-
if (
|
|
423
|
-
const
|
|
424
|
-
this.language =
|
|
421
|
+
async fetchConfig(e) {
|
|
422
|
+
if (e) {
|
|
423
|
+
const t = await this.api.getStoreConfig(e);
|
|
424
|
+
this.language = t.lang;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
-
translate(
|
|
428
|
-
return this.translations[this.language][
|
|
427
|
+
translate(e) {
|
|
428
|
+
return this.translations[this.language][e] || e;
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
431
|
const a = new I();
|
|
@@ -438,17 +438,17 @@ class T {
|
|
|
438
438
|
o.key === "Enter" && this.handleUserInput();
|
|
439
439
|
});
|
|
440
440
|
}
|
|
441
|
-
displayFirstMessage(
|
|
441
|
+
displayFirstMessage(e, t = "api") {
|
|
442
442
|
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
443
|
-
i.className = `message ${
|
|
443
|
+
i.className = `message ${t}`, i.textContent = e, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
444
444
|
}
|
|
445
445
|
async handleUserInput() {
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
448
|
-
this.displayMessage(
|
|
446
|
+
const e = document.getElementById("user-input"), t = e.value.trim();
|
|
447
|
+
if (t) {
|
|
448
|
+
this.displayMessage(t, "user"), e.value = "", this.showTypingIndicator();
|
|
449
449
|
try {
|
|
450
|
-
y(
|
|
451
|
-
const o = await this.api.getWineRecommendations(
|
|
450
|
+
y(t);
|
|
451
|
+
const o = await this.api.getWineRecommendations(t);
|
|
452
452
|
this.hideTypingIndicator(), o && o.length ? this.displayResults(o) : this.displayMessage("No results found.", "api");
|
|
453
453
|
} catch {
|
|
454
454
|
this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
|
|
@@ -461,16 +461,16 @@ class T {
|
|
|
461
461
|
hideTypingIndicator() {
|
|
462
462
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
463
463
|
}
|
|
464
|
-
displayMessage(
|
|
464
|
+
displayMessage(e, t) {
|
|
465
465
|
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
466
|
-
i.textContent =
|
|
466
|
+
i.textContent = e, i.className = "message " + t, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
467
467
|
}
|
|
468
|
-
sendAnalytics(
|
|
469
|
-
x(
|
|
468
|
+
sendAnalytics(e) {
|
|
469
|
+
x(e);
|
|
470
470
|
}
|
|
471
|
-
displayResults(
|
|
472
|
-
const
|
|
473
|
-
w(
|
|
471
|
+
displayResults(e) {
|
|
472
|
+
const t = document.getElementById("message-container");
|
|
473
|
+
w(e.map((o) => o.Title)), e.forEach((o) => {
|
|
474
474
|
const i = document.createElement("div");
|
|
475
475
|
i.className = "wine-item";
|
|
476
476
|
const s = document.createElement("img");
|
|
@@ -482,14 +482,15 @@ class T {
|
|
|
482
482
|
${a.translate("region")}: ${o.Region}<br>
|
|
483
483
|
${a.translate("type")}: ${o.Type}<br>
|
|
484
484
|
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
485
|
-
`, i.appendChild(c),
|
|
486
|
-
}),
|
|
485
|
+
`, i.appendChild(c), t.appendChild(i);
|
|
486
|
+
}), t.scrollTop = t.scrollHeight;
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
+
const B = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
489
490
|
document.addEventListener("DOMContentLoaded", () => {
|
|
490
491
|
window.toggleChatWindow = u, window.closeChatWindow = v, window.openChatWindow = k;
|
|
491
492
|
});
|
|
492
|
-
function
|
|
493
|
+
function L() {
|
|
493
494
|
const n = `
|
|
494
495
|
<div id="chatbot-container">
|
|
495
496
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
@@ -519,28 +520,28 @@ function B() {
|
|
|
519
520
|
`;
|
|
520
521
|
document.body.insertAdjacentHTML("beforeend", n);
|
|
521
522
|
}
|
|
522
|
-
function
|
|
523
|
+
function P() {
|
|
523
524
|
document.getElementById("close-btn").addEventListener("click", u);
|
|
524
525
|
}
|
|
525
|
-
function
|
|
526
|
+
function W() {
|
|
526
527
|
window.addEventListener("click", function(n) {
|
|
527
|
-
const
|
|
528
|
-
!
|
|
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");
|
|
529
530
|
});
|
|
530
531
|
}
|
|
531
|
-
function
|
|
532
|
+
function O(n) {
|
|
532
533
|
console.log(n);
|
|
533
|
-
const
|
|
534
|
-
|
|
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");
|
|
535
536
|
}
|
|
536
537
|
var l;
|
|
537
538
|
if (typeof window < "u") {
|
|
538
539
|
const n = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
539
540
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
540
541
|
var s;
|
|
541
|
-
const
|
|
542
|
+
const t = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
|
|
542
543
|
let o;
|
|
543
|
-
|
|
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();
|
|
544
545
|
});
|
|
545
546
|
}
|
|
546
547
|
export {
|
|
@@ -279,7 +279,7 @@
|
|
|
279
279
|
${s.translate("region")}: ${o.Region}<br>
|
|
280
280
|
${s.translate("type")}: ${o.Type}<br>
|
|
281
281
|
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${s.translate("moreInfo")}</a>
|
|
282
|
-
`,i.appendChild(p),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=f,window.openChatWindow=b});function
|
|
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
|
|
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
package/src/index.js
CHANGED
|
@@ -10,6 +10,9 @@ import { Chatbot } from './js/chatbot.js';
|
|
|
10
10
|
import './js/api.js';
|
|
11
11
|
import translator from './js/i18n.js';
|
|
12
12
|
|
|
13
|
+
const DEMO_TOKEN='OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL';
|
|
14
|
+
|
|
15
|
+
|
|
13
16
|
document.addEventListener('DOMContentLoaded', () => {
|
|
14
17
|
// Attach any necessary initialization code here
|
|
15
18
|
// For example, expose functions to global scope if absolutely necessary
|
|
@@ -105,7 +108,7 @@ if (typeof window !== 'undefined') {
|
|
|
105
108
|
setupCloseButton();
|
|
106
109
|
setupOutsideClick();
|
|
107
110
|
toggleChatIconPosition(position);
|
|
108
|
-
setCookie('chatbotToken', window.wineaterData?.CLIENT_TOKEN, 365);
|
|
111
|
+
setCookie('chatbotToken', window.wineaterData?.CLIENT_TOKEN || DEMO_TOKEN, 365);
|
|
109
112
|
const myChatbot = new Chatbot();
|
|
110
113
|
myChatbot.initialize();
|
|
111
114
|
});
|