nomadro/apps/nomadweb/backend/app/services/ntfy_push.py
eric d93a355fd5 Migrate navmini/ebook/nomadweb into apps/ as same-origin portal subpaths.
Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 03:30:34 -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