Skip to content
MSO CloudDocumentation

Add a notification channel

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_REGISTRY in packages/notify/src/channels.ts (pure, importable from a client bundle): id, kind (in_app or external), userLink (none, push_subscription, link_code), i18nLabelKey, defaultLabel, delivery (inbox, per_item, digest), format (rich, html, text, template), optional minSeverity.
  • Adapter: defineChannelAdapter in packages/notify-channels/src/adapters/contract.ts. Five things: a named Zod configSchema for the platform credential (carries channel), publicMeta (the non-secret part an admin list may render), resolveUserTargets plus optional revokeTarget, deliver (never throws; returns a classified ChannelSendOutcome), and a testSend the helper supplies.
  • Failure classes: ChannelFailureKind in packages/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, no org_id), organization allow-matrix in org_notification_channels (a missing row is off), person link in user_channel_identities or push_subscriptions; all in packages/schema/src/tables/notification-channels.ts. The channel column is varchar(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#

  1. Add the row to NOTIFICATION_CHANNEL_REGISTRY (packages/notify/src/channels.ts).
  2. Add the label key (notifications.channel<Name>) to packages/i18n/src/messages/{vi,en}.ts.
  3. Write packages/notify-channels/src/channels/<id>.ts with defineChannelAdapter: config and target schemas with channel: z.literal('<id>'), a failure-rule table passed to classifyHttpStatus (add the table to classify.ts only when the status mapping differs from the existing ones), deliver using the shared message shape in packages/notify-channels/src/message.ts.
  4. Register the adapter in packages/notify-channels/src/adapters/registry.ts.
  5. If people link an identity (link_code), reuse packages/notify-channels/src/identities.ts and the link-code helper in the Telegram adapter.
  6. Add tests next to the adapter with a stubbed fetch: one per failure class, and that no credential reaches reason or logs.
  7. 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_deliveries row before any provider call, which is the idempotency guard for providers without one. Bursts reach external channels as one digest where delivery is digest.
  • The queue notify retries 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; unsubscribe revokes the target through revokeTarget.
  • The notify:sweep job (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_RULES and RESEND_FAILURE_RULES are 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.