nomadweb/backend/app/services/ntfy_push.py
eric 96fa96c61e Migrate auth/community/social to PocketBase and wire SeaweedFS S3 uploads.
Keep FastAPI as the only backend; add media upload, ntfy hook, and PB collection bootstrap for production.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 11:19:30 -05:00

32 lines
728 B
Python

"""ntfy push notifications (server: 127.0.0.1:2586)."""
from __future__ import annotations
import httpx
from app.config import settings
async def send_push(
topic: str,
title: str,
body: str,
*,
tags: list[str] | None = None,
click_url: str = "",
) -> bool:
if not settings.ntfy_enabled:
return False
base = settings.ntfy_url.rstrip("/")
url = f"{base}/{topic}"
headers: dict[str, str] = {"Title": title}
if click_url:
headers["Click"] = click_url
if tags:
headers["Tags"] = ",".join(tags)
try:
async with httpx.AsyncClient(timeout=8.0) as client:
r = await client.post(url, content=body, headers=headers)
return r.status_code < 300
except Exception:
return False