Skip to content
MSO CloudDocumentation

ADR 0047 — One notification preference store, four linkable channels

On this page
  • Status: Accepted. Shipped 2026-09-07.
  • Owners: Platform (alerts / notifications).
  • Extends: ADR 0046 (delivery posture, Phase 0), §79 (audience fence), §82 (brand partitioning).

Context#

Phase 1 shipped the Notification Center (inbox, bell, preference matrix), Phase 2 the channel layer (platform channel configs, the per-org allow matrix, four adapters) and the delivery worker. A verification pass found the feature only half reachable:

  1. Two preference stores. /settings/notifications wrote notification_preferences (type × channel, org- and brand-scoped) and no producer read it — emitNotification's external return value was never consumed. What decided who got an email was alert_rule_user_states.channels, written by /settings/alerts, which is where the dispatch was wired. Unticking email in the matrix changed nothing.
  2. Two channel vocabularies. @yng/notify's catalogue listed in-app / email / zalo; @yng/notify-channels and the adapters knew five. Web push and Telegram could not be selected anywhere in the product.
  3. No linking screen. registerPushSubscription, startTelegramLink and the Telegram webhook were reachable from no page. Only email reached a person end to end.

Decisions#

D1 — notification_preferences is the only answer to "which channel"

resolveDelivery (@yng/notify) computes it once, per recipient, per finding; emitNotification returns it as external; the alert engine sends on exactly that. A producer may NARROW the set — a per-rule mute or snooze, the account-level email veto (ADR 0046 D5) — and may never widen it.

alert_rule_user_states keeps mute and snooze, per rule, which is what /settings/alerts now asks and all it asks. Its channels column is dead state; migration 0202 carried the opt-ins that existed only there into notification_preferences (org-wide rows, muted rules excluded — a mute is a refusal, not an opt-in). Guard: scripts/audit/notification-single-preference-store.py.

D2 — A rule row's channels records what the rule shipped with and decides nothing

A rule is authored for an org; a channel is chosen by a person. Capping delivery by alert_rules.channels (ADR 0046 D2) put a per-org ceiling under a per-person choice, and since NEW_ALERT_RULE_CHANNELS is ['in-app'] that ceiling forbade every transport for every rule. The column stays for provenance; nothing reads it at delivery, and neither the dataset-rule authoring form nor the pack installer offers a channel picker any more. The PLATFORM ceiling (notification_settings, super admin, ADR 0046 D3) is unchanged and is applied by resolveDelivery.

D3 — One channel vocabulary, five tokens

NOTIFICATION_CHANNELS = ['in-app', 'web-push', 'email', 'telegram', 'zalo'] is declared once, in packages/notify/src/catalogue.ts, and re-exported by @yng/notify-channels. The matrix, the admin ceiling console and the adapters read that one list.

D4 — Four gates, in order, and every refusal is named

Nothing leaves the product unless: the platform has the channel configured, the org is allowed it, the person opted in for that notification type, and the person linked that channel. The first two are loadOrgChannelAvailability; the third is the matrix; the fourth is a per-user push_subscriptions row or a linked user_channel_identities row. emitNotification now REQUIRES availableChannels — there is no "assume everything" default — and the delivery worker skips a recipient with no target and records why.

A cell the person cannot tick renders the refusal (channel_not_configured, channel_not_allowed_for_org, channel_not_linked), and a save drops a channel that is not usable rather than storing a preference that could never be honoured.

D5 — A person links their own channels, from their own settings page

/settings/notifications carries a linking card above the matrix: enable browser push on this device, link or unlink Telegram, link or unlink Zalo. Email needs no link — it is the address on the account. Telegram and Zalo are linked by a one-time code the person sends to the bot or the OA; only the webhook that witnesses that message stamps linked_at, and only the code's hash is stored. Zalo's webhook verifies the OA signature (sha256(appId + body + timestamp + appSecret)) before it parses anything, which is why the platform Zalo config gained an appId field.

Consequences#

  • The default posture is unchanged and still load-bearing: absent preference = in-app only.
  • An org that wants email for a notification type still has no bulk switch: every person opts in for themselves, now per TYPE rather than per rule.
  • alert_rule_user_states.channels is never written again. The column is left in place (dropping it is not additive); it holds only pre-migration history.
  • A person who unlinks a channel keeps their stored preference for it; delivery skips it and the matrix shows why, so re-linking restores it without re-ticking.
  • A notification_settings ceiling row STORED before this change lists only the three channels that existed then. Web push and Telegram stay refused for that type — with the reason on the cell — until a super admin re-saves the row at /admin/notifications, which now offers all five. The rows are deliberately not widened by migration: a ceiling is a super admin's own statement, and ADR 0046 D2 forbids adding a channel anywhere but the narrowest end.