From c30e22e1b165c63f0393318f0e5a1db70e184df1 Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 31 Jan 2026 19:50:03 +0300 Subject: [PATCH 1/2] Update subscription_auto_purchase_service.py --- .../subscription_auto_purchase_service.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/services/subscription_auto_purchase_service.py b/app/services/subscription_auto_purchase_service.py index 9147b5a5..20fe7f1f 100644 --- a/app/services/subscription_auto_purchase_service.py +++ b/app/services/subscription_auto_purchase_service.py @@ -1248,6 +1248,22 @@ async def _auto_add_devices( price_kopeks, ) + # WebSocket уведомление для кабинета + try: + from app.cabinet.routes.websocket import notify_user_devices_purchased + + await notify_user_devices_purchased( + user_id=user.id, + devices_added=devices_to_add, + new_device_limit=subscription.device_limit, + amount_kopeks=price_kopeks, + ) + except Exception as ws_error: + logger.warning( + '⚠️ Автопокупка устройств: не удалось отправить WebSocket уведомление: %s', + ws_error, + ) + # Уведомление пользователю if bot and user.telegram_id: texts = get_texts(getattr(user, 'language', 'ru')) From 7bd5d13cc8cc821cbe9c5d659055e3071aecff17 Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 31 Jan 2026 19:50:47 +0300 Subject: [PATCH 2/2] Update websocket.py --- app/cabinet/routes/websocket.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/cabinet/routes/websocket.py b/app/cabinet/routes/websocket.py index 8ea04ae1..c9f2ed9e 100644 --- a/app/cabinet/routes/websocket.py +++ b/app/cabinet/routes/websocket.py @@ -374,6 +374,25 @@ async def notify_user_subscription_renewed( ) +async def notify_user_devices_purchased( + user_id: int, + devices_added: int, + new_device_limit: int, + amount_kopeks: int, +) -> None: + """Уведомить пользователя о покупке устройств.""" + await cabinet_ws_manager.send_to_user( + user_id, + { + 'type': 'subscription.devices_purchased', + 'devices_added': devices_added, + 'new_device_limit': new_device_limit, + 'amount_kopeks': amount_kopeks, + 'amount_rubles': amount_kopeks / 100, + }, + ) + + # ============================================================================ # Уведомления об автопродлении # ============================================================================