Skip to main content

Module notify

Module notify 

Source
Expand description

Notifications — one delivery path, many destinations.

Before this, every notification in the CMS was an email loop written where it was needed: form submissions built theirs inline in the submit handler, page publishes built theirs in page_subscription, workflow events in workflow_mail. Adding Slack meant writing a fourth loop, and adding Teams a fifth — per event, forever.

So the destination is a plugin, not a branch:

  • Notification is what happened, in channel-agnostic terms — a title, a summary, some labelled fields, maybe a link. It never knows who will render it.
  • NotificationChannel renders and delivers one. Email writes a message, Slack posts blocks, Telegram sends Markdown. Register one with register_notification_channel! and it is available everywhere, including from a host app’s own crate.
  • A Target row is a configured destination: which channel, its settings, its secret, and which events it wants.

§Delivery is durable on purpose

enqueue writes a row per target and returns; a worker (worker::drain) sends with backoff. Notifications are the part of a form nobody watches until it silently stops working, and the failure modes here are all transient and external — a rate limit, an expired webhook, a five-minute Slack outage. Sending inline would mean the visitor waits on Slack, and a failure would be a log line nobody reads while the lead is gone. A row that says failed, 3 attempts, 429 is recoverable; a warning in yesterday’s journal is not.

Modules§

channels
Built-in destinations.
events
Event keys. Constants rather than literals so a typo at the emit site cannot silently produce an event no target subscribes to.
model
Persisted notification config + the delivery outbox.
targets
Keeping a form’s notify_emails setting and the target table in step.
worker
The outbox: enqueue on the request path, deliver off it.

Structs§

ChannelRegistration
Registration slot — see register_notification_channel!.
ConfigField
One configurable setting on a channel, rendered into the admin form. Reuses the widget vocabulary the rest of the admin speaks rather than inventing a second one.
Delivery
Everything a channel needs to deliver: its resolved configuration and the decrypted secret.
Notification
What happened, in terms every channel can render.

Enums§

DeliverError
Why a delivery failed, which decides whether the worker tries again.

Traits§

NotificationChannel
A destination kind. Implement it, register it, and it appears in the admin’s channel picker with its own settings.

Functions§

channel_for
The channel handling kind, or None when a target names a channel this binary was not built with — a real case for host-registered channels, so it must not panic.
registered_channels
Every registered channel, in registration order.