wineater-bot 1.2.0 → 1.3.0
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 +139 -71
- package/dist/wineater-chatbot.umd.js +12 -12
- package/index.html +17 -0
- package/package.json +1 -1
- package/src/index.js +2 -0
- package/src/js/api.js +6 -3
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var g = (i, e, t) => e in i ? p(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
-
var r = (i, e, t) => (g(i, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
-
const h = `
|
|
1
|
+
const g = `
|
|
5
2
|
@font-face {
|
|
6
3
|
font-family: 'Poppins';
|
|
7
4
|
src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
|
|
@@ -277,13 +274,13 @@ const h = `
|
|
|
277
274
|
visibility: visible;
|
|
278
275
|
height: 50px;
|
|
279
276
|
}`, c = document.createElement("style");
|
|
280
|
-
c.textContent =
|
|
277
|
+
c.textContent = g;
|
|
281
278
|
document.head.appendChild(c);
|
|
282
279
|
function l() {
|
|
283
|
-
const
|
|
284
|
-
|
|
280
|
+
const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
281
|
+
n.classList.contains("visible") ? (n.classList.remove("visible"), t.style.display = "flex") : (n.classList.add("visible"), t.style.display = "none");
|
|
285
282
|
}
|
|
286
|
-
function
|
|
283
|
+
function h() {
|
|
287
284
|
document.getElementById("chat-window").classList.remove("visible");
|
|
288
285
|
}
|
|
289
286
|
function u() {
|
|
@@ -292,52 +289,123 @@ function u() {
|
|
|
292
289
|
document.addEventListener("DOMContentLoaded", () => {
|
|
293
290
|
setupCloseButton(), setupOutsideClick();
|
|
294
291
|
});
|
|
295
|
-
const
|
|
296
|
-
class
|
|
297
|
-
constructor(
|
|
298
|
-
|
|
292
|
+
const m = ["climats", "telckel", "biobio", "weinpoint"], f = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
293
|
+
class p {
|
|
294
|
+
constructor(t) {
|
|
295
|
+
var e;
|
|
296
|
+
this.baseURL = "https://api.wineater.com/", this.store = m.find((o) => window.location.href.includes(o)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || f;
|
|
297
|
+
}
|
|
298
|
+
async getStoreConfig(t) {
|
|
299
|
+
console.log(t);
|
|
300
|
+
try {
|
|
301
|
+
const e = await fetch(`${this.baseURL}stores/store`, {
|
|
302
|
+
method: "POST",
|
|
303
|
+
headers: {
|
|
304
|
+
"Content-Type": "application/json",
|
|
305
|
+
Authorization: `Bearer ${this.token}`
|
|
306
|
+
},
|
|
307
|
+
body: JSON.stringify({ store: t })
|
|
308
|
+
});
|
|
309
|
+
if (!e.ok)
|
|
310
|
+
throw new Error(`HTTP error! Status: ${e.status}`);
|
|
311
|
+
return await e.json();
|
|
312
|
+
} catch (e) {
|
|
313
|
+
throw console.error("Error fetching store configuration:", e), e;
|
|
314
|
+
}
|
|
299
315
|
}
|
|
300
|
-
async getWineRecommendations(
|
|
316
|
+
async getWineRecommendations(t) {
|
|
301
317
|
console.log(window.location.href);
|
|
302
318
|
try {
|
|
303
|
-
const
|
|
319
|
+
const e = await fetch(`${this.baseURL}dish/recommendations`, {
|
|
304
320
|
method: "POST",
|
|
305
321
|
headers: {
|
|
306
|
-
"Content-Type": "application/json"
|
|
322
|
+
"Content-Type": "application/json",
|
|
323
|
+
Authorization: `Bearer ${this.token}`
|
|
307
324
|
},
|
|
308
|
-
body: JSON.stringify({ text:
|
|
309
|
-
}), o = await
|
|
310
|
-
if (!
|
|
311
|
-
throw new Error(`API call failed with status ${
|
|
325
|
+
body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
|
|
326
|
+
}), o = await e.json();
|
|
327
|
+
if (!e.ok)
|
|
328
|
+
throw new Error(`API call failed with status ${e.status}: ${o.message || "No additional error information"}`);
|
|
312
329
|
return o;
|
|
313
|
-
} catch (
|
|
314
|
-
throw console.error("Fetching wine recommendations failed:",
|
|
330
|
+
} catch (e) {
|
|
331
|
+
throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
|
|
315
332
|
}
|
|
316
333
|
}
|
|
317
334
|
}
|
|
318
335
|
class y {
|
|
319
336
|
constructor() {
|
|
320
|
-
|
|
321
|
-
|
|
337
|
+
this.api = new p(), this.language = "en", this.translations = {
|
|
338
|
+
fr: {
|
|
339
|
+
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?",
|
|
340
|
+
noResultsFound: "Aucun résultat trouvé.",
|
|
341
|
+
somethingWentWrong: "Désolé, quelque chose a mal tourné.",
|
|
342
|
+
chatButton: "Accorder le vin au dîner",
|
|
343
|
+
inputPlaceholder: "ex., Salade de thon",
|
|
344
|
+
sendButton: "Accorder",
|
|
345
|
+
price: "Prix",
|
|
346
|
+
region: "Région",
|
|
347
|
+
type: "Type",
|
|
348
|
+
moreInfo: "Plus d'infos"
|
|
349
|
+
},
|
|
350
|
+
es: {
|
|
351
|
+
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?",
|
|
352
|
+
noResultsFound: "No se encontraron resultados.",
|
|
353
|
+
somethingWentWrong: "Lo sentimos, algo salió mal.",
|
|
354
|
+
chatButton: "Maridar vino con cena",
|
|
355
|
+
inputPlaceholder: "ej., Ensalada de atún",
|
|
356
|
+
sendButton: "Maridar",
|
|
357
|
+
price: "Precio",
|
|
358
|
+
region: "Región",
|
|
359
|
+
type: "Tipo",
|
|
360
|
+
moreInfo: "Más info"
|
|
361
|
+
},
|
|
362
|
+
en: {
|
|
363
|
+
welcomeMessage: "Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",
|
|
364
|
+
noResultsFound: "No results found.",
|
|
365
|
+
somethingWentWrong: "Sorry, something went wrong.",
|
|
366
|
+
chatButton: "Pair wine with dinner",
|
|
367
|
+
inputPlaceholder: "e.g., Tuna Salad",
|
|
368
|
+
sendButton: "Pair",
|
|
369
|
+
price: "Price",
|
|
370
|
+
region: "Region",
|
|
371
|
+
type: "Type",
|
|
372
|
+
moreInfo: "More info"
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
async fetchConfig(t) {
|
|
377
|
+
if (t) {
|
|
378
|
+
const e = await this.api.getStoreConfig(t);
|
|
379
|
+
this.language = e.lang;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
translate(t) {
|
|
383
|
+
return this.translations[this.language][t] || t;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const s = new y();
|
|
387
|
+
class b {
|
|
388
|
+
constructor() {
|
|
389
|
+
this.api = new p(), this.displayFirstMessage(s.translate("welcomeMessage"));
|
|
322
390
|
}
|
|
323
391
|
initialize() {
|
|
324
392
|
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (o) => {
|
|
325
393
|
o.key === "Enter" && this.handleUserInput();
|
|
326
394
|
});
|
|
327
395
|
}
|
|
328
|
-
displayFirstMessage(
|
|
329
|
-
const o = document.getElementById("message-container"),
|
|
330
|
-
|
|
396
|
+
displayFirstMessage(t, e = "api") {
|
|
397
|
+
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
398
|
+
i.className = `message ${e}`, i.textContent = t, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
331
399
|
}
|
|
332
400
|
async handleUserInput() {
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
335
|
-
this.displayMessage(
|
|
401
|
+
const t = document.getElementById("user-input"), e = t.value.trim();
|
|
402
|
+
if (e) {
|
|
403
|
+
this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
|
|
336
404
|
try {
|
|
337
|
-
const o = await this.api.getWineRecommendations(
|
|
405
|
+
const o = await this.api.getWineRecommendations(e);
|
|
338
406
|
this.hideTypingIndicator(), o && o.length ? this.displayResults(o) : this.displayMessage("No results found.", "api");
|
|
339
|
-
} catch
|
|
340
|
-
this.hideTypingIndicator(),
|
|
407
|
+
} catch {
|
|
408
|
+
this.hideTypingIndicator(), this.displayMessage(s.translate("somethingWentWrong"), "api");
|
|
341
409
|
}
|
|
342
410
|
}
|
|
343
411
|
}
|
|
@@ -347,37 +415,37 @@ class y {
|
|
|
347
415
|
hideTypingIndicator() {
|
|
348
416
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
349
417
|
}
|
|
350
|
-
displayMessage(
|
|
351
|
-
const o = document.getElementById("message-container"),
|
|
352
|
-
|
|
418
|
+
displayMessage(t, e) {
|
|
419
|
+
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
420
|
+
i.textContent = t, i.className = "message " + e, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
353
421
|
}
|
|
354
|
-
displayResults(
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
`,
|
|
369
|
-
}),
|
|
422
|
+
displayResults(t) {
|
|
423
|
+
const e = document.getElementById("message-container");
|
|
424
|
+
t.forEach((o) => {
|
|
425
|
+
const i = document.createElement("div");
|
|
426
|
+
i.className = "wine-item";
|
|
427
|
+
const a = document.createElement("img");
|
|
428
|
+
a.src = o.Image, i.appendChild(a);
|
|
429
|
+
const r = document.createElement("div");
|
|
430
|
+
r.innerHTML = `
|
|
431
|
+
<strong>${o.Title}</strong><br>
|
|
432
|
+
${s.translate("price")}: ${o.Price}<br>
|
|
433
|
+
${s.translate("region")}: ${o.Region}<br>
|
|
434
|
+
${s.translate("type")}: ${o.Type}<br>
|
|
435
|
+
<a href="${o.Url}" target="_blank">${s.translate("moreInfo")}</a>
|
|
436
|
+
`, i.appendChild(r), e.appendChild(i);
|
|
437
|
+
}), e.scrollTop = e.scrollHeight;
|
|
370
438
|
}
|
|
371
439
|
}
|
|
372
440
|
document.addEventListener("DOMContentLoaded", () => {
|
|
373
|
-
window.toggleChatWindow = l, window.closeChatWindow =
|
|
441
|
+
window.toggleChatWindow = l, window.closeChatWindow = h, window.openChatWindow = u;
|
|
374
442
|
});
|
|
375
443
|
function w() {
|
|
376
|
-
|
|
444
|
+
const n = `
|
|
377
445
|
<div id="chatbot-container">
|
|
378
446
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
379
447
|
<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 -->
|
|
380
|
-
<span
|
|
448
|
+
<span>${s.translate("chatButton")}</span>
|
|
381
449
|
</div>
|
|
382
450
|
|
|
383
451
|
<div id="chat-window" class="hidden">
|
|
@@ -394,35 +462,35 @@ function w() {
|
|
|
394
462
|
<span></span><span></span><span></span>
|
|
395
463
|
</div>
|
|
396
464
|
<div id="input-container">
|
|
397
|
-
<input type="text" id="user-input" placeholder="
|
|
398
|
-
<button id="send-button"
|
|
465
|
+
<input type="text" id="user-input" placeholder="${s.translate("inputPlaceholder")}">
|
|
466
|
+
<button id="send-button">${s.translate("sendButton")}</button>
|
|
399
467
|
</div>
|
|
400
468
|
</div>
|
|
401
469
|
</div>
|
|
402
|
-
|
|
470
|
+
`;
|
|
471
|
+
document.body.insertAdjacentHTML("beforeend", n);
|
|
403
472
|
}
|
|
404
473
|
function x() {
|
|
405
474
|
document.getElementById("close-btn").addEventListener("click", l);
|
|
406
475
|
}
|
|
407
476
|
function v() {
|
|
408
|
-
window.addEventListener("click", function(
|
|
409
|
-
const
|
|
410
|
-
!
|
|
477
|
+
window.addEventListener("click", function(n) {
|
|
478
|
+
const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
479
|
+
!t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
|
|
411
480
|
});
|
|
412
481
|
}
|
|
413
|
-
function d(
|
|
414
|
-
console.log(
|
|
415
|
-
const
|
|
416
|
-
|
|
482
|
+
function d(n) {
|
|
483
|
+
console.log(n);
|
|
484
|
+
const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
|
|
485
|
+
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");
|
|
417
486
|
}
|
|
418
|
-
typeof window < "u" && window.addEventListener("DOMContentLoaded", () => {
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
487
|
+
typeof window < "u" && (console.log("привет"), console.log(window.wineaterClientData), window.addEventListener("DOMContentLoaded", async () => {
|
|
488
|
+
const t = ["climats", "telckel", "biobio", "weinpoint"].find((i) => window.location.href.includes(i)) || null;
|
|
489
|
+
let e;
|
|
490
|
+
t && (e = t.charAt(0).toUpperCase() + t.slice(1)), await s.fetchConfig(e || null), w(), x(), v(), d(t && t === "biobio" ? "right-center" : "bottom-right"), new b().initialize();
|
|
491
|
+
}));
|
|
422
492
|
export {
|
|
423
|
-
|
|
493
|
+
h as closeChatWindow,
|
|
424
494
|
u as openChatWindow,
|
|
425
495
|
l as toggleChatWindow
|
|
426
496
|
};
|
|
427
|
-
|
|
428
|
-
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.WineaterChatbot={}))})(this,function(a){"use strict";const r=`
|
|
2
2
|
@font-face {
|
|
3
3
|
font-family: 'Poppins';
|
|
4
4
|
src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
|
|
@@ -273,17 +273,17 @@
|
|
|
273
273
|
.typing-indicator.visible {
|
|
274
274
|
visibility: visible;
|
|
275
275
|
height: 50px;
|
|
276
|
-
}`,
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
`,
|
|
276
|
+
}`,c=document.createElement("style");c.textContent=r,document.head.appendChild(c);function d(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(n.classList.remove("visible"),t.style.display="flex"):(n.classList.add("visible"),t.style.display="none")}function l(){document.getElementById("chat-window").classList.remove("visible")}function p(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const f=["climats","telckel","biobio","weinpoint"],y="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class g{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=f.find(o=>window.location.href.includes(o)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||y}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),o=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${o.message||"No additional error information"}`);return o}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class b{constructor(){this.api=new g,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"}}}async fetchConfig(t){if(t){const e=await this.api.getStoreConfig(t);this.language=e.lang}}translate(t){return this.translations[this.language][t]||t}}const s=new b;class w{constructor(){this.api=new g,this.displayFirstMessage(s.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",o=>{o.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const o=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,o.appendChild(i),o.scrollTop=o.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{const o=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),o&&o.length?this.displayResults(o):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(s.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const o=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,o.appendChild(i),o.scrollTop=o.scrollHeight}displayResults(t){const e=document.getElementById("message-container");t.forEach(o=>{const i=document.createElement("div");i.className="wine-item";const u=document.createElement("img");u.src=o.Image,i.appendChild(u);const m=document.createElement("div");m.innerHTML=`
|
|
277
|
+
<strong>${o.Title}</strong><br>
|
|
278
|
+
${s.translate("price")}: ${o.Price}<br>
|
|
279
|
+
${s.translate("region")}: ${o.Region}<br>
|
|
280
|
+
${s.translate("type")}: ${o.Type}<br>
|
|
281
|
+
<a href="${o.Url}" target="_blank">${s.translate("moreInfo")}</a>
|
|
282
|
+
`,i.appendChild(m),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=d,window.closeChatWindow=l,window.openChatWindow=p});function x(){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 -->
|
|
286
|
-
<span
|
|
286
|
+
<span>${s.translate("chatButton")}</span>
|
|
287
287
|
</div>
|
|
288
288
|
|
|
289
289
|
<div id="chat-window" class="hidden">
|
|
@@ -300,9 +300,9 @@
|
|
|
300
300
|
<span></span><span></span><span></span>
|
|
301
301
|
</div>
|
|
302
302
|
<div id="input-container">
|
|
303
|
-
<input type="text" id="user-input" placeholder="
|
|
304
|
-
<button id="send-button"
|
|
303
|
+
<input type="text" id="user-input" placeholder="${s.translate("inputPlaceholder")}">
|
|
304
|
+
<button id="send-button">${s.translate("sendButton")}</button>
|
|
305
305
|
</div>
|
|
306
306
|
</div>
|
|
307
307
|
</div>
|
|
308
|
-
|
|
308
|
+
`;document.body.insertAdjacentHTML("beforeend",n)}function v(){document.getElementById("close-btn").addEventListener("click",d)}function E(){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 h(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")}typeof window<"u"&&(console.log("привет"),console.log(window.wineaterClientData),window.addEventListener("DOMContentLoaded",async()=>{const t=["climats","telckel","biobio","weinpoint"].find(i=>window.location.href.includes(i))||null;let e;t&&(e=t.charAt(0).toUpperCase()+t.slice(1)),await s.fetchConfig(e||null),x(),v(),E(),h(t&&t==="biobio"?"right-center":"bottom-right"),new w().initialize()})),a.closeChatWindow=l,a.openChatWindow=p,a.toggleChatWindow=d,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/index.html
CHANGED
|
@@ -5,8 +5,25 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Chatbot</title>
|
|
7
7
|
<!-- <script type="module" src="https://unpkg.com/wineater-bot@1.0.0/dist/wineater-chatbot.umd.js"></script> -->
|
|
8
|
+
<script>
|
|
9
|
+
|
|
10
|
+
</script>
|
|
8
11
|
<script type="module" src="./src/index.js"></script>
|
|
9
12
|
|
|
13
|
+
<script>
|
|
14
|
+
// Set the unique token for the chatbot
|
|
15
|
+
window.wineaterData = {
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Asynchronously load the chatbot script
|
|
19
|
+
(function() {
|
|
20
|
+
var script = document.createElement('script');
|
|
21
|
+
script.src = "./src/index.js";
|
|
22
|
+
script.type = 'module';
|
|
23
|
+
document.body.appendChild(script);
|
|
24
|
+
})();
|
|
25
|
+
</script>
|
|
26
|
+
|
|
10
27
|
</head>
|
|
11
28
|
<body>
|
|
12
29
|
</body>
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -91,6 +91,8 @@ function toggleChatIconPosition(position) {
|
|
|
91
91
|
|
|
92
92
|
// If you want to initialize your chatbot automatically when the script is loaded
|
|
93
93
|
if (typeof window !== 'undefined') {
|
|
94
|
+
console.log('привет');
|
|
95
|
+
console.log(window.wineaterClientData);
|
|
94
96
|
window.addEventListener('DOMContentLoaded', async () => {
|
|
95
97
|
const stores = ['climats', 'telckel', 'biobio', 'weinpoint'];
|
|
96
98
|
const store = stores.find(value => window.location.href.includes(value)) || null;
|
package/src/js/api.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// api.js
|
|
2
2
|
|
|
3
3
|
const stores = ['climats', 'telckel', 'biobio', 'weinpoint'];
|
|
4
|
+
const DEMO_TOKEN='OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL';
|
|
4
5
|
|
|
5
6
|
export class Api {
|
|
6
7
|
constructor(apiEndpoint) {
|
|
7
8
|
// Allow users of the library to specify their own endpoint if needed
|
|
8
9
|
this.baseURL = 'https://api.wineater.com/';
|
|
9
10
|
this.store = stores.find(value => window.location.href.includes(value));
|
|
10
|
-
|
|
11
|
+
this.token = window?.wineaterData?.CLIENT_TOKEN || DEMO_TOKEN;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
async getStoreConfig(storeName) {
|
|
@@ -16,7 +17,8 @@ export class Api {
|
|
|
16
17
|
const response = await fetch(`${this.baseURL}stores/store`, {
|
|
17
18
|
method: 'POST',
|
|
18
19
|
headers: {
|
|
19
|
-
'Content-Type': 'application/json'
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
'Authorization': `Bearer ${this.token}`
|
|
20
22
|
},
|
|
21
23
|
body: JSON.stringify({ store: storeName })
|
|
22
24
|
});
|
|
@@ -34,7 +36,8 @@ export class Api {
|
|
|
34
36
|
const response = await fetch(`${this.baseURL}dish/recommendations`, {
|
|
35
37
|
method: 'POST',
|
|
36
38
|
headers: {
|
|
37
|
-
'Content-Type': 'application/json'
|
|
39
|
+
'Content-Type': 'application/json',
|
|
40
|
+
'Authorization': `Bearer ${this.token}`
|
|
38
41
|
},
|
|
39
42
|
body: JSON.stringify({ text: text, store: this.store ? (this.store.toString().charAt(0).toUpperCase() + this.store.slice(1)) : undefined})
|
|
40
43
|
});
|