Notify moderators about service center applications
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
from datetime import UTC, datetime
|
||||
|
||||
import httpx
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.deps import get_current_telegram_user, log_audit, require_platform_role
|
||||
from app.core.config import settings
|
||||
from app.db.session import get_session
|
||||
from app.models.car import (
|
||||
AuditLog,
|
||||
@@ -17,6 +15,7 @@ from app.models.car import (
|
||||
)
|
||||
from app.models.user import User
|
||||
from app.schemas.service_center import AdminModerationDecision, ServiceCenterRead, ServiceVisitRead
|
||||
from app.services.notifications import notify_user
|
||||
|
||||
router = APIRouter(prefix="/admin", tags=["admin"])
|
||||
|
||||
@@ -261,16 +260,3 @@ async def ensure_owner_employee(session: AsyncSession, service_center_id: int, o
|
||||
else:
|
||||
employee.role = "owner"
|
||||
employee.status = "active"
|
||||
|
||||
|
||||
async def notify_user(user: User, text: str) -> None:
|
||||
if not settings.bot_token:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user