[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationIntroduction

Introduction

How backend code puts a message in a user's notification list: categories, subjects and sending.

The notifications domain of @antelopejs/interface-dms is how backend code puts a message in a user's notification list. It has two halves. You declare a taxonomy once, and you use a builder every time you send.

The taxonomy is two levels deep. A category groups related notifications. A subject sits under a category and names one kind of message. Every notification is filed under a subject. Users choose what they receive per subject in their notification settings, so the subject you pick decides how the user sees the message grouped and whether the DMS delivers it at all.

You declare both levels at import time, with NotificationCategory() first and then the NotificationSubject() calls under it. Sending is a chain of calls. Notification() opens a builder, the setters fill in the icon, title, description and subject, and .build() returns an immutable SendableNotification. You dispatch that to one user, a list of users, the holders of a set of roles, or every user.

The Read notifications walkthrough shows the open notification bell with one unread message, and describes how a click marks a message read and how a new message reaches every open session of its recipient. The Notification preferences walkthrough shows the System category expanded to its subjects.

What the domain gives you

  • A two-level taxonomy. Categories group subjects, and subjects classify notifications. The DMS stores a user's preferences under the categoryId:subjectId pair.
  • Declarative registration. NotificationCategory() and NotificationSubject() register at import time and return plain info objects that you keep as constants and pass around.
  • Built-in system subjects. GeneralSubject, SecuritySubject, AccountSubject, CollaborationSubject and AutomationSubject cover the common platform messages, so you declare nothing for them.
  • A type-checked builder. The builder tracks the fields you have supplied in its type parameter, so .build() does not compile until the icon, the title, the description and the subject are all set.
  • Four dispatch targets. You send to one user, to a list of users, to every user holding at least one of a set of roles, or to every user.
  • Shared or individual read state. A multi-recipient send can give each recipient their own read state. It can also group the copies, so that one recipient reading the notification marks it read for all of them.
  • Preference-aware delivery. The DMS skips a send without an error for a user who turned the subject off. togglePermission marks the subjects that users may not turn off.
  • E-mail. A subject can offer e-mail next to the app, and a mail module registers the channel that sends it. See E-mail.

Dependencies

This interface relies on the following AntelopeJS package:

The implementation lives in the DMS module, so the interface only works in a project that loads @antelopejs/dms. Sending to users and roles uses the DMS user and role identifiers that the DMS auth and tenancy guide describes.

A first notification

The following example declares a category with one subject and sends a notification under it.

typescript
import {
  Notification,
  NotificationCategory,
  NotificationSubject,
} from "@antelopejs/interface-dms/notifications";

export const shopCategory = NotificationCategory("shop", {
  labelKey: "shop.notifications.categories.shop",
  descriptionKey: "shop.notifications.categories.shop_desc",
  icon: "i-ph-shopping-cart",
});

export const orderSubject = NotificationSubject("orders", {
  category: shopCategory,
  labelKey: "shop.notifications.subjects.orders",
  togglePermission: "default",
});

export async function notifyOrderShipped(
  userId: string,
  orderRef: string,
): Promise<void> {
  await Notification()
    .icon("i-ph-truck")
    .title("$shop.notifications.order_shipped.title")
    .description("$shop.notifications.order_shipped.description")
    .params({ orderRef })
    .subject(orderSubject)
    .linkTo("/shop/orders")
    .build()
    .toUser(userId);
}

The category comes first in the file because the DMS refuses a subject whose category it has not registered yet. The user sees the notification in the dashboard, and finds an orders switch under a shop group in their notification settings.

Pages in this section

  • Categories and subjects covers declaring categories and subjects, controlling what users may turn off, and the built-in system subjects.
  • Sending notifications covers building a notification, dispatching it to users, roles or everyone, and the rules that decide delivery.