Skip to main content
zerotal

Documentation


Documentation / @zerotal/notifications / NotificationManager

Class: NotificationManager

Defined in: notifications/src/NotificationManager.ts:21

Constructors

Constructor

new NotificationManager(config): NotificationManager

Defined in: notifications/src/NotificationManager.ts:28

Parameters

config

NotificationConfigShape

Returns

NotificationManager

Accessors

database

Get Signature

get database(): DatabaseChannel

Defined in: notifications/src/NotificationManager.ts:243

Expose the database channel for direct queries (unread, markAsRead).

Returns

DatabaseChannel

Methods

extend()

extend(channel, factory): this

Defined in: notifications/src/NotificationManager.ts:71

Register a custom delivery channel, or replace a built-in one.

The factory runs once, the first time the channel is used, so a channel nobody sends on costs nothing.

Parameters

channel

string

factory

ChannelResolver

Returns

this

Example

// in a service provider's onBooted()
const notify = app.container.makeSync("notifications");
notify.extend("discord", () => new DiscordChannel(config));

// then, in a notification
channels() { return ["discord"]; }
toDiscord() { return { content: "Deploy finished" }; }

channels()

channels(): string[]

Defined in: notifications/src/NotificationManager.ts:78

Every registered channel name, built-in and custom.

Returns

string[]


send()

send(notifiable, notification): Promise<void>

Defined in: notifications/src/NotificationManager.ts:95

Send a notification via all declared channels immediately.

Every channel is attempted even if an earlier one fails — a Slack webhook returning 500 must not cost the recipient the email and the stored row that were declared alongside it. If any channel failed, the failures are reported together as a NotificationDispatchError once the rest are delivered.

Parameters

notifiable

Notifiable

notification

Notification

Returns

Promise<void>

Throws

when one or more channels failed.

Example

await Notify.send(user, new OrderShippedNotification(order));

sendMany()

sendMany(notifiables, notification): Promise<void>

Defined in: notifications/src/NotificationManager.ts:150

Send one notification to many recipients.

Recipients are independent: one failing does not stop the rest, and the errors are reported together at the end.

Parameters

notifiables

Iterable<Notifiable>

notification

Notification

Returns

Promise<void>

Throws

when one or more recipients failed.

Example

await Notify.sendMany(admins, new LowStockNotification(product));

queueMany()

queueMany(notifiables, notification): Promise<void>

Defined in: notifications/src/NotificationManager.ts:176

Queue one notification for many recipients.

Parameters

notifiables

Iterable<Notifiable>

notification

Notification

Returns

Promise<void>


route()

route(routes): object

Defined in: notifications/src/NotificationManager.ts:191

Notify a destination that has no model behind it — a bare email address, phone number, or Slack webhook.

Parameters

routes

OnDemandRoutes

Returns

object

notify()

notify(notification): Promise<void>

Parameters
notification

Notification

Returns

Promise<void>

notifyLater()

notifyLater(notification): Promise<void>

Parameters
notification

Notification

Returns

Promise<void>

Example

await Notify.route({ mail: "ops@acme.test" }).notify(new DeployFinished(build));
await Notify.route({ sms: "+15551234567", mail: "on-call@acme.test" })
  .notifyLater(new PagerAlert(incident));

queue()

queue(notifiable, notification): Promise<void>

Defined in: notifications/src/NotificationManager.ts:213

Queue the notification for background delivery via @zerotal/queue.

Parameters

notifiable

Notifiable

notification

Notification

Returns

Promise<void>

Example

await Notify.queue(user, new OrderShippedNotification(order));