Skip to main content
zerotal

Documentation


Documentation / @zerotal/notifications / OnDemandNotifiable

Class: OnDemandNotifiable

Defined in: notifications/src/OnDemandNotifiable.ts:26

A recipient addressed directly rather than looked up — Notify.route({ mail: "ops@acme.test" }).

It satisfies Notifiable without being a model, so every channel works unchanged. The database channel is the exception worth knowing about: rows it writes are keyed to a random id nothing can query back, which is why an on-demand notification normally declares only transport channels.

Implements

  • Notifiable

Constructors

Constructor

new OnDemandNotifiable(_routes): OnDemandNotifiable

Defined in: notifications/src/OnDemandNotifiable.ts:31

Parameters

_routes

OnDemandRoutes

Returns

OnDemandNotifiable

Properties

id

readonly id: string

Defined in: notifications/src/OnDemandNotifiable.ts:27

Implementation of

Notifiable.id


email?

readonly optional email?: string

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

Implementation of

Notifiable.email


phone?

readonly optional phone?: string

Defined in: notifications/src/OnDemandNotifiable.ts:29

Phone number in E.164 format, required when using the sms channel.

Implementation of

Notifiable.phone

Methods

routeNotificationFor()

routeNotificationFor(channel): string | undefined

Defined in: notifications/src/OnDemandNotifiable.ts:39

Per-channel destination override, consulted before the default field.

Return the address a channel should deliver to — an email for "mail", an E.164 number for "sms", a webhook URL for "slack" — or undefined to fall back. Lets one model route differently per channel without every notification having to know how.

Parameters

channel

string

Returns

string | undefined

Example

routeNotificationFor(channel: string) {
  return channel === "mail" ? this.billingEmail : undefined;
}

Implementation of

Notifiable.routeNotificationFor


receivesBroadcastNotificationsOn()

receivesBroadcastNotificationsOn(): string

Defined in: notifications/src/OnDemandNotifiable.ts:43

Override the channel this notifiable receives broadcast notifications on. Default: notifications.{id} (broadcast as a private channel). Used by the 'broadcast' channel.

Returns

string

Implementation of

Notifiable.receivesBroadcastNotificationsOn