wineater-bot 1.6.1 → 1.7.1
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 +15 -11
- package/dist/wineater-chatbot.umd.js +5 -5
- package/package.json +1 -1
- package/src/index.js +3 -2
- package/src/js/api.js +2 -2
- package/src/js/chatbot.js +2 -1
|
@@ -358,7 +358,7 @@ const C = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"], T = "OuhX
|
|
|
358
358
|
class f {
|
|
359
359
|
constructor(t) {
|
|
360
360
|
var e;
|
|
361
|
-
this.baseURL = "
|
|
361
|
+
this.baseURL = "http://localhost:3000/", 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) || T;
|
|
362
362
|
}
|
|
363
363
|
async getStoreConfig(t) {
|
|
364
364
|
console.log(t);
|
|
@@ -467,9 +467,12 @@ class B {
|
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
const a = new B();
|
|
470
|
-
class
|
|
470
|
+
class S {
|
|
471
471
|
constructor() {
|
|
472
|
-
|
|
472
|
+
var e;
|
|
473
|
+
this.api = new f();
|
|
474
|
+
const t = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.FIRST_MESSAGE_TEXT) || a.translate("welcomeMessage");
|
|
475
|
+
this.displayFirstMessage(t);
|
|
473
476
|
}
|
|
474
477
|
initialize() {
|
|
475
478
|
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (n) => {
|
|
@@ -524,16 +527,17 @@ class W {
|
|
|
524
527
|
}), e.scrollTop = e.scrollHeight;
|
|
525
528
|
}
|
|
526
529
|
}
|
|
527
|
-
const
|
|
530
|
+
const W = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
528
531
|
document.addEventListener("DOMContentLoaded", () => {
|
|
529
532
|
window.toggleChatWindow = m, window.closeChatWindow = I, window.openChatWindow = E;
|
|
530
533
|
});
|
|
531
|
-
function
|
|
532
|
-
|
|
534
|
+
function L() {
|
|
535
|
+
var e;
|
|
536
|
+
const t = `
|
|
533
537
|
<div id="chatbot-container">
|
|
534
538
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
535
539
|
<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 -->
|
|
536
|
-
<span>${a.translate("chatButton")}</span>
|
|
540
|
+
<span>${((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.BUTTON_TEXT) || a.translate("chatButton")}</span>
|
|
537
541
|
</div>
|
|
538
542
|
|
|
539
543
|
<div id="chat-window" class="hidden">
|
|
@@ -558,9 +562,9 @@ function P() {
|
|
|
558
562
|
</div>
|
|
559
563
|
</div>
|
|
560
564
|
`;
|
|
561
|
-
document.body.insertAdjacentHTML("beforeend",
|
|
565
|
+
document.body.insertAdjacentHTML("beforeend", t);
|
|
562
566
|
}
|
|
563
|
-
function
|
|
567
|
+
function P() {
|
|
564
568
|
document.getElementById("close-btn").addEventListener("click", m);
|
|
565
569
|
}
|
|
566
570
|
function O() {
|
|
@@ -576,12 +580,12 @@ function M(o) {
|
|
|
576
580
|
}
|
|
577
581
|
var l;
|
|
578
582
|
if (typeof window < "u") {
|
|
579
|
-
let o = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
583
|
+
let o = ((l = window == null ? void 0 : window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
580
584
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
581
585
|
var r;
|
|
582
586
|
const e = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"].find((c) => window.location.href.includes(c)) || null;
|
|
583
587
|
let n;
|
|
584
|
-
e && (n = e.charAt(0).toUpperCase() + e.slice(1), n === "Biobio" && (o = "right-center")), await a.fetchConfig(n || "Demo"),
|
|
588
|
+
e && (n = e.charAt(0).toUpperCase() + e.slice(1), n === "Biobio" && (o = "right-center")), await a.fetchConfig(n || "Demo"), L(), P(), O(), M(o), h("chatbotToken", ((r = window.wineaterData) == null ? void 0 : r.CLIENT_TOKEN) || W, 365), x(), new S().initialize();
|
|
585
589
|
});
|
|
586
590
|
}
|
|
587
591
|
export {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.WineaterChatbot={}))})(this,function(r){"use strict";var
|
|
1
|
+
(function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.WineaterChatbot={}))})(this,function(r){"use strict";var x;const d=`
|
|
2
2
|
@font-face {
|
|
3
3
|
font-family: 'Poppins';
|
|
4
4
|
src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
|
|
@@ -277,17 +277,17 @@
|
|
|
277
277
|
.typing-indicator.visible {
|
|
278
278
|
visibility: visible;
|
|
279
279
|
height: 50px;
|
|
280
|
-
}`,p=document.createElement("style");p.textContent=d,document.head.appendChild(p);function v(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){const t=Math.random()*16|0;return(o==="x"?t:t&3|8).toString(16)})}function u(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 s(o){const t=o+"=",e=document.cookie.split(";");for(let n=0;n<e.length;n++){let i=e[n];for(;i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null}function k(){const o="uniqueUserID";let t=s(o);return t||(t=v(),u(o,t,365)),t}function c(o,t){fetch("https://api.wineater.com/proxy/track",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:o,properties:t})}).then(i=>{i.ok||console.error("Mixpanel tracking failed",i)}).catch(i=>{console.error("Mixpanel tracking error",i)})}function m(){c("Chatbot Opened",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function f(){c("Chatbot Closed",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function I(o){c("Message Sent",{distinct_id:s("uniqueUserID"),message_content:o,client:s("chatbotToken")})}function
|
|
280
|
+
}`,p=document.createElement("style");p.textContent=d,document.head.appendChild(p);function v(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){const t=Math.random()*16|0;return(o==="x"?t:t&3|8).toString(16)})}function u(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 s(o){const t=o+"=",e=document.cookie.split(";");for(let n=0;n<e.length;n++){let i=e[n];for(;i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null}function k(){const o="uniqueUserID";let t=s(o);return t||(t=v(),u(o,t,365)),t}function c(o,t){fetch("https://api.wineater.com/proxy/track",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:o,properties:t})}).then(i=>{i.ok||console.error("Mixpanel tracking failed",i)}).catch(i=>{console.error("Mixpanel tracking error",i)})}function m(){c("Chatbot Opened",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function f(){c("Chatbot Closed",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function I(o){c("Message Sent",{distinct_id:s("uniqueUserID"),message_content:o,client:s("chatbotToken")})}function E(o){c("Products Got",{distinct_id:s("uniqueUserID"),products:o,client:s("chatbotToken")})}function C(o){c("Product Clicked",{distinct_id:s("uniqueUserID"),product_id:o,client:s("chatbotToken")})}function h(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(f(),o.classList.remove("visible"),t.style.display="flex"):(m(),o.classList.add("visible"),t.style.display="none")}function b(){f(),document.getElementById("chat-window").classList.remove("visible")}function y(){m(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const T=["climats","telckel","biobio","weinpoint","vinigrandi"],B="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class w{constructor(t){var e;this.baseURL="http://localhost:3000/",this.store=T.find(n=>window.location.href.includes(n)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||B}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 W{constructor(){this.api=new w,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",reason:"Suggestion",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",reason:"Sugerencia",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",reason:"Suggestion",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",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",reason:"Anregung",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 a=new W;class S{constructor(){var e;this.api=new w;const t=((e=window==null?void 0:window.wineaterData)==null?void 0:e.FIRST_MESSAGE_TEXT)||a.translate("welcomeMessage");this.displayFirstMessage(t)}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{I(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(a.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){C(t)}displayResults(t){const e=document.getElementById("message-container");E(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 g=document.createElement("div");g.innerHTML=`
|
|
281
281
|
<strong>${n.Title}</strong><br>
|
|
282
282
|
${a.translate("price")}: ${n.Price}<br>
|
|
283
283
|
${a.translate("region")}: ${n.Region}<br>
|
|
284
284
|
${a.translate("type")}: ${n.Type}<br>
|
|
285
285
|
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
286
|
-
`,i.appendChild(g),e.appendChild(i),this.displayFirstMessage(n.Reason)}),e.scrollTop=e.scrollHeight}}const
|
|
286
|
+
`,i.appendChild(g),e.appendChild(i),this.displayFirstMessage(n.Reason)}),e.scrollTop=e.scrollHeight}}const L="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=b,window.openChatWindow=y});function P(){var e;const t=`
|
|
287
287
|
<div id="chatbot-container">
|
|
288
288
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
289
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 -->
|
|
290
|
-
<span>${a.translate("chatButton")}</span>
|
|
290
|
+
<span>${((e=window==null?void 0:window.wineaterData)==null?void 0:e.BUTTON_TEXT)||a.translate("chatButton")}</span>
|
|
291
291
|
</div>
|
|
292
292
|
|
|
293
293
|
<div id="chat-window" class="hidden">
|
|
@@ -311,4 +311,4 @@
|
|
|
311
311
|
</div>
|
|
312
312
|
</div>
|
|
313
313
|
</div>
|
|
314
|
-
`;document.body.insertAdjacentHTML("beforeend",
|
|
314
|
+
`;document.body.insertAdjacentHTML("beforeend",t)}function O(){document.getElementById("close-btn").addEventListener("click",h)}function M(){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 D(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"){let o=((x=window==null?void 0:window.wineaterData)==null?void 0:x.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var l;const e=["climats","telckel","biobio","weinpoint","vinigrandi"].find(g=>window.location.href.includes(g))||null;let n;e&&(n=e.charAt(0).toUpperCase()+e.slice(1),n==="Biobio"&&(o="right-center")),await a.fetchConfig(n||"Demo"),P(),O(),M(),D(o),u("chatbotToken",((l=window.wineaterData)==null?void 0:l.CLIENT_TOKEN)||L,365),k(),new S().initialize()})}r.closeChatWindow=b,r.openChatWindow=y,r.toggleChatWindow=h,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -28,11 +28,12 @@ export {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
function createChatbotUI() {
|
|
31
|
+
const buttonText = window?.wineaterData?.BUTTON_TEXT || translator.translate('chatButton');
|
|
31
32
|
const chatbotHTML = `
|
|
32
33
|
<div id="chatbot-container">
|
|
33
34
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
34
35
|
<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 -->
|
|
35
|
-
<span>${
|
|
36
|
+
<span>${buttonText}</span>
|
|
36
37
|
</div>
|
|
37
38
|
|
|
38
39
|
<div id="chat-window" class="hidden">
|
|
@@ -97,7 +98,7 @@ function toggleChatIconPosition(position) {
|
|
|
97
98
|
|
|
98
99
|
// If you want to initialize your chatbot automatically when the script is loaded
|
|
99
100
|
if (typeof window !== 'undefined') {
|
|
100
|
-
let position = window
|
|
101
|
+
let position = window?.wineaterData?.POSITION || 'bottom-right';
|
|
101
102
|
window.addEventListener('DOMContentLoaded', async () => {
|
|
102
103
|
const stores = ['climats', 'telckel', 'biobio', 'weinpoint', 'vinigrandi'];
|
|
103
104
|
const store = stores.find(value => window.location.href.includes(value)) || null;
|
package/src/js/api.js
CHANGED
|
@@ -6,8 +6,8 @@ const DEMO_TOKEN='OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOO
|
|
|
6
6
|
export class Api {
|
|
7
7
|
constructor(apiEndpoint) {
|
|
8
8
|
// Allow users of the library to specify their own endpoint if needed
|
|
9
|
-
this.baseURL = 'https://api.wineater.com/';
|
|
10
|
-
|
|
9
|
+
// this.baseURL = 'https://api.wineater.com/';
|
|
10
|
+
this.baseURL = 'http://localhost:3000/'
|
|
11
11
|
this.store = stores.find(value => window.location.href.includes(value));
|
|
12
12
|
this.token = window?.wineaterData?.CLIENT_TOKEN || DEMO_TOKEN;
|
|
13
13
|
}
|
package/src/js/chatbot.js
CHANGED
|
@@ -6,7 +6,8 @@ import { trackMessageSent, trackProductClick, trackRecommendationsGet } from './
|
|
|
6
6
|
export class Chatbot {
|
|
7
7
|
constructor() {
|
|
8
8
|
this.api = new Api(); // Instantiate the Api class
|
|
9
|
-
|
|
9
|
+
const firstMessageText = window?.wineaterData?.FIRST_MESSAGE_TEXT || translator.translate('welcomeMessage');
|
|
10
|
+
this.displayFirstMessage(firstMessageText);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
initialize() {
|