Files
zurdi 8089040bfd feat(notifications): rebuild notification channels on Apprise
Forward notifications to any of the 100+ services Apprise reaches instead
of the two hand-coded webhook formats. The channel form lists every
Apprise service with the fields it takes, and the backend builds the
Apprise URL from them.

- New `apprise` channel type, admin only: Apprise opens its own
  connections, past the SSRF guard. The owner's role is checked again at
  every delivery.
- GET /api/notification-channels/apprise-services describes each service
  from Apprise's plugin details: URL tokens as fields, options as
  advanced fields. A field is required only when every URL template
  needs it.
- A channel stores the service and its fields sealed; the URL is built
  from the template those fields fill at each send. Local schemas, the
  options that read files and the ones RomM sets are never offered.
  Apprise follows no redirects, does not retry and its timeouts are
  capped.
- The RomM JSON webhook keeps its payload and HMAC signature; its
  Discord and ntfy formats go, Apprise covers them. Email is unchanged.
- The v2 dialog picks the type from one searchable list and renders the
  service's fields, options folded under "Advanced options".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 09:01:39 +02:00

48 lines
1.3 KiB
Python

"""What a channel keeps sealed: where it sends, and how."""
from typing import Any, NotRequired, TypedDict
from urllib.parse import urlsplit
from utils.secret_box import UnsealError, seal, unseal
class AppriseConfig(TypedDict):
service: str
# What the owner filled in, which the Apprise URL is built from.
fields: dict[str, Any]
class WebhookConfig(TypedDict):
url: str
# The key the payload is signed with.
secret: NotRequired[str | None]
class EmailConfig(TypedDict):
address: str
def seal_config(config: AppriseConfig | WebhookConfig | EmailConfig) -> str:
return seal(dict(config))
def read_config(sealed: str) -> dict[str, Any]:
"""A channel's config; empty when the auth secret changed since it was saved."""
try:
return unseal(sealed)
except UnsealError:
return {}
def origin(url: str) -> str:
"""The URL's scheme, host and port: whom a request to it reaches."""
parts = urlsplit(url)
port = f":{parts.port}" if parts.port else ""
return f"{parts.scheme}://{parts.hostname or ''}{port}"
def masked_url(url: str) -> str:
"""The URL with its path hidden, which is where a webhook keeps its token."""
tail = urlsplit(url).path.rstrip("/")[-4:]
return f"{origin(url)}/…{tail}" if tail else origin(url)