On this page
A channel is a transport that carries a notification out of the product: web push, email, Telegram and Zalo exist. A new channel is one registry row and one adapter; the compiler refuses one without the other.
When to use#
Use it when an existing notification type (alert, brief, subscription digest) must also reach people on another transport. The in-app inbox is the floor and has no adapter. To change who is told or which channel a person chose, you change data, not code: the platform-configured, organization-allowed and person-opted-in gates decide, and an adapter cannot widen them (ADR 0050, rule §136 in .claude/rules/notification-delivery.md). To call a customer's own webhook, build it as a channel; the platform webhooks of Platform API and events carry app events, not notifications.
The contract#
- Registry row:
NOTIFICATION_CHANNEL_REGISTRYinpackages/notify/src/channels.ts(pure, importable from a client bundle):id,kind(in_apporexternal),userLink(none,push_subscription,link_code),i18nLabelKey,defaultLabel,delivery(inbox,per_item,digest),format(rich,html,text,template), optionalminSeverity. - Adapter:
defineChannelAdapterinpackages/notify-channels/src/adapters/contract.ts. Five things: a named ZodconfigSchemafor the platform credential (carrieschannel),publicMeta(the non-secret part an admin list may render),resolveUserTargetsplus optionalrevokeTarget,deliver(never throws; returns a classifiedChannelSendOutcome), and atestSendthe helper supplies. - Failure classes:
ChannelFailureKindinpackages/notify-channels/src/classify.ts:permanent(our request was wrong, no retry),transient(retry with backoff),unsubscribe(target gone, revoke it). - Storage: platform credential in
notification_channel_configs(encrypted, noorg_id), organization allow-matrix inorg_notification_channels(a missing row is off), person link inuser_channel_identitiesorpush_subscriptions; all inpackages/schema/src/tables/notification-channels.ts. Thechannelcolumn isvarchar(16), so the id fits 16 characters.
How registration works#
NOTIFICATION_CHANNEL_ADAPTERS in packages/notify-channels/src/adapters/registry.ts is as const satisfies Record<ExternalNotificationChannel, NotificationChannelAdapter>: a registry row with no adapter fails to compile, and the config and target unions are derived from the adapters, so nothing is hand-listed. The ids live in the pure package because a credential and an HTTP transport may not enter a client bundle.
Add one#
- Add the row to
NOTIFICATION_CHANNEL_REGISTRY(packages/notify/src/channels.ts). - Add the label key (
notifications.channel<Name>) topackages/i18n/src/messages/{vi,en}.ts. - Write
packages/notify-channels/src/channels/<id>.tswithdefineChannelAdapter: config and target schemas withchannel: z.literal('<id>'), a failure-rule table passed toclassifyHttpStatus(add the table toclassify.tsonly when the status mapping differs from the existing ones),deliverusing the shared message shape inpackages/notify-channels/src/message.ts. - Register the adapter in
packages/notify-channels/src/adapters/registry.ts. - If people link an identity (
link_code), reusepackages/notify-channels/src/identities.tsand the link-code helper in the Telegram adapter. - Add tests next to the adapter with a stubbed
fetch: one per failure class, and that no credential reachesreasonor logs. - The admin card appears from the registry at
apps/web/src/app/admin/notifications/channels; a super admin enters the platform credential, then allows it per organization.
Guards#
packages/notify-channels/src/adapters/registry.test.ts, send.test.ts, allow.test.ts, catalogue.test.ts; scripts/audit/notification-single-preference-store.py (in audit:all); scripts/audit/rls-notification-isolation.ts (tenancy gate, verify:rls); rule pack .claude/rules/notification-delivery.md.
Operating it#
- An external copy is claimed as a
notification_deliveriesrow before any provider call, which is the idempotency guard for providers without one. Bursts reach external channels as one digest wheredeliveryisdigest. - The queue
notifyretries a transient failure with BullMQ backoff (5 attempts, 30 s doubling); on the last attempt the failure becomes a visible delivery row, not a dead letter (apps/worker/src/processors/notify-delivery.ts). A permanent failure stops at once;unsubscriberevokes the target throughrevokeTarget. - The
notify:sweepjob (every 5 minutes,apps/worker/src/schedules.ts) reconciles external deliveries that were claimed and never settled. Operators read results in the admin deliveries view (apps/web/src/app/admin/notifications/deliveries).
Where it stops#
- The Zalo adapter exists in the registry, but the dashboard-subscription processor sends mail only and its Zalo client is not wired to a credential or follower ids (
apps/worker/src/processors/dashboard-subscription.ts); see Project status for what a customer can use. ZALO_FAILURE_RULESandRESEND_FAILURE_RULESare identical copies.- A new notification type is declared at a vertical or domain registry row, not in the channel code.
- There is no per-organization credential: channel credentials are platform-wide.