wineater-bot 1.5.23 → 1.5.24
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 +7 -7
- package/dist/wineater-chatbot.umd.js +2 -2
- package/index.html +3 -2
- package/package.json +1 -1
- package/src/assets/biobio.png +0 -0
- package/src/index.js +5 -2
|
@@ -286,7 +286,7 @@ function y() {
|
|
|
286
286
|
return (o === "x" ? t : t & 3 | 8).toString(16);
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
|
-
function
|
|
289
|
+
function g(o, t, e) {
|
|
290
290
|
let n = "";
|
|
291
291
|
if (e) {
|
|
292
292
|
const i = /* @__PURE__ */ new Date();
|
|
@@ -308,7 +308,7 @@ function s(o) {
|
|
|
308
308
|
function x() {
|
|
309
309
|
const o = "uniqueUserID";
|
|
310
310
|
let t = s(o);
|
|
311
|
-
return t || (t = y(),
|
|
311
|
+
return t || (t = y(), g(o, t, 365)), t;
|
|
312
312
|
}
|
|
313
313
|
function d(o, t) {
|
|
314
314
|
fetch("https://api.wineater.com/proxy/track", {
|
|
@@ -326,7 +326,7 @@ function d(o, t) {
|
|
|
326
326
|
console.error("Mixpanel tracking error", i);
|
|
327
327
|
});
|
|
328
328
|
}
|
|
329
|
-
function
|
|
329
|
+
function p() {
|
|
330
330
|
d("Chatbot Opened", { distinct_id: s("uniqueUserID"), client: s("chatbotToken") });
|
|
331
331
|
}
|
|
332
332
|
function u() {
|
|
@@ -343,13 +343,13 @@ function k(o) {
|
|
|
343
343
|
}
|
|
344
344
|
function m() {
|
|
345
345
|
const o = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
346
|
-
o.classList.contains("visible") ? (u(), o.classList.remove("visible"), t.style.display = "flex") : (
|
|
346
|
+
o.classList.contains("visible") ? (u(), o.classList.remove("visible"), t.style.display = "flex") : (p(), o.classList.add("visible"), t.style.display = "none");
|
|
347
347
|
}
|
|
348
348
|
function I() {
|
|
349
349
|
u(), document.getElementById("chat-window").classList.remove("visible");
|
|
350
350
|
}
|
|
351
351
|
function E() {
|
|
352
|
-
|
|
352
|
+
p(), document.getElementById("chat-window").classList.add("visible");
|
|
353
353
|
}
|
|
354
354
|
document.addEventListener("DOMContentLoaded", () => {
|
|
355
355
|
setupCloseButton(), setupOutsideClick();
|
|
@@ -584,12 +584,12 @@ function D(o) {
|
|
|
584
584
|
}
|
|
585
585
|
var l;
|
|
586
586
|
if (typeof window < "u") {
|
|
587
|
-
|
|
587
|
+
let o = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
588
588
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
589
589
|
var r;
|
|
590
590
|
const e = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"].find((c) => window.location.href.includes(c)) || null;
|
|
591
591
|
let n;
|
|
592
|
-
e && (n = e.charAt(0).toUpperCase() + e.slice(1)), await a.fetchConfig(n || "Demo"), L(), S(), O(), D(o),
|
|
592
|
+
e && (n = e.charAt(0).toUpperCase() + e.slice(1), n === "Biobio" && (o = "right-center")), await a.fetchConfig(n || "Demo"), L(), S(), O(), D(o), g("chatbotToken", ((r = window.wineaterData) == null ? void 0 : r.CLIENT_TOKEN) || P, 365), x(), new W().initialize();
|
|
593
593
|
});
|
|
594
594
|
}
|
|
595
595
|
export {
|
|
@@ -277,7 +277,7 @@
|
|
|
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 g(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(),g(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 C(o){c("Products Got",{distinct_id:s("uniqueUserID"),products:o,client:s("chatbotToken")})}function E(o){c("Product Clicked",{distinct_id:s("uniqueUserID"),product_id:o,client:s("chatbotToken")})}function u(){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"],
|
|
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 g(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(),g(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 C(o){c("Products Got",{distinct_id:s("uniqueUserID"),products:o,client:s("chatbotToken")})}function E(o){c("Product Clicked",{distinct_id:s("uniqueUserID"),product_id:o,client:s("chatbotToken")})}function u(){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 x{constructor(t){var e;this.baseURL="https://api.wineater.com/",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 x,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",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 a=new W;class P{constructor(){this.api=new x,this.displayFirstMessage(a.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{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){E(t)}displayResults(t){const e=document.getElementById("message-container");C(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 h=document.createElement("div");h.innerHTML=`
|
|
281
281
|
<strong>${n.Title}</strong><br>
|
|
282
282
|
${a.translate("price")}: ${n.Price}<br>
|
|
283
283
|
${a.translate("region")}: ${n.Region}<br>
|
|
@@ -311,4 +311,4 @@
|
|
|
311
311
|
</div>
|
|
312
312
|
</div>
|
|
313
313
|
</div>
|
|
314
|
-
`;document.body.insertAdjacentHTML("beforeend",o)}function O(){document.getElementById("close-btn").addEventListener("click",u)}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"){
|
|
314
|
+
`;document.body.insertAdjacentHTML("beforeend",o)}function O(){document.getElementById("close-btn").addEventListener("click",u)}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=((w=window.wineaterData)==null?void 0:w.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var l;const e=["climats","telckel","biobio","weinpoint","vinigrandi"].find(h=>window.location.href.includes(h))||null;let n;e&&(n=e.charAt(0).toUpperCase()+e.slice(1),n==="Biobio"&&(o="right-center")),await a.fetchConfig(n||"Demo"),S(),O(),M(),D(o),g("chatbotToken",((l=window.wineaterData)==null?void 0:l.CLIENT_TOKEN)||L,365),k(),new P().initialize()})}r.closeChatWindow=b,r.openChatWindow=y,r.toggleChatWindow=u,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/index.html
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
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>window.wineaterData = {CLIENT_TOKEN: '
|
|
8
|
+
<script>window.wineaterData = {CLIENT_TOKEN: 'K0ZzlrfT0z00J6dSAt8ZEIKWiUfypG1Tyb1ZGtgwuJaF8WZuRKlHfvEMCF9DyytZ'};</script><script type="module" src="./src/index.js"></script>
|
|
9
9
|
</head>
|
|
10
|
-
<body>
|
|
10
|
+
<body style="margin: 0;">
|
|
11
|
+
<img src="./src/assets/biobio.png" style="width: 100vw; height: 100vh; margin: 0;">
|
|
11
12
|
</body>
|
|
12
13
|
</html>
|
package/package.json
CHANGED
|
Binary file
|
package/src/index.js
CHANGED
|
@@ -97,13 +97,16 @@ function toggleChatIconPosition(position) {
|
|
|
97
97
|
|
|
98
98
|
// If you want to initialize your chatbot automatically when the script is loaded
|
|
99
99
|
if (typeof window !== 'undefined') {
|
|
100
|
-
|
|
100
|
+
let position = window.wineaterData?.POSITION || 'bottom-right';
|
|
101
101
|
window.addEventListener('DOMContentLoaded', async () => {
|
|
102
102
|
const stores = ['climats', 'telckel', 'biobio', 'weinpoint', 'vinigrandi'];
|
|
103
103
|
const store = stores.find(value => window.location.href.includes(value)) || null;
|
|
104
104
|
let capitalizeStore;
|
|
105
105
|
if (store) {
|
|
106
|
-
capitalizeStore = store.charAt(0).toUpperCase() + store.slice(1)
|
|
106
|
+
capitalizeStore = store.charAt(0).toUpperCase() + store.slice(1);
|
|
107
|
+
if (capitalizeStore === 'Biobio') {
|
|
108
|
+
position = 'right-center';
|
|
109
|
+
}
|
|
107
110
|
}
|
|
108
111
|
await translator.fetchConfig(capitalizeStore || 'Demo');
|
|
109
112
|
createChatbotUI(); // Create the UI
|