wineater-bot 3.2.1 → 3.4.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.
package/src/js/ui.js DELETED
@@ -1,107 +0,0 @@
1
-
2
- import { trackChatbotOpen, trackChatbotClose, trackChatbotOpenAuto, setCookie, getCookie, deleteCookie } from './analytics.js';
3
- import translator from './i18n.js';
4
-
5
- const MAX_CHAT_CLOSURES = 3;
6
- let timerId = null; // Переменная для хранения ID таймера
7
-
8
- export function toggleChatWindow() {
9
- const chatWindow = document.getElementById('chat-window');
10
- const chatIcon = document.getElementById('chat-icon');
11
-
12
-
13
- // Check if the chat window is currently visible
14
- const isWindowOpen = chatWindow.classList.contains('visible');
15
-
16
- if (isWindowOpen) {
17
- trackChatbotClose();
18
- closeChatWindow();
19
- chatIcon.style.display = 'flex'; // Show the chat icon/button
20
- } else {
21
- if (timerId) {
22
- clearTimeout(timerId);
23
- timerId = null; // Сбрасываем таймер
24
- }
25
- trackChatbotOpen();
26
- chatWindow.classList.add('visible');
27
- chatIcon.style.display = 'none'; // Hide the chat icon/button
28
- }
29
- }
30
-
31
- export function closeChatWindow() {
32
- console.log('ghbdtn');
33
- trackChatbotClose();
34
- const chatWindow = document.getElementById('chat-window');
35
- chatWindow.classList.remove('visible');
36
-
37
- let closeCount = parseInt(getCookie('chatCloseCount')) || 0;
38
- closeCount += 1;
39
-
40
- if (closeCount >= MAX_CHAT_CLOSURES) {
41
- console.log(closeCount);
42
- setCookie('disableAutoOpen', 'true', 1); // Disable auto-opening for 1 day
43
- deleteCookie('chatCloseCount'); // Reset close count
44
- } else {
45
- console.log(closeCount);
46
- setCookie('chatCloseCount', closeCount, 1); // Update the close count cookie
47
- }
48
- }
49
-
50
- export function openChatWindowWithDishes(dishes) {
51
- const chatWindow = document.getElementById('chat-window');
52
- const messageContainer = document.getElementById('message-container');
53
- const inputField = document.querySelector('#input-container input'); // Инпут для текста пользователя
54
-
55
- // Очистить существующие сообщения
56
- messageContainer.innerHTML = '';
57
-
58
- chatWindow.classList.add('visible'); // Открыть окно чата
59
-
60
- // Добавить сообщение о предложенных блюдах
61
- const introMessage = document.createElement('div');
62
- introMessage.className = 'message api';
63
- introMessage.textContent = translator.translate('winePairingIntro');
64
- messageContainer.appendChild(introMessage);
65
-
66
- // Показать блюда с кликабельностью
67
- dishes.slice(0, 3).forEach(dish => {
68
- const dishMessage = document.createElement('div');
69
- dishMessage.className = 'message dish-message'; // Используем новый стиль для блюда
70
- dishMessage.textContent = dish; // Предполагаем, что в ответе от API есть поле "name"
71
-
72
- // Добавляем событие клика для подстановки названия в инпут
73
- dishMessage.addEventListener('click', () => {
74
- inputField.value = dish; // Подставляем название блюда в инпут
75
- });
76
-
77
- messageContainer.appendChild(dishMessage);
78
- });
79
-
80
- // Добавляем вопрос пользователю
81
- const followUpMessage = document.createElement('div');
82
- followUpMessage.className = 'message api';
83
- followUpMessage.textContent = translator.translate('askForDinner');
84
- messageContainer.appendChild(followUpMessage);
85
-
86
- messageContainer.scrollTop = messageContainer.scrollHeight; // Скролл до последнего сообщения
87
- }
88
-
89
- export function openChatWindow(fromUrl = null) {
90
- if (!!fromUrl) {
91
- trackChatbotOpenAuto(fromUrl);
92
- } else {
93
- trackChatbotOpen();
94
- }
95
- const chatWindow = document.getElementById('chat-window');
96
- chatWindow.classList.add('visible');
97
- }
98
-
99
- // Setup event listeners upon loading the module
100
- document.addEventListener('DOMContentLoaded', () => {
101
- setupCloseButton();
102
- setupOutsideClick();
103
- });
104
-
105
- export function setAutoOpenTimer(timer) {
106
- timerId = timer;
107
- }