Notify moderators about service center applications

This commit is contained in:
VPN SaaS Dev
2026-05-15 04:45:54 +09:00
parent c0014ab4ea
commit 85b46a94b9
4 changed files with 65 additions and 17 deletions

View File

@@ -0,0 +1,27 @@
import httpx
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.config import settings
from app.models.user import User
MODERATOR_ROLES = {"admin", "verifier", "moderator"}
async def notify_user(user: User, text: str) -> None:
if not settings.bot_token or settings.app_env == "test":
return
try:
async with httpx.AsyncClient(timeout=5) as client:
await client.post(
f"https://api.telegram.org/bot{settings.bot_token}/sendMessage",
data={"chat_id": str(user.telegram_id), "text": text},
)
except Exception:
return
async def notify_platform_moderators(session: AsyncSession, text: str) -> None:
result = await session.execute(select(User).where(User.platform_role.in_(MODERATOR_ROLES)))
for user in result.scalars():
await notify_user(user, text)