wineater-bot 1.1.2 → 1.1.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.
@@ -245,45 +245,47 @@ function p() {
245
245
  document.addEventListener("DOMContentLoaded", () => {
246
246
  setupCloseButton(), setupOutsideClick();
247
247
  });
248
- class g {
248
+ const g = ["climats", "telckel", "biobio"];
249
+ class h {
249
250
  constructor(n) {
250
- this.apiEndpoint = n || "https://api.wineater.com/dish/recommendations";
251
+ this.apiEndpoint = n || "https://api.wineater.com/dish/recommendations", this.store = g.find((e) => window.location.href.includes(e)), console.log(this.store);
251
252
  }
252
253
  async getWineRecommendations(n) {
254
+ console.log(window.location.href);
253
255
  try {
254
- const t = await fetch(this.apiEndpoint, {
256
+ const e = await fetch(this.apiEndpoint, {
255
257
  method: "POST",
256
258
  headers: {
257
259
  "Content-Type": "application/json"
258
260
  },
259
- body: JSON.stringify({ text: n })
260
- }), e = await t.json();
261
- if (!t.ok)
262
- throw new Error(`API call failed with status ${t.status}: ${e.message || "No additional error information"}`);
263
- return e;
264
- } catch (t) {
265
- throw console.error("Fetching wine recommendations failed:", t.message), new Error(`Error in getWineRecommendations: ${t.message}`);
261
+ body: JSON.stringify({ text: n, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
262
+ }), t = await e.json();
263
+ if (!e.ok)
264
+ throw new Error(`API call failed with status ${e.status}: ${t.message || "No additional error information"}`);
265
+ return t;
266
+ } catch (e) {
267
+ throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
266
268
  }
267
269
  }
268
270
  }
269
- class h {
271
+ class u {
270
272
  constructor() {
271
- this.api = new g();
273
+ this.api = new h();
272
274
  }
273
275
  initialize() {
274
- document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (e) => {
275
- e.key === "Enter" && this.handleUserInput();
276
+ document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (t) => {
277
+ t.key === "Enter" && this.handleUserInput();
276
278
  });
277
279
  }
278
280
  async handleUserInput() {
279
- const n = document.getElementById("user-input"), t = n.value.trim();
280
- if (t) {
281
- this.displayMessage(t, "user"), n.value = "", this.showTypingIndicator();
281
+ const n = document.getElementById("user-input"), e = n.value.trim();
282
+ if (e) {
283
+ this.displayMessage(e, "user"), n.value = "", this.showTypingIndicator();
282
284
  try {
283
- const e = await this.api.getWineRecommendations(t);
284
- this.hideTypingIndicator(), e && e.length ? this.displayResults(e) : this.displayMessage("No results found.", "api");
285
- } catch (e) {
286
- this.hideTypingIndicator(), console.error("Error fetching wine recommendations:", e), this.displayMessage("Sorry, something went wrong.", "api");
285
+ const t = await this.api.getWineRecommendations(e);
286
+ this.hideTypingIndicator(), t && t.length ? this.displayResults(t) : this.displayMessage("No results found.", "api");
287
+ } catch (t) {
288
+ this.hideTypingIndicator(), console.error("Error fetching wine recommendations:", t), this.displayMessage("Sorry, something went wrong.", "api");
287
289
  }
288
290
  }
289
291
  }
@@ -293,26 +295,26 @@ class h {
293
295
  hideTypingIndicator() {
294
296
  document.getElementById("typing-indicator").classList.remove("visible");
295
297
  }
296
- displayMessage(n, t) {
297
- const e = document.getElementById("message-container"), o = document.createElement("div");
298
- o.textContent = n, o.className = "message " + t, e.appendChild(o), e.scrollTop = e.scrollHeight;
298
+ displayMessage(n, e) {
299
+ const t = document.getElementById("message-container"), o = document.createElement("div");
300
+ o.textContent = n, o.className = "message " + e, t.appendChild(o), t.scrollTop = t.scrollHeight;
299
301
  }
300
302
  displayResults(n) {
301
- const t = document.getElementById("message-container");
302
- n.forEach((e) => {
303
+ const e = document.getElementById("message-container");
304
+ n.forEach((t) => {
303
305
  const o = document.createElement("div");
304
306
  o.className = "wine-item";
305
- const a = document.createElement("img");
306
- a.src = e.Image, o.appendChild(a);
307
- const s = document.createElement("div");
308
- s.innerHTML = `<strong>${e.Title}</strong><br>Price: ${e.Price}<br>Region: ${e.Region}<br>Type: ${e.Type}<br><a href="${e.Url}" target="_blank">More Info</a>`, o.appendChild(s), t.appendChild(o);
309
- }), t.scrollTop = t.scrollHeight;
307
+ const s = document.createElement("img");
308
+ s.src = t.Image, o.appendChild(s);
309
+ const a = document.createElement("div");
310
+ a.innerHTML = `<strong>${t.Title}</strong><br>Price: ${t.Price}<br>Region: ${t.Region}<br>Type: ${t.Type}<br><a href="${t.Url}" target="_blank">More Info</a>`, o.appendChild(a), e.appendChild(o);
311
+ }), e.scrollTop = e.scrollHeight;
310
312
  }
311
313
  }
312
314
  document.addEventListener("DOMContentLoaded", () => {
313
315
  window.toggleChatWindow = d, window.closeChatWindow = l, window.openChatWindow = p;
314
316
  });
315
- function u() {
317
+ function m() {
316
318
  document.body.insertAdjacentHTML("beforeend", `
317
319
  <div id="chatbot-container">
318
320
  <div id="chat-icon" onclick="toggleChatWindow()">
@@ -336,17 +338,17 @@ function u() {
336
338
  </div>
337
339
  `);
338
340
  }
339
- function m() {
341
+ function b() {
340
342
  document.getElementById("close-btn").addEventListener("click", d);
341
343
  }
342
- function b() {
344
+ function f() {
343
345
  window.addEventListener("click", function(i) {
344
- const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
345
- !n.contains(i.target) && !t.contains(i.target) && n.classList.remove("visible");
346
+ const n = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
347
+ !n.contains(i.target) && !e.contains(i.target) && n.classList.remove("visible");
346
348
  });
347
349
  }
348
350
  typeof window < "u" && window.addEventListener("DOMContentLoaded", () => {
349
- u(), m(), b(), new h().initialize();
351
+ m(), b(), f(), new u().initialize();
350
352
  });
351
353
  export {
352
354
  l as closeChatWindow,
@@ -1,4 +1,4 @@
1
- (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.WineaterChatbot={}))})(this,function(o){"use strict";const s=`
1
+ (function(o,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(o=typeof globalThis<"u"?globalThis:o||self,a(o.WineaterChatbot={}))})(this,function(o){"use strict";const a=`
2
2
  @font-face {
3
3
  font-family: 'Poppins';
4
4
  src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
@@ -230,7 +230,7 @@
230
230
  overflow-y: auto;
231
231
  height: 300px; /* adjust based on your UI needs */
232
232
  padding: 10px;
233
- }`,r=document.createElement("style");r.textContent=s,document.head.appendChild(r);function d(){document.getElementById("chat-window").classList.toggle("visible")}function c(){document.getElementById("chat-window").classList.remove("visible")}function l(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});class h{constructor(n){this.apiEndpoint=n||"https://api.wineater.com/dish/recommendations"}async getWineRecommendations(n){try{const t=await fetch(this.apiEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:n})}),e=await t.json();if(!t.ok)throw new Error(`API call failed with status ${t.status}: ${e.message||"No additional error information"}`);return e}catch(t){throw console.error("Fetching wine recommendations failed:",t.message),new Error(`Error in getWineRecommendations: ${t.message}`)}}}class u{constructor(){this.api=new h}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",e=>{e.key==="Enter"&&this.handleUserInput()})}async handleUserInput(){const n=document.getElementById("user-input"),t=n.value.trim();if(t){this.displayMessage(t,"user"),n.value="",this.showTypingIndicator();try{const e=await this.api.getWineRecommendations(t);this.hideTypingIndicator(),e&&e.length?this.displayResults(e):this.displayMessage("No results found.","api")}catch(e){this.hideTypingIndicator(),console.error("Error fetching wine recommendations:",e),this.displayMessage("Sorry, something went wrong.","api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(n,t){const e=document.getElementById("message-container"),a=document.createElement("div");a.textContent=n,a.className="message "+t,e.appendChild(a),e.scrollTop=e.scrollHeight}displayResults(n){const t=document.getElementById("message-container");n.forEach(e=>{const a=document.createElement("div");a.className="wine-item";const p=document.createElement("img");p.src=e.Image,a.appendChild(p);const g=document.createElement("div");g.innerHTML=`<strong>${e.Title}</strong><br>Price: ${e.Price}<br>Region: ${e.Region}<br>Type: ${e.Type}<br><a href="${e.Url}" target="_blank">More Info</a>`,a.appendChild(g),t.appendChild(a)}),t.scrollTop=t.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=d,window.closeChatWindow=c,window.openChatWindow=l});function m(){document.body.insertAdjacentHTML("beforeend",`
233
+ }`,d=document.createElement("style");d.textContent=a,document.head.appendChild(d);function r(){document.getElementById("chat-window").classList.toggle("visible")}function c(){document.getElementById("chat-window").classList.remove("visible")}function l(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const g=["climats","telckel","biobio"];class u{constructor(n){this.apiEndpoint=n||"https://api.wineater.com/dish/recommendations",this.store=g.find(e=>window.location.href.includes(e)),console.log(this.store)}async getWineRecommendations(n){console.log(window.location.href);try{const e=await fetch(this.apiEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:n,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),t=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${t.message||"No additional error information"}`);return t}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class m{constructor(){this.api=new u}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",t=>{t.key==="Enter"&&this.handleUserInput()})}async handleUserInput(){const n=document.getElementById("user-input"),e=n.value.trim();if(e){this.displayMessage(e,"user"),n.value="",this.showTypingIndicator();try{const t=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),t&&t.length?this.displayResults(t):this.displayMessage("No results found.","api")}catch(t){this.hideTypingIndicator(),console.error("Error fetching wine recommendations:",t),this.displayMessage("Sorry, something went wrong.","api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(n,e){const t=document.getElementById("message-container"),s=document.createElement("div");s.textContent=n,s.className="message "+e,t.appendChild(s),t.scrollTop=t.scrollHeight}displayResults(n){const e=document.getElementById("message-container");n.forEach(t=>{const s=document.createElement("div");s.className="wine-item";const p=document.createElement("img");p.src=t.Image,s.appendChild(p);const h=document.createElement("div");h.innerHTML=`<strong>${t.Title}</strong><br>Price: ${t.Price}<br>Region: ${t.Region}<br>Type: ${t.Type}<br><a href="${t.Url}" target="_blank">More Info</a>`,s.appendChild(h),e.appendChild(s)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=r,window.closeChatWindow=c,window.openChatWindow=l});function b(){document.body.insertAdjacentHTML("beforeend",`
234
234
  <div id="chatbot-container">
235
235
  <div id="chat-icon" onclick="toggleChatWindow()">
236
236
  <img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon">
@@ -251,4 +251,4 @@
251
251
  </div>
252
252
  </div>
253
253
  </div>
254
- `)}function b(){document.getElementById("close-btn").addEventListener("click",d)}function f(){window.addEventListener("click",function(i){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");!n.contains(i.target)&&!t.contains(i.target)&&n.classList.remove("visible")})}typeof window<"u"&&window.addEventListener("DOMContentLoaded",()=>{m(),b(),f(),new u().initialize()}),o.closeChatWindow=c,o.openChatWindow=l,o.toggleChatWindow=d,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
254
+ `)}function f(){document.getElementById("close-btn").addEventListener("click",r)}function y(){window.addEventListener("click",function(i){const n=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!n.contains(i.target)&&!e.contains(i.target)&&n.classList.remove("visible")})}typeof window<"u"&&window.addEventListener("DOMContentLoaded",()=>{b(),f(),y(),new m().initialize()}),o.closeChatWindow=c,o.openChatWindow=l,o.toggleChatWindow=r,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/index.html CHANGED
@@ -4,7 +4,9 @@
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Chatbot</title>
7
- <script src="https://unpkg.com/wineater-bot@latest/dist/wineater-chatbot.umd.js"></script>
7
+ <!-- <script type="module" src="https://unpkg.com/wineater-bot@1.0.0/dist/wineater-chatbot.umd.js"></script> -->
8
+ <script type="module" src="./src/index.js"></script>
9
+
8
10
  </head>
9
11
  <body>
10
12
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/js/api.js CHANGED
@@ -1,19 +1,24 @@
1
1
  // api.js
2
2
 
3
+ const stores = ['climats', 'telckel', 'biobio'];
4
+
3
5
  export class Api {
4
6
  constructor(apiEndpoint) {
5
7
  // Allow users of the library to specify their own endpoint if needed
6
8
  this.apiEndpoint = apiEndpoint || 'https://api.wineater.com/dish/recommendations';
9
+ this.store = stores.find(value => window.location.href.includes(value));
10
+ console.log(this.store);
7
11
  }
8
12
 
9
13
  async getWineRecommendations(text) {
14
+ console.log(window.location.href);
10
15
  try {
11
16
  const response = await fetch(this.apiEndpoint, {
12
17
  method: 'POST',
13
18
  headers: {
14
19
  'Content-Type': 'application/json'
15
20
  },
16
- body: JSON.stringify({ text: text })
21
+ body: JSON.stringify({ text: text, store: this.store ? (this.store.toString().charAt(0).toUpperCase() + this.store.slice(1)) : undefined})
17
22
  });
18
23
 
19
24
  const data = await response.json();