douyinWEB/backend/app/notify.py
eric 76afafa6c9 Initial commit: Douyin live monitor with sh2-aligned probe.
Next.js + FastAPI + PocketBase stack for room/session monitoring, cookie sync from sh2, and anti-risk polling defaults.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 09:03:00 -05:00

37 lines
918 B
Python

from __future__ import annotations
import asyncio
from typing import Any
import httpx
from . import db
async def send_webhook(event: str, payload: dict[str, Any]) -> None:
cfg = db.get_settings_map()
url = str(cfg.get("notify_webhook_url") or "").strip()
if not url:
return
if event == "live" and not cfg.get("notify_on_live", True):
return
if event == "offline" and not cfg.get("notify_on_offline", False):
return
if event == "risk" and not cfg.get("notify_on_risk", True):
return
body = {
"event": event,
"text": payload.get("message") or event,
"payload": payload,
}
async def _post() -> None:
try:
async with httpx.AsyncClient(timeout=8.0, trust_env=False) as client:
await client.post(url, json=body)
except Exception:
pass
asyncio.create_task(_post())