Add owner work order approval page
Some checks failed
ci / test (push) Has been cancelled

This commit is contained in:
VPN SaaS Dev
2026-05-16 10:51:05 +09:00
parent ac5845d5a0
commit 545f4d088d
12 changed files with 1066 additions and 48 deletions

View File

@@ -1,3 +1,4 @@
import json
from datetime import UTC, datetime, timedelta
import httpx
@@ -11,14 +12,26 @@ from app.models.user import User
MODERATOR_ROLES = {"admin", "verifier", "moderator"}
async def notify_user(user: User, text: str) -> bool:
async def notify_user(
user: User,
text: str,
*,
web_app_url: str | None = None,
button_text: str = "Открыть",
) -> bool:
if not settings.bot_token or settings.app_env == "test":
return False
data: dict[str, str] = {"chat_id": str(user.telegram_id), "text": text}
if web_app_url:
data["reply_markup"] = json.dumps(
{"inline_keyboard": [[{"text": button_text, "web_app": {"url": web_app_url}}]]},
ensure_ascii=False,
)
try:
async with httpx.AsyncClient(timeout=5) as client:
response = await client.post(
f"https://api.telegram.org/bot{settings.bot_token}/sendMessage",
data={"chat_id": str(user.telegram_id), "text": text},
data=data,
)
return response.status_code < 400
except Exception: