mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-03-01 07:42:30 +00:00
feat: add admin notifications for partner applications and withdrawals
Send notifications to admin chat when a partner application is submitted or a withdrawal request is created, following existing notification pattern.
This commit is contained in:
@@ -122,6 +122,31 @@ async def apply_for_partner(
|
||||
detail=error,
|
||||
)
|
||||
|
||||
# Уведомляем админов о новой заявке
|
||||
try:
|
||||
from aiogram import Bot
|
||||
|
||||
from app.services.admin_notification_service import AdminNotificationService
|
||||
|
||||
if getattr(settings, 'ADMIN_NOTIFICATIONS_ENABLED', False) and settings.BOT_TOKEN:
|
||||
bot = Bot(token=settings.BOT_TOKEN)
|
||||
try:
|
||||
notification_service = AdminNotificationService(bot)
|
||||
await notification_service.send_partner_application_notification(
|
||||
user=user,
|
||||
application_data={
|
||||
'company_name': request.company_name,
|
||||
'telegram_channel': request.telegram_channel,
|
||||
'website_url': request.website_url,
|
||||
'description': request.description,
|
||||
'expected_monthly_referrals': request.expected_monthly_referrals,
|
||||
},
|
||||
)
|
||||
finally:
|
||||
await bot.session.close()
|
||||
except Exception as e:
|
||||
logger.error('Failed to send admin notification for partner application', error=e)
|
||||
|
||||
return PartnerApplicationInfo(
|
||||
id=application.id,
|
||||
status=application.status,
|
||||
|
||||
@@ -68,6 +68,26 @@ async def create_withdrawal(
|
||||
detail=error,
|
||||
)
|
||||
|
||||
# Уведомляем админов о запросе на вывод
|
||||
try:
|
||||
from aiogram import Bot
|
||||
|
||||
from app.services.admin_notification_service import AdminNotificationService
|
||||
|
||||
if getattr(settings, 'ADMIN_NOTIFICATIONS_ENABLED', False) and settings.BOT_TOKEN:
|
||||
bot = Bot(token=settings.BOT_TOKEN)
|
||||
try:
|
||||
notification_service = AdminNotificationService(bot)
|
||||
await notification_service.send_withdrawal_request_notification(
|
||||
user=user,
|
||||
amount_kopeks=request.amount_kopeks,
|
||||
payment_details=request.payment_details,
|
||||
)
|
||||
finally:
|
||||
await bot.session.close()
|
||||
except Exception as e:
|
||||
logger.error('Failed to send admin notification for withdrawal request', error=e)
|
||||
|
||||
return WithdrawalCreateResponse(
|
||||
id=withdrawal.id,
|
||||
amount_kopeks=withdrawal.amount_kopeks,
|
||||
|
||||
@@ -1635,6 +1635,103 @@ class AdminNotificationService:
|
||||
return str(value)
|
||||
return str(value)
|
||||
|
||||
async def send_partner_application_notification(
|
||||
self,
|
||||
user: User,
|
||||
application_data: dict[str, Any],
|
||||
) -> bool:
|
||||
"""Уведомление о новой заявке на партнёрку."""
|
||||
if not self._is_enabled():
|
||||
return False
|
||||
|
||||
try:
|
||||
user_display = self._get_user_display(user)
|
||||
user_id_display = self._get_user_identifier_display(user)
|
||||
|
||||
message_lines = [
|
||||
'🤝 <b>ЗАЯВКА НА ПАРТНЁРКУ</b>',
|
||||
'',
|
||||
f'👤 {user_display} ({user_id_display})',
|
||||
]
|
||||
|
||||
username = getattr(user, 'username', None)
|
||||
if username:
|
||||
message_lines.append(f'📱 @{username}')
|
||||
|
||||
message_lines.append('')
|
||||
|
||||
if application_data.get('company_name'):
|
||||
message_lines.append(f'🏢 Компания: {application_data["company_name"]}')
|
||||
if application_data.get('telegram_channel'):
|
||||
message_lines.append(f'📢 Канал: {application_data["telegram_channel"]}')
|
||||
if application_data.get('website_url'):
|
||||
message_lines.append(f'🌐 Сайт: {application_data["website_url"]}')
|
||||
if application_data.get('description'):
|
||||
desc = application_data['description']
|
||||
if len(desc) > 200:
|
||||
desc = desc[:197] + '...'
|
||||
message_lines.append(f'📝 {desc}')
|
||||
if application_data.get('expected_monthly_referrals'):
|
||||
message_lines.append(f'👥 Ожидаемых рефералов: {application_data["expected_monthly_referrals"]}/мес')
|
||||
|
||||
message_lines.extend([
|
||||
'',
|
||||
f'⏰ <i>{format_local_datetime(datetime.now(UTC), "%d.%m.%Y %H:%M:%S")}</i>',
|
||||
])
|
||||
|
||||
return await self._send_message('\n'.join(message_lines))
|
||||
|
||||
except Exception as e:
|
||||
logger.error('Ошибка отправки уведомления о заявке на партнёрку', error=e)
|
||||
return False
|
||||
|
||||
async def send_withdrawal_request_notification(
|
||||
self,
|
||||
user: User,
|
||||
amount_kopeks: int,
|
||||
payment_details: str | None = None,
|
||||
) -> bool:
|
||||
"""Уведомление о запросе на вывод средств."""
|
||||
if not self._is_enabled():
|
||||
return False
|
||||
|
||||
try:
|
||||
user_display = self._get_user_display(user)
|
||||
user_id_display = self._get_user_identifier_display(user)
|
||||
|
||||
message_lines = [
|
||||
'💸 <b>ЗАПРОС НА ВЫВОД СРЕДСТВ</b>',
|
||||
'',
|
||||
f'👤 {user_display} ({user_id_display})',
|
||||
]
|
||||
|
||||
username = getattr(user, 'username', None)
|
||||
if username:
|
||||
message_lines.append(f'📱 @{username}')
|
||||
|
||||
message_lines.extend([
|
||||
'',
|
||||
f'💵 <b>Сумма: {settings.format_price(amount_kopeks)}</b>',
|
||||
f'💰 Баланс: {settings.format_price(user.balance_kopeks)}',
|
||||
])
|
||||
|
||||
if payment_details:
|
||||
details = payment_details
|
||||
if len(details) > 200:
|
||||
details = details[:197] + '...'
|
||||
message_lines.extend(['', f'💳 Реквизиты: {details}'])
|
||||
|
||||
message_lines.extend([
|
||||
'',
|
||||
f'⏰ <i>{format_local_datetime(datetime.now(UTC), "%d.%m.%Y %H:%M:%S")}</i>',
|
||||
])
|
||||
|
||||
return await self._send_message('\n'.join(message_lines))
|
||||
|
||||
except Exception as e:
|
||||
logger.error('Ошибка отправки уведомления о запросе на вывод', error=e)
|
||||
return False
|
||||
|
||||
async def send_bulk_ban_notification(
|
||||
self,
|
||||
admin_user_id: int,
|
||||
|
||||
Reference in New Issue
Block a user