wineater-bot 1.5.15 → 1.5.17
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 +31 -34
- package/dist/wineater-chatbot.umd.js +8 -6
- package/package.json +1 -1
- package/src/index.js +4 -2
- package/src/js/analytics.js +5 -12
- package/src/js/i18n.js +3 -1
- package/src/js/styles.js +1 -1
|
@@ -91,7 +91,7 @@ const f = `
|
|
|
91
91
|
border-radius: 16px; /* Rounded corners for the container */
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
#powered-by span {
|
|
94
|
+
#powered-by a span {
|
|
95
95
|
font-family: 'Poppins', sans-serif;
|
|
96
96
|
color: #7E27ED; /* Text color - using the primary color from your style guide */
|
|
97
97
|
margin-right: 8px; /* Space between the text and the logo */
|
|
@@ -294,23 +294,16 @@ function r(o) {
|
|
|
294
294
|
return e.pop().split(";").shift();
|
|
295
295
|
}
|
|
296
296
|
function d(o, t) {
|
|
297
|
-
|
|
298
|
-
event: o,
|
|
299
|
-
properties: {
|
|
300
|
-
token: e,
|
|
301
|
-
...t
|
|
302
|
-
}
|
|
303
|
-
}];
|
|
304
|
-
fetch(n, {
|
|
297
|
+
fetch("https://api.wineater.com/proxy/track", {
|
|
305
298
|
method: "POST",
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}).then((
|
|
311
|
-
|
|
312
|
-
}).catch((
|
|
313
|
-
console.error("Mixpanel tracking error",
|
|
299
|
+
body: {
|
|
300
|
+
event: o,
|
|
301
|
+
properties: t
|
|
302
|
+
}
|
|
303
|
+
}).then((i) => {
|
|
304
|
+
i.ok || console.error("Mixpanel tracking failed", i);
|
|
305
|
+
}).catch((i) => {
|
|
306
|
+
console.error("Mixpanel tracking error", i);
|
|
314
307
|
});
|
|
315
308
|
}
|
|
316
309
|
function h() {
|
|
@@ -450,19 +443,21 @@ class C {
|
|
|
450
443
|
};
|
|
451
444
|
}
|
|
452
445
|
async fetchConfig(t = "Demo") {
|
|
453
|
-
|
|
446
|
+
try {
|
|
454
447
|
const e = await this.api.getStoreConfig(t);
|
|
455
448
|
this.language = e.lang;
|
|
449
|
+
} catch {
|
|
450
|
+
this.language = "en";
|
|
456
451
|
}
|
|
457
452
|
}
|
|
458
453
|
translate(t) {
|
|
459
454
|
return this.translations[this.language][t] || t;
|
|
460
455
|
}
|
|
461
456
|
}
|
|
462
|
-
const
|
|
457
|
+
const s = new C();
|
|
463
458
|
class T {
|
|
464
459
|
constructor() {
|
|
465
|
-
this.api = new m(), this.displayFirstMessage(
|
|
460
|
+
this.api = new m(), this.displayFirstMessage(s.translate("welcomeMessage"));
|
|
466
461
|
}
|
|
467
462
|
initialize() {
|
|
468
463
|
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (n) => {
|
|
@@ -482,7 +477,7 @@ class T {
|
|
|
482
477
|
const n = await this.api.getWineRecommendations(e);
|
|
483
478
|
this.hideTypingIndicator(), n && n.length ? this.displayResults(n) : this.displayMessage("No results found.", "api");
|
|
484
479
|
} catch {
|
|
485
|
-
this.hideTypingIndicator(), this.displayMessage(
|
|
480
|
+
this.hideTypingIndicator(), this.displayMessage(s.translate("somethingWentWrong"), "api");
|
|
486
481
|
}
|
|
487
482
|
}
|
|
488
483
|
}
|
|
@@ -504,15 +499,15 @@ class T {
|
|
|
504
499
|
w(t.map((n) => n.Title)), t.forEach((n) => {
|
|
505
500
|
const i = document.createElement("div");
|
|
506
501
|
i.className = "wine-item";
|
|
507
|
-
const
|
|
508
|
-
|
|
502
|
+
const a = document.createElement("img");
|
|
503
|
+
a.src = n.Image, i.appendChild(a);
|
|
509
504
|
const c = document.createElement("div");
|
|
510
505
|
c.innerHTML = `
|
|
511
506
|
<strong>${n.Title}</strong><br>
|
|
512
|
-
${
|
|
513
|
-
${
|
|
514
|
-
${
|
|
515
|
-
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${
|
|
507
|
+
${s.translate("price")}: ${n.Price}<br>
|
|
508
|
+
${s.translate("region")}: ${n.Region}<br>
|
|
509
|
+
${s.translate("type")}: ${n.Type}<br>
|
|
510
|
+
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${s.translate("moreInfo")}</a>
|
|
516
511
|
`, i.appendChild(c), e.appendChild(i);
|
|
517
512
|
}), e.scrollTop = e.scrollHeight;
|
|
518
513
|
}
|
|
@@ -526,14 +521,16 @@ function W() {
|
|
|
526
521
|
<div id="chatbot-container">
|
|
527
522
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
528
523
|
<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 -->
|
|
529
|
-
<span>${
|
|
524
|
+
<span>${s.translate("chatButton")}</span>
|
|
530
525
|
</div>
|
|
531
526
|
|
|
532
527
|
<div id="chat-window" class="hidden">
|
|
533
528
|
<div id="chat-header">
|
|
534
529
|
<div id="powered-by">
|
|
535
|
-
<
|
|
536
|
-
|
|
530
|
+
<a href="https://wineater.com" target="_blank" style="text-decoration: none; color: inherit;">
|
|
531
|
+
<span>Powered by</span>
|
|
532
|
+
<img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/logo.svg" alt="Wineater Logo" id="chatbot-logo">
|
|
533
|
+
</a>
|
|
537
534
|
</div>
|
|
538
535
|
<div id="close-btn">×</div>
|
|
539
536
|
</div>
|
|
@@ -543,8 +540,8 @@ function W() {
|
|
|
543
540
|
<span></span><span></span><span></span>
|
|
544
541
|
</div>
|
|
545
542
|
<div id="input-container">
|
|
546
|
-
<input type="text" id="user-input" placeholder="${
|
|
547
|
-
<button id="send-button">${
|
|
543
|
+
<input type="text" id="user-input" placeholder="${s.translate("inputPlaceholder")}">
|
|
544
|
+
<button id="send-button">${s.translate("sendButton")}</button>
|
|
548
545
|
</div>
|
|
549
546
|
</div>
|
|
550
547
|
</div>
|
|
@@ -569,10 +566,10 @@ var l;
|
|
|
569
566
|
if (typeof window < "u") {
|
|
570
567
|
const o = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
571
568
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
572
|
-
var
|
|
569
|
+
var a;
|
|
573
570
|
const e = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"].find((c) => window.location.href.includes(c)) || null;
|
|
574
571
|
let n;
|
|
575
|
-
e && (n = e.charAt(0).toUpperCase() + e.slice(1)), await
|
|
572
|
+
e && (n = e.charAt(0).toUpperCase() + e.slice(1)), await s.fetchConfig(n || "Demo"), W(), P(), L(), S(o), b("chatbotToken", ((a = window.wineaterData) == null ? void 0 : a.CLIENT_TOKEN) || B, 365), new T().initialize();
|
|
576
573
|
});
|
|
577
574
|
}
|
|
578
575
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(r
|
|
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";var w;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');
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
border-radius: 16px; /* Rounded corners for the container */
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
#powered-by span {
|
|
94
|
+
#powered-by a span {
|
|
95
95
|
font-family: 'Poppins', sans-serif;
|
|
96
96
|
color: #7E27ED; /* Text color - using the primary color from your style guide */
|
|
97
97
|
margin-right: 8px; /* Space between the text and the logo */
|
|
@@ -277,7 +277,7 @@
|
|
|
277
277
|
.typing-indicator.visible {
|
|
278
278
|
visibility: visible;
|
|
279
279
|
height: 50px;
|
|
280
|
-
}`,g=document.createElement("style");g.textContent=
|
|
280
|
+
}`,g=document.createElement("style");g.textContent=r,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 d(o){const e=`; ${document.cookie}`.split(`; ${o}=`);if(e.length===2)return e.pop().split(";").shift()}function c(o,t){fetch("https://api.wineater.com/proxy/track",{method:"POST",body:{event:o,properties:t}}).then(i=>{i.ok||console.error("Mixpanel tracking failed",i)}).catch(i=>{console.error("Mixpanel tracking error",i)})}function u(){c("Chatbot Opened",{distinct_id:d("chatbotToken")})}function m(){c("Chatbot Closed",{distinct_id:d("chatbotToken")})}function v(o){c("Message Sent",{distinct_id:d("chatbotToken"),message_content:o})}function k(o){c("Message Sent",{distinct_id:d("chatbotToken"),products:o})}function E(o){c("Product Clicked",{distinct_id:d("chatbotToken"),product_id:o})}function h(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(m(),o.classList.remove("visible"),t.style.display="flex"):(u(),o.classList.add("visible"),t.style.display="none")}function f(){m(),document.getElementById("chat-window").classList.remove("visible")}function b(){u(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const C=["climats","telckel","biobio","weinpoint"],I="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=C.find(n=>window.location.href.includes(n)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||I}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),n=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${n.message||"No additional error information"}`);return n}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class T{constructor(){this.api=new y,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},de:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"},de:{welcomeMessage:"Verbessern Sie Ihr kulinarisches Erlebnis. Geben Sie einfach die Details Ihres Gerichts an und erhalten Sie die ideale Weinempfehlung. Was möchten Sie essen?",noResultsFound:"Keine Ergebnisse gefunden.",somethingWentWrong:"Entschuldigung, etwas ist schief gelaufen.",chatButton:"Wein zum Abendessen kombinieren",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",moreInfo:"Mehr Info"}}}async fetchConfig(t="Demo"){try{const e=await this.api.getStoreConfig(t);this.language=e.lang}catch{this.language="en"}}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 l=document.createElement("img");l.src=n.Image,i.appendChild(l);const p=document.createElement("div");p.innerHTML=`
|
|
281
281
|
<strong>${n.Title}</strong><br>
|
|
282
282
|
${s.translate("price")}: ${n.Price}<br>
|
|
283
283
|
${s.translate("region")}: ${n.Region}<br>
|
|
@@ -293,8 +293,10 @@
|
|
|
293
293
|
<div id="chat-window" class="hidden">
|
|
294
294
|
<div id="chat-header">
|
|
295
295
|
<div id="powered-by">
|
|
296
|
-
<
|
|
297
|
-
|
|
296
|
+
<a href="https://wineater.com" target="_blank" style="text-decoration: none; color: inherit;">
|
|
297
|
+
<span>Powered by</span>
|
|
298
|
+
<img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/logo.svg" alt="Wineater Logo" id="chatbot-logo">
|
|
299
|
+
</a>
|
|
298
300
|
</div>
|
|
299
301
|
<div id="close-btn">×</div>
|
|
300
302
|
</div>
|
|
@@ -309,4 +311,4 @@
|
|
|
309
311
|
</div>
|
|
310
312
|
</div>
|
|
311
313
|
</div>
|
|
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
|
|
314
|
+
`;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 l;const e=["climats","telckel","biobio","weinpoint","vinigrandi"].find(p=>window.location.href.includes(p))||null;let n;e&&(n=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(n||"Demo"),P(),L(),S(),O(o),x("chatbotToken",((l=window.wineaterData)==null?void 0:l.CLIENT_TOKEN)||B,365),new W().initialize()})}a.closeChatWindow=f,a.openChatWindow=b,a.toggleChatWindow=h,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -38,8 +38,10 @@ function createChatbotUI() {
|
|
|
38
38
|
<div id="chat-window" class="hidden">
|
|
39
39
|
<div id="chat-header">
|
|
40
40
|
<div id="powered-by">
|
|
41
|
-
<
|
|
42
|
-
|
|
41
|
+
<a href="https://wineater.com" target="_blank" style="text-decoration: none; color: inherit;">
|
|
42
|
+
<span>Powered by</span>
|
|
43
|
+
<img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/logo.svg" alt="Wineater Logo" id="chatbot-logo">
|
|
44
|
+
</a>
|
|
43
45
|
</div>
|
|
44
46
|
<div id="close-btn">×</div>
|
|
45
47
|
</div>
|
package/src/js/analytics.js
CHANGED
|
@@ -18,22 +18,15 @@ function setCookie(name, value, days) {
|
|
|
18
18
|
|
|
19
19
|
// Функция для отправки событий в Mixpanel
|
|
20
20
|
function trackEvent(event, properties) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const data = [{
|
|
21
|
+
const endpoint = 'https://api.wineater.com/proxy/track';
|
|
22
|
+
const data = {
|
|
24
23
|
event,
|
|
25
|
-
properties
|
|
26
|
-
|
|
27
|
-
...properties
|
|
28
|
-
}
|
|
29
|
-
}];
|
|
24
|
+
properties
|
|
25
|
+
};
|
|
30
26
|
|
|
31
27
|
fetch(endpoint, {
|
|
32
28
|
method: 'POST',
|
|
33
|
-
|
|
34
|
-
'content-type': 'application/json'
|
|
35
|
-
},
|
|
36
|
-
body: JSON.stringify(data)
|
|
29
|
+
body: data
|
|
37
30
|
}).then(response => {
|
|
38
31
|
if (!response.ok) {
|
|
39
32
|
console.error('Mixpanel tracking failed', response);
|
package/src/js/i18n.js
CHANGED
package/src/js/styles.js
CHANGED
|
@@ -92,7 +92,7 @@ const css = `
|
|
|
92
92
|
border-radius: 16px; /* Rounded corners for the container */
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
#powered-by span {
|
|
95
|
+
#powered-by a span {
|
|
96
96
|
font-family: 'Poppins', sans-serif;
|
|
97
97
|
color: #7E27ED; /* Text color - using the primary color from your style guide */
|
|
98
98
|
margin-right: 8px; /* Space between the text and the logo */
|