wineater-bot 1.1.4 → 1.1.6

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.
@@ -26,9 +26,28 @@ const g = `
26
26
  border-radius: 20px; /* Rounded corners for the button */
27
27
  background-color: #fff; /* Background color from your style guide */
28
28
  cursor: pointer;
29
+ box-sizing: content-box;
29
30
  box-shadow: 0 2px 10px rgba(0,0,0,0.2); /* Optional: add shadow for depth */
30
31
  }
31
32
 
33
+ /* Position class for bottom-right */
34
+ .chat-icon-bottom-right {
35
+ position: fixed;
36
+ bottom: 20px;
37
+ right: 20px;
38
+ /* Other styles for the bottom-right button */
39
+ /* ... */
40
+ }
41
+
42
+ .chat-icon-right-center {
43
+ position: fixed;
44
+ top: 50%;
45
+ right: -100px;
46
+ transform: translateY(-50%) rotate(90deg);
47
+ /* Additional styling for the button */
48
+ /* ... */
49
+ }
50
+
32
51
  #chat-icon img {
33
52
  width: 40px; /* Adjust icon size as needed */
34
53
  height: auto;
@@ -43,13 +62,13 @@ const g = `
43
62
 
44
63
  /* Chat window styles */
45
64
  #chat-window {
65
+ position: fixed;
66
+ bottom: 20px; /* Set to the desired distance from the bottom */
67
+ right: 20px; /* Set to the desired distance from the right */
46
68
  width: 350px; /* Width of the chat window */
47
69
  background-color: white;
48
70
  border-radius: 8px;
49
71
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
50
- position: absolute;
51
- bottom: 80px; /* Positioning from the bottom */
52
- right: 0;
53
72
  display: none; /* Initially hidden */
54
73
  }
55
74
 
@@ -261,21 +280,22 @@ const g = `
261
280
  d.textContent = g;
262
281
  document.head.appendChild(d);
263
282
  function c() {
264
- document.getElementById("chat-window").classList.toggle("visible");
283
+ const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
284
+ n.classList.contains("visible") ? (n.classList.remove("visible"), t.style.display = "flex") : (n.classList.add("visible"), t.style.display = "none");
265
285
  }
266
286
  function h() {
267
287
  document.getElementById("chat-window").classList.remove("visible");
268
288
  }
269
- function u() {
289
+ function m() {
270
290
  document.getElementById("chat-window").classList.add("visible");
271
291
  }
272
292
  document.addEventListener("DOMContentLoaded", () => {
273
293
  setupCloseButton(), setupOutsideClick();
274
294
  });
275
- const m = ["climats", "telckel", "biobio"];
295
+ const u = ["climats", "telckel", "biobio"];
276
296
  class f {
277
297
  constructor(t) {
278
- this.apiEndpoint = t || "https://api.wineater.com/dish/recommendations", this.store = m.find((e) => window.location.href.includes(e)), console.log(this.store);
298
+ this.apiEndpoint = t || "https://api.wineater.com/dish/recommendations", this.store = u.find((e) => window.location.href.includes(e)), console.log(this.store);
279
299
  }
280
300
  async getWineRecommendations(t) {
281
301
  console.log(window.location.href);
@@ -350,7 +370,7 @@ class b {
350
370
  }
351
371
  }
352
372
  document.addEventListener("DOMContentLoaded", () => {
353
- window.toggleChatWindow = c, window.closeChatWindow = h, window.openChatWindow = u;
373
+ window.toggleChatWindow = c, window.closeChatWindow = h, window.openChatWindow = m;
354
374
  });
355
375
  function y() {
356
376
  document.body.insertAdjacentHTML("beforeend", `
@@ -387,14 +407,19 @@ function w() {
387
407
  function x() {
388
408
  window.addEventListener("click", function(n) {
389
409
  const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
390
- !t.contains(n.target) && !e.contains(n.target) && t.classList.remove("visible");
410
+ !t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
391
411
  });
392
412
  }
413
+ function v(n) {
414
+ console.log(n);
415
+ const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
416
+ 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
+ }
393
418
  typeof window < "u" && window.addEventListener("DOMContentLoaded", () => {
394
- y(), w(), x(), new b().initialize();
419
+ y(), w(), x(), v("right-center"), new b().initialize();
395
420
  });
396
421
  export {
397
422
  h as closeChatWindow,
398
- u as openChatWindow,
423
+ m as openChatWindow,
399
424
  c as toggleChatWindow
400
425
  };
@@ -1,4 +1,4 @@
1
- (function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.WineaterChatbot={}))})(this,function(n){"use strict";var x=Object.defineProperty;var v=(n,i,r)=>i in n?x(n,i,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[i]=r;var h=(n,i,r)=>(v(n,typeof i!="symbol"?i+"":i,r),r);const i=`
1
+ (function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i.WineaterChatbot={}))})(this,function(i){"use strict";var v=Object.defineProperty;var E=(i,s,r)=>s in i?v(i,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[s]=r;var h=(i,s,r)=>(E(i,typeof s!="symbol"?s+"":s,r),r);const s=`
2
2
  @font-face {
3
3
  font-family: 'Poppins';
4
4
  src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
@@ -23,9 +23,28 @@
23
23
  border-radius: 20px; /* Rounded corners for the button */
24
24
  background-color: #fff; /* Background color from your style guide */
25
25
  cursor: pointer;
26
+ box-sizing: content-box;
26
27
  box-shadow: 0 2px 10px rgba(0,0,0,0.2); /* Optional: add shadow for depth */
27
28
  }
28
29
 
30
+ /* Position class for bottom-right */
31
+ .chat-icon-bottom-right {
32
+ position: fixed;
33
+ bottom: 20px;
34
+ right: 20px;
35
+ /* Other styles for the bottom-right button */
36
+ /* ... */
37
+ }
38
+
39
+ .chat-icon-right-center {
40
+ position: fixed;
41
+ top: 50%;
42
+ right: -100px;
43
+ transform: translateY(-50%) rotate(90deg);
44
+ /* Additional styling for the button */
45
+ /* ... */
46
+ }
47
+
29
48
  #chat-icon img {
30
49
  width: 40px; /* Adjust icon size as needed */
31
50
  height: auto;
@@ -40,13 +59,13 @@
40
59
 
41
60
  /* Chat window styles */
42
61
  #chat-window {
62
+ position: fixed;
63
+ bottom: 20px; /* Set to the desired distance from the bottom */
64
+ right: 20px; /* Set to the desired distance from the right */
43
65
  width: 350px; /* Width of the chat window */
44
66
  background-color: white;
45
67
  border-radius: 8px;
46
68
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
47
- position: absolute;
48
- bottom: 80px; /* Positioning from the bottom */
49
- right: 0;
50
69
  display: none; /* Initially hidden */
51
70
  }
52
71
 
@@ -254,13 +273,13 @@
254
273
  .typing-indicator.visible {
255
274
  visibility: visible;
256
275
  height: 50px;
257
- }`,r=document.createElement("style");r.textContent=i,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()});const u=["climats","telckel","biobio"];class m{constructor(o){this.apiEndpoint=o||"https://api.wineater.com/dish/recommendations",this.store=u.find(t=>window.location.href.includes(t)),console.log(this.store)}async getWineRecommendations(o){console.log(window.location.href);try{const t=await fetch(this.apiEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:o,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),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 f{constructor(){h(this,"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?");this.api=new m,this.displayFirstMessage(this.welcomeMessage)}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",e=>{e.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(o,t="api"){const e=document.getElementById("message-container"),s=document.createElement("div");s.className=`message ${t}`,s.textContent=o,e.appendChild(s),e.scrollTop=e.scrollHeight}async handleUserInput(){const o=document.getElementById("user-input"),t=o.value.trim();if(t){this.displayMessage(t,"user"),o.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(o,t){const e=document.getElementById("message-container"),s=document.createElement("div");s.textContent=o,s.className="message "+t,e.appendChild(s),e.scrollTop=e.scrollHeight}displayResults(o){const t=document.getElementById("message-container");o.forEach(e=>{const s=document.createElement("div");s.className="wine-item";const p=document.createElement("img");p.src=e.Image,s.appendChild(p);const g=document.createElement("div");g.innerHTML=`
258
- <strong>${e.Title}</strong><br>
259
- Prix: ${e.Price}<br>
260
- Région: ${e.Region}<br>
261
- Type: ${e.Type}<br>
262
- <a href="${e.Url}" target="_blank">Plus d'infos</a>
263
- `,s.appendChild(g),t.appendChild(s)}),t.scrollTop=t.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=d,window.closeChatWindow=c,window.openChatWindow=l});function b(){document.body.insertAdjacentHTML("beforeend",`
276
+ }`,r=document.createElement("style");r.textContent=s,document.head.appendChild(r);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 c(){document.getElementById("chat-window").classList.remove("visible")}function l(){document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const u=["climats","telckel","biobio"];class m{constructor(t){this.apiEndpoint=t||"https://api.wineater.com/dish/recommendations",this.store=u.find(e=>window.location.href.includes(e)),console.log(this.store)}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(this.apiEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},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 f{constructor(){h(this,"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?");this.api=new m,this.displayFirstMessage(this.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"),a=document.createElement("div");a.className=`message ${e}`,a.textContent=t,o.appendChild(a),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(o){this.hideTypingIndicator(),console.error("Error fetching wine recommendations:",o),this.displayMessage("Sorry, something went wrong.","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"),a=document.createElement("div");a.textContent=t,a.className="message "+e,o.appendChild(a),o.scrollTop=o.scrollHeight}displayResults(t){const e=document.getElementById("message-container");t.forEach(o=>{const a=document.createElement("div");a.className="wine-item";const p=document.createElement("img");p.src=o.Image,a.appendChild(p);const g=document.createElement("div");g.innerHTML=`
277
+ <strong>${o.Title}</strong><br>
278
+ Prix: ${o.Price}<br>
279
+ Région: ${o.Region}<br>
280
+ Type: ${o.Type}<br>
281
+ <a href="${o.Url}" target="_blank">Plus d'infos</a>
282
+ `,a.appendChild(g),e.appendChild(a)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=d,window.closeChatWindow=c,window.openChatWindow=l});function b(){document.body.insertAdjacentHTML("beforeend",`
264
283
  <div id="chatbot-container">
265
284
  <div id="chat-icon" onclick="toggleChatWindow()">
266
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,4 +305,4 @@
286
305
  </div>
287
306
  </div>
288
307
  </div>
289
- `)}function y(){document.getElementById("close-btn").addEventListener("click",d)}function w(){window.addEventListener("click",function(a){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");!o.contains(a.target)&&!t.contains(a.target)&&o.classList.remove("visible")})}typeof window<"u"&&window.addEventListener("DOMContentLoaded",()=>{b(),y(),w(),new f().initialize()}),n.closeChatWindow=c,n.openChatWindow=l,n.toggleChatWindow=d,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
308
+ `)}function y(){document.getElementById("close-btn").addEventListener("click",d)}function w(){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 x(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"&&window.addEventListener("DOMContentLoaded",()=>{b(),y(),w(),x("right-center"),new f().initialize()}),i.closeChatWindow=c,i.openChatWindow=l,i.toggleChatWindow=d,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/index.js CHANGED
@@ -14,6 +14,7 @@ document.addEventListener('DOMContentLoaded', () => {
14
14
  window.toggleChatWindow = toggleChatWindow;
15
15
  window.closeChatWindow = closeChatWindow;
16
16
  window.openChatWindow = openChatWindow;
17
+
17
18
  });
18
19
 
19
20
  export {
@@ -65,16 +66,36 @@ function setupOutsideClick() {
65
66
  const chatIcon = document.getElementById('chat-icon');
66
67
  if (!chatWindow.contains(event.target) && !chatIcon.contains(event.target)) {
67
68
  chatWindow.classList.remove('visible');
69
+ chatIcon.style.display = 'flex'; // Show the chat icon/button
68
70
  }
69
71
  });
70
72
  }
71
73
 
74
+ // Function to toggle the chat icon position
75
+ function toggleChatIconPosition(position) {
76
+ console.log(position);
77
+ const chatIcon = document.getElementById('chat-icon');
78
+ const chatWindow = document.getElementById('chat-window');
79
+
80
+ chatIcon.className = ''; // Reset classes
81
+ chatWindow.className = ''; // Reset classes
82
+
83
+ if (position === 'right-center') {
84
+ chatIcon.classList.add('chat-icon-right-center');
85
+ chatWindow.classList.add('right-center-aligned');
86
+ } else {
87
+ // Apply bottom-right or other default classes as needed
88
+ chatIcon.classList.add('chat-icon-bottom-right');
89
+ }
90
+ }
91
+
72
92
  // If you want to initialize your chatbot automatically when the script is loaded
73
93
  if (typeof window !== 'undefined') {
74
94
  window.addEventListener('DOMContentLoaded', () => {
75
95
  createChatbotUI(); // Create the UI
76
96
  setupCloseButton();
77
97
  setupOutsideClick();
98
+ toggleChatIconPosition('right-center');
78
99
  const myChatbot = new Chatbot();
79
100
  myChatbot.initialize();
80
101
  });
package/src/js/styles.js CHANGED
@@ -24,9 +24,28 @@ const css = `
24
24
  border-radius: 20px; /* Rounded corners for the button */
25
25
  background-color: #fff; /* Background color from your style guide */
26
26
  cursor: pointer;
27
+ box-sizing: content-box;
27
28
  box-shadow: 0 2px 10px rgba(0,0,0,0.2); /* Optional: add shadow for depth */
28
29
  }
29
30
 
31
+ /* Position class for bottom-right */
32
+ .chat-icon-bottom-right {
33
+ position: fixed;
34
+ bottom: 20px;
35
+ right: 20px;
36
+ /* Other styles for the bottom-right button */
37
+ /* ... */
38
+ }
39
+
40
+ .chat-icon-right-center {
41
+ position: fixed;
42
+ top: 50%;
43
+ right: -100px;
44
+ transform: translateY(-50%) rotate(90deg);
45
+ /* Additional styling for the button */
46
+ /* ... */
47
+ }
48
+
30
49
  #chat-icon img {
31
50
  width: 40px; /* Adjust icon size as needed */
32
51
  height: auto;
@@ -41,13 +60,13 @@ const css = `
41
60
 
42
61
  /* Chat window styles */
43
62
  #chat-window {
63
+ position: fixed;
64
+ bottom: 20px; /* Set to the desired distance from the bottom */
65
+ right: 20px; /* Set to the desired distance from the right */
44
66
  width: 350px; /* Width of the chat window */
45
67
  background-color: white;
46
68
  border-radius: 8px;
47
69
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
48
- position: absolute;
49
- bottom: 80px; /* Positioning from the bottom */
50
- right: 0;
51
70
  display: none; /* Initially hidden */
52
71
  }
53
72
 
package/src/js/ui.js CHANGED
@@ -1,6 +1,17 @@
1
1
  export function toggleChatWindow() {
2
2
  const chatWindow = document.getElementById('chat-window');
3
- chatWindow.classList.toggle('visible');
3
+ const chatIcon = document.getElementById('chat-icon');
4
+
5
+ // Check if the chat window is currently visible
6
+ const isWindowOpen = chatWindow.classList.contains('visible');
7
+
8
+ if (isWindowOpen) {
9
+ chatWindow.classList.remove('visible');
10
+ chatIcon.style.display = 'flex'; // Show the chat icon/button
11
+ } else {
12
+ chatWindow.classList.add('visible');
13
+ chatIcon.style.display = 'none'; // Hide the chat icon/button
14
+ }
4
15
  }
5
16
 
6
17
  export function closeChatWindow() {