wineater-bot 3.0.1 → 3.0.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.
package/index.html CHANGED
@@ -5,8 +5,8 @@
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: 'K0ZzlrfT0z00J6dSAt8ZEIKWiUfypG1Tyb1ZGtgwuJaF8WZuRKlHfvEMCF9DyytZ', position: 'right-center'};</script>
9
- <script type="module" src="./src/index.js"></script>
8
+ <script>window.wineaterData = {CLIENT_TOKEN: 'HeUw6IXuhvz6tRuXdPEGEbj3SGQ3Q2YtEc1Z8jd41Kg9LtyPb4Epu0to31SYIadG', position: 'right-center', TYPE: 'widget'};</script>
9
+ <script type="module" src="./dist/wineater-chatbot.umd.js"></script>
10
10
  </head>
11
11
  <body style="margin: 0;">
12
12
  <div id="widget-container"></div> <!-- Контейнер для виджета -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wineater-bot",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",
package/src/index.js CHANGED
@@ -8,11 +8,11 @@ import translator from './js/i18n.js';
8
8
  import { shouldOpenChatAutomatically } from './js/auto-open.js';
9
9
  import { toggleChatWindow, closeChatWindow, openChatWindow } from './js/ui.js';
10
10
 
11
- const DEMO_TOKEN = 'tbMTFzLbWcXFgXK8SzyFHA6kIjelFcz5VQABVPbXdXh5XZJCDQH9BcVlrv3DF3kA';
11
+ const DEMO_TOKEN = 'HeUw6IXuhvz6tRuXdPEGEbj3SGQ3Q2YtEc1Z8jd41Kg9LtyPb4Epu0to31SYIadG';
12
12
 
13
13
  class App {
14
14
  constructor() {
15
- this.stores = ['climats', 'telckel', 'biobio', 'weinpoint', 'vinigrandi', 'ampely'];
15
+ this.stores = ['climats', 'telckel', 'biobio', 'weinpoint', 'vinigrandi', 'ampely', 'test'];
16
16
  this.tracker = new Tracker({ projectKey: "PA8j9fAi49i6g2QnvpNs", '__DISABLE_SECURE_MODE': true });
17
17
  this.position = window?.wineaterData?.POSITION || 'right-center';
18
18
  this.type = window?.wineaterData?.TYPE || 'chatbot';
@@ -37,8 +37,8 @@ class App {
37
37
  }
38
38
 
39
39
  async initTranslator() {
40
- const storeName = this.store ? this.store.charAt(0).toUpperCase() + this.store.slice(1) : 'Climats';
41
- await translator.fetchConfig(storeName || 'Climats');
40
+ const storeName = this.store ? this.store.charAt(0).toUpperCase() + this.store.slice(1) : 'Test';
41
+ await translator.fetchConfig(storeName || 'Test');
42
42
  }
43
43
 
44
44
  initCookies() {
@@ -65,7 +65,7 @@ class App {
65
65
  const chatbotHTML = `
66
66
  <div id="chatbot-container">
67
67
  <div id="chat-icon">
68
- <img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon">
68
+ <img src="https://czvgkhagwvmknscoerfy.supabase.co/storage/v1/object/public/static-media/chat-icon.svg" alt="Chat Icon">
69
69
  <span>${buttonText}</span>
70
70
  </div>
71
71
  <div id="chat-window" class="hidden">
@@ -86,7 +86,7 @@ class App {
86
86
  <div id="powered-by">
87
87
  <a href="https://wineater.com" target="_blank">
88
88
  <span>${translator.translate('poweredBy')}</span>
89
- <img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/logo.svg" alt="Wineater Logo" id="chatbot-logo">
89
+ <img src="https://czvgkhagwvmknscoerfy.supabase.co/storage/v1/object/public/static-media/logo.svg" alt="Wineater Logo" id="chatbot-logo">
90
90
  </a>
91
91
  </div>
92
92
  </div>
package/src/js/api.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // api.js
2
2
 
3
- const stores = ['climats', 'telckel', 'biobio', 'weinpoint', 'vinigrandi', 'ampely'];
4
- const DEMO_TOKEN='bMTFzLbWcXFgXK8SzyFHA6kIjelFcz5VQABVPbXdXh5XZJCDQH9BcVlrv3DF3kA';
3
+ const stores = ['climats', 'telckel', 'biobio', 'weinpoint', 'vinigrandi', 'ampely', 'test'];
4
+ const DEMO_TOKEN='HeUw6IXuhvz6tRuXdPEGEbj3SGQ3Q2YtEc1Z8jd41Kg9LtyPb4Epu0to31SYIadG';
5
5
 
6
6
  export class Api {
7
7
  constructor(apiEndpoint) {
@@ -59,6 +59,33 @@ export class Api {
59
59
  }
60
60
  }
61
61
 
62
+ async getWineRecommendationsSearch(text) {
63
+ console.log(window.location.href);
64
+ try {
65
+ const response = await fetch(`${this.baseURL}dish/recommendations/search`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ 'Authorization': `Bearer ${this.token}`
70
+ },
71
+ body: JSON.stringify({ text: text, store: this.store ? (this.store.toString().charAt(0).toUpperCase() + this.store.slice(1)) : undefined})
72
+ });
73
+
74
+ const data = await response.json();
75
+
76
+ if (!response.ok) {
77
+ // Providing more detailed error information
78
+ throw new Error(`API call failed with status ${response.status}: ${data.message || 'No additional error information'}`);
79
+ }
80
+
81
+ return data;
82
+ } catch (error) {
83
+ // Log and rethrow to allow consumer of the API to handle or display the error appropriately
84
+ console.error('Fetching wine recommendations failed:', error.message);
85
+ throw new Error(`Error in getWineRecommendations: ${error.message}`);
86
+ }
87
+ }
88
+
62
89
  async getPossibleDishesWithMeta(metaTitle, metaDescription) {
63
90
  try {
64
91
  const response = await fetch(`${this.baseURL}dish/possible_dishes`, {
package/src/js/styles.js CHANGED
@@ -435,10 +435,14 @@ border-bottom-right-radius: 15px;
435
435
  justify-content: center;
436
436
  align-items: center;
437
437
  height: 0;
438
- visibility: hidden;
438
+ visibility: hidden;
439
439
  background-color: white;
440
440
  }
441
441
 
442
+ #loading-indicator .typing-indicator {
443
+ visibility: visible;
444
+ }
445
+
442
446
  .typing-indicator span {
443
447
  display: block;
444
448
  width: 8px;
package/src/js/widget.js CHANGED
@@ -31,9 +31,10 @@ export class WineWidget {
31
31
  <div class="filter-group">
32
32
  <span class="filter-label">${translator.translate('priceRange')}:</span>
33
33
  <div class="filter-buttons" id="price-buttons">
34
- <button data-value="<10"><$10</button>
35
- <button data-value="10-20">$10-$20</button>
36
- <button data-value=">20">>$20</button>
34
+ <button data-value="< 500">< $500</button>
35
+ <button data-value="500 - 1000">$500 - $1000</button>
36
+ <button data-value="> 1000">> $1000</button>
37
+ <button data-value=" " class="selected">Any</button>
37
38
  </div>
38
39
  </div>
39
40
  <div class="filter-group">
@@ -42,6 +43,7 @@ export class WineWidget {
42
43
  <button data-value="red">${translator.translate('red')}</button>
43
44
  <button data-value="white">${translator.translate('white')}</button>
44
45
  <button data-value="rose">${translator.translate('rose')}</button>
46
+ <button data-value=" " class="selected">${translator.translate('Any')}</button>
45
47
  </div>
46
48
  </div>
47
49
  <div class="filter-group">
@@ -50,19 +52,22 @@ export class WineWidget {
50
52
  <button data-value="light">${translator.translate('light')}</button>
51
53
  <button data-value="medium">${translator.translate('medium')}</button>
52
54
  <button data-value="full">${translator.translate('full')}</button>
55
+ <button data-value=" " class="selected">${translator.translate('Any')}</button>
53
56
  </div>
54
57
  </div>
55
58
  </div>
56
59
  <div id="powered-by-widget">
57
60
  <a href="https://wineater.com" target="_blank">
58
61
  <span>${translator.translate('poweredBy')}</span>
59
- <img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/logo.svg" alt="Wineater Logo">
62
+ <img src="https://czvgkhagwvmknscoerfy.supabase.co/storage/v1/object/public/static-media/logo.svg" alt="Wineater Logo">
60
63
  </a>
61
64
  </div>
62
65
  </div>
63
66
  <div id="wine-widget-right">
64
67
  <div id="loading-indicator" class="hidden">
65
- <img src="https://czvgkhagwvmknscoerfy.supabase.co/storage/v1/object/public/static-media/mascot.jpeg" alt="Loading" />
68
+ <div id="typing-indicator" class="typing-indicator">
69
+ <span></span><span></span><span></span>
70
+ </div>
66
71
  </div>
67
72
  <div id="wine-placeholder"></div>
68
73
  </div>
@@ -92,29 +97,44 @@ export class WineWidget {
92
97
  buttons.forEach(btn => btn.classList.remove('selected'));
93
98
  e.target.classList.add('selected');
94
99
  this.selectedFilters[filterKey] = e.target.dataset.value;
100
+ this.handleSearch();
95
101
  });
96
102
  });
97
103
  }
98
104
 
99
105
  async handleSearch() {
100
- const query = document.getElementById('wine-search-input').value;
101
-
102
- // Показать эффект исчезновения карточек
103
- this.animateCardDisappearance();
104
-
105
- // Показать индикатор загрузки
106
-
106
+ const query = 'wine for dish:' + document.getElementById('wine-search-input').value.trim() + ';';
107
107
 
108
108
  // Учитываем текущие выбранные фильтры
109
109
  const filters = this.selectedFilters;
110
-
111
- // Добавляем вывод информации о запросе
112
- console.log('Searching for:', query);
110
+
111
+ // Формируем органичную фразу с фильтрами
112
+ const filterPhrases = [];
113
+ if (filters.price) {
114
+ filterPhrases.push(`price: ${filters.price || 'any'};`);
115
+ }
116
+ if (filters.color) {
117
+ filterPhrases.push(`color: ${filters.color || 'any'}; `);
118
+ }
119
+ if (filters.intensity) {
120
+ filterPhrases.push(`intensity: ${filters.intensity || 'any'}; `);
121
+ }
122
+
123
+ // Объединяем фильтры с основным запросом
124
+ const fullQuery = filterPhrases.length > 0
125
+ ? `${query} ${filterPhrases.join(', ')}`
126
+ : query;
127
+
128
+ // Логирование запроса
129
+ console.log('Searching for:', fullQuery);
113
130
  console.log('Applied filters:', filters);
114
131
 
132
+ // Показать эффект исчезновения карточек и индикатор загрузки
133
+ this.animateCardDisappearance();
134
+
115
135
  try {
116
136
  // Вызываем API метод для получения рекомендаций
117
- const results = await this.api.getWineRecommendations(query);
137
+ const results = await this.api.getWineRecommendationsSearch(fullQuery);
118
138
 
119
139
  // Проверяем, есть ли данные
120
140
  if (results && results.length > 0) {
@@ -207,7 +227,7 @@ export class WineWidget {
207
227
  }
208
228
 
209
229
  async loadInstantRecommendations() {
210
- console.log('привет')
230
+ this.showLoadingIndicator();
211
231
  try {
212
232
  const recommendations = await this.api.getInstantRecommendations();
213
233
  this.displayResults(recommendations); // Обновляем отображение рекомендаций