wineater-bot 1.1.8 → 1.2.0

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.
@@ -424,3 +424,5 @@ export {
424
424
  u as openChatWindow,
425
425
  l as toggleChatWindow
426
426
  };
427
+
428
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "1.1.8",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ import './js/styles.js';
7
7
  import { toggleChatWindow, closeChatWindow, openChatWindow } from './js/ui.js';
8
8
  import { Chatbot } from './js/chatbot.js';
9
9
  import './js/api.js';
10
+ import translator from './js/i18n.js';
10
11
 
11
12
  document.addEventListener('DOMContentLoaded', () => {
12
13
  // Attach any necessary initialization code here
@@ -14,7 +15,6 @@ document.addEventListener('DOMContentLoaded', () => {
14
15
  window.toggleChatWindow = toggleChatWindow;
15
16
  window.closeChatWindow = closeChatWindow;
16
17
  window.openChatWindow = openChatWindow;
17
-
18
18
  });
19
19
 
20
20
  export {
@@ -28,7 +28,7 @@ function createChatbotUI() {
28
28
  <div id="chatbot-container">
29
29
  <div id="chat-icon" onclick="toggleChatWindow()">
30
30
  <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 -->
31
- <span>Accorder le vin au dîner</span>
31
+ <span>${translator.translate('chatButton')}</span>
32
32
  </div>
33
33
 
34
34
  <div id="chat-window" class="hidden">
@@ -45,8 +45,8 @@ function createChatbotUI() {
45
45
  <span></span><span></span><span></span>
46
46
  </div>
47
47
  <div id="input-container">
48
- <input type="text" id="user-input" placeholder="ex., Salade de thon">
49
- <button id="send-button">Accorder</button>
48
+ <input type="text" id="user-input" placeholder="${translator.translate('inputPlaceholder')}">
49
+ <button id="send-button">${translator.translate('sendButton')}</button>
50
50
  </div>
51
51
  </div>
52
52
  </div>
@@ -91,9 +91,14 @@ function toggleChatIconPosition(position) {
91
91
 
92
92
  // If you want to initialize your chatbot automatically when the script is loaded
93
93
  if (typeof window !== 'undefined') {
94
- window.addEventListener('DOMContentLoaded', () => {
94
+ window.addEventListener('DOMContentLoaded', async () => {
95
95
  const stores = ['climats', 'telckel', 'biobio', 'weinpoint'];
96
96
  const store = stores.find(value => window.location.href.includes(value)) || null;
97
+ let capitalizeStore;
98
+ if (store) {
99
+ capitalizeStore = store.charAt(0).toUpperCase() + store.slice(1)
100
+ }
101
+ await translator.fetchConfig(capitalizeStore || null);
97
102
  createChatbotUI(); // Create the UI
98
103
  setupCloseButton();
99
104
  setupOutsideClick();
@@ -101,7 +106,7 @@ if (typeof window !== 'undefined') {
101
106
  toggleChatIconPosition('right-center');
102
107
  } else {
103
108
  toggleChatIconPosition('bottom-right');
104
- }
109
+ }
105
110
  const myChatbot = new Chatbot();
106
111
  myChatbot.initialize();
107
112
  });
package/src/js/api.js CHANGED
@@ -5,15 +5,33 @@ const stores = ['climats', 'telckel', 'biobio', 'weinpoint'];
5
5
  export class Api {
6
6
  constructor(apiEndpoint) {
7
7
  // Allow users of the library to specify their own endpoint if needed
8
- this.apiEndpoint = apiEndpoint || 'https://api.wineater.com/dish/recommendations';
8
+ this.baseURL = 'https://api.wineater.com/';
9
9
  this.store = stores.find(value => window.location.href.includes(value));
10
10
  console.log(this.store);
11
11
  }
12
12
 
13
+ async getStoreConfig(storeName) {
14
+ console.log(storeName);
15
+ try {
16
+ const response = await fetch(`${this.baseURL}stores/store`, {
17
+ method: 'POST',
18
+ headers: {
19
+ 'Content-Type': 'application/json'
20
+ },
21
+ body: JSON.stringify({ store: storeName })
22
+ });
23
+ if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
24
+ return await response.json();
25
+ } catch (error) {
26
+ console.error('Error fetching store configuration:', error);
27
+ throw error;
28
+ }
29
+ }
30
+
13
31
  async getWineRecommendations(text) {
14
32
  console.log(window.location.href);
15
33
  try {
16
- const response = await fetch(this.apiEndpoint, {
34
+ const response = await fetch(`${this.baseURL}dish/recommendations`, {
17
35
  method: 'POST',
18
36
  headers: {
19
37
  'Content-Type': 'application/json'
package/src/js/chatbot.js CHANGED
@@ -1,14 +1,13 @@
1
1
  // chatbot.js
2
2
  import { Api } from './api.js';
3
+ import translator from './i18n.js';
3
4
 
4
5
  export class Chatbot {
5
6
  constructor() {
6
7
  this.api = new Api(); // Instantiate the Api class
7
- this.displayFirstMessage(this.welcomeMessage);
8
+ this.displayFirstMessage(translator.translate('welcomeMessage'));
8
9
  }
9
10
 
10
- 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?";
11
-
12
11
  initialize() {
13
12
  // Attach event listeners
14
13
  const sendButton = document.getElementById('send-button');
@@ -58,8 +57,7 @@ export class Chatbot {
58
57
  // Hide the loader
59
58
  this.hideTypingIndicator();
60
59
 
61
- console.error('Error fetching wine recommendations:', error);
62
- this.displayMessage('Sorry, something went wrong.', 'api');
60
+ this.displayMessage(translator.translate('somethingWentWrong'), 'api');
63
61
  }
64
62
  }
65
63
 
@@ -94,11 +92,11 @@ export class Chatbot {
94
92
 
95
93
  const contentDiv = document.createElement('div');
96
94
  contentDiv.innerHTML = `
97
- <strong>${wine.Title}</strong><br>
98
- Prix: ${wine.Price}<br>
99
- Région: ${wine.Region}<br>
100
- Type: ${wine.Type}<br>
101
- <a href="${wine.Url}" target="_blank">Plus d'infos</a>
95
+ <strong>${wine.Title}</strong><br>
96
+ ${translator.translate('price')}: ${wine.Price}<br>
97
+ ${translator.translate('region')}: ${wine.Region}<br>
98
+ ${translator.translate('type')}: ${wine.Type}<br>
99
+ <a href="${wine.Url}" target="_blank">${translator.translate('moreInfo')}</a>
102
100
  `;
103
101
  wineDiv.appendChild(contentDiv);
104
102
 
package/src/js/i18n.js ADDED
@@ -0,0 +1,59 @@
1
+ import { Api } from './api.js';
2
+
3
+ class Translator {
4
+ constructor() {
5
+ this.api = new Api();
6
+ this.language = 'en'; // Default to French
7
+ this.translations = {
8
+ fr: {
9
+ 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?",
10
+ noResultsFound: "Aucun résultat trouvé.",
11
+ somethingWentWrong: "Désolé, quelque chose a mal tourné.",
12
+ chatButton: "Accorder le vin au dîner",
13
+ inputPlaceholder: "ex., Salade de thon",
14
+ sendButton: "Accorder",
15
+ price: "Prix",
16
+ region: "Région",
17
+ type: "Type",
18
+ moreInfo: "Plus d'infos"
19
+ },
20
+ es: {
21
+ 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?",
22
+ noResultsFound: "No se encontraron resultados.",
23
+ somethingWentWrong: "Lo sentimos, algo salió mal.",
24
+ chatButton: "Maridar vino con cena",
25
+ inputPlaceholder: "ej., Ensalada de atún",
26
+ sendButton: "Maridar",
27
+ price: "Precio",
28
+ region: "Región",
29
+ type: "Tipo",
30
+ moreInfo: "Más info"
31
+ },
32
+ en: {
33
+ welcomeMessage: "Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",
34
+ noResultsFound: "No results found.",
35
+ somethingWentWrong: "Sorry, something went wrong.",
36
+ chatButton: "Pair wine with dinner",
37
+ inputPlaceholder: "e.g., Tuna Salad",
38
+ sendButton: "Pair",
39
+ price: "Price",
40
+ region: "Region",
41
+ type: "Type",
42
+ moreInfo: "More info"
43
+ }
44
+ };
45
+ }
46
+
47
+ async fetchConfig(storeName) {
48
+ if (storeName) {
49
+ const config = await this.api.getStoreConfig(storeName);
50
+ this.language = config.lang;
51
+ }
52
+ }
53
+
54
+ translate(key) {
55
+ return this.translations[this.language][key] || key;
56
+ }
57
+ }
58
+
59
+ export default new Translator();