Add voice bot welcome tracking functionality
- Implemented methods to check and mark if a user has received a welcome message from the voice bot in both async and synchronous database classes. - Updated database schema to include a new field for tracking welcome message status. - Enhanced voice handler to utilize the new tracking methods, improving user interaction flow and engagement metrics.
This commit is contained in:
@@ -977,3 +977,63 @@ class AsyncBotDB:
|
||||
"""Закрытие соединений."""
|
||||
# Соединения закрываются в каждом методе
|
||||
pass
|
||||
|
||||
# Методы для voice bot welcome tracking
|
||||
async def check_voice_bot_welcome_received(self, user_id: int) -> bool:
|
||||
"""
|
||||
Проверяет, получал ли пользователь приветственное сообщение от voice_bot.
|
||||
|
||||
Args:
|
||||
user_id (int): Идентификатор пользователя в Telegram.
|
||||
|
||||
Returns:
|
||||
bool: True, если пользователь получал приветствие, False - иначе.
|
||||
"""
|
||||
conn = None
|
||||
try:
|
||||
conn = await self._get_connection()
|
||||
async with conn.execute(
|
||||
"SELECT voice_bot_welcome_received FROM our_users WHERE user_id = ?",
|
||||
(user_id,)
|
||||
) as cursor:
|
||||
result = await cursor.fetchone()
|
||||
if result:
|
||||
welcome_received = bool(result[0])
|
||||
self.logger.info(f"Пользователь {user_id} получал приветствие: {welcome_received}")
|
||||
return welcome_received
|
||||
else:
|
||||
self.logger.info(f"Пользователь {user_id} не найден в базе")
|
||||
return False
|
||||
except Exception as e:
|
||||
self.logger.error(f"Ошибка при проверке получения приветствия: {e}")
|
||||
return False
|
||||
finally:
|
||||
if conn:
|
||||
await conn.close()
|
||||
|
||||
async def mark_voice_bot_welcome_received(self, user_id: int) -> bool:
|
||||
"""
|
||||
Отмечает, что пользователь получил приветственное сообщение от voice_bot.
|
||||
|
||||
Args:
|
||||
user_id (int): Идентификатор пользователя в Telegram.
|
||||
|
||||
Returns:
|
||||
bool: True, если обновление прошло успешно, False - в случае ошибки.
|
||||
"""
|
||||
conn = None
|
||||
try:
|
||||
conn = await self._get_connection()
|
||||
await conn.execute(
|
||||
"UPDATE our_users SET voice_bot_welcome_received = 1 WHERE user_id = ?",
|
||||
(user_id,)
|
||||
)
|
||||
await conn.commit()
|
||||
self.logger.info(f"Пользователь {user_id} отмечен как получивший приветствие")
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"Ошибка при отметке получения приветствия: {e}")
|
||||
return False
|
||||
finally:
|
||||
if conn:
|
||||
await conn.close()
|
||||
|
||||
Reference in New Issue
Block a user