[**Documentation**](../../../README)

***

[Documentation](../../../README) / [@zerotal/notifications](../README) / NotificationManager

# Class: NotificationManager

Defined in: [notifications/src/NotificationManager.ts:21](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L21)

## Constructors

### Constructor

> **new NotificationManager**(`config`): `NotificationManager`

Defined in: [notifications/src/NotificationManager.ts:28](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L28)

#### Parameters

##### config

[`NotificationConfigShape`](../interfaces/NotificationConfigShape)

#### Returns

`NotificationManager`

## Accessors

### database

#### Get Signature

> **get** **database**(): [`DatabaseChannel`](DatabaseChannel)

Defined in: [notifications/src/NotificationManager.ts:243](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L243)

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

##### Returns

[`DatabaseChannel`](DatabaseChannel)

## Methods

### extend()

> **extend**(`channel`, `factory`): `this`

Defined in: [notifications/src/NotificationManager.ts:71](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L71)

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

```ts
// 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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L78)

Every registered channel name, built-in and custom.

#### Returns

`string`[]

***

### send()

> **send**(`notifiable`, `notification`): `Promise`\<`void`\>

Defined in: [notifications/src/NotificationManager.ts:95](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L95)

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](NotificationDispatchError) once the rest are delivered.

#### Parameters

##### notifiable

`Notifiable`

##### notification

[`Notification`](Notification)

#### Returns

`Promise`\<`void`\>

#### Throws

when one or more channels failed.

#### Example

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

***

### sendMany()

> **sendMany**(`notifiables`, `notification`): `Promise`\<`void`\>

Defined in: [notifications/src/NotificationManager.ts:150](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L150)

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`](Notification)

#### Returns

`Promise`\<`void`\>

#### Throws

when one or more recipients failed.

#### Example

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

***

### queueMany()

> **queueMany**(`notifiables`, `notification`): `Promise`\<`void`\>

Defined in: [notifications/src/NotificationManager.ts:176](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L176)

Queue one notification for many recipients.

#### Parameters

##### notifiables

`Iterable`\<`Notifiable`\>

##### notification

[`Notification`](Notification)

#### Returns

`Promise`\<`void`\>

***

### route()

> **route**(`routes`): `object`

Defined in: [notifications/src/NotificationManager.ts:191](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L191)

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

#### Parameters

##### routes

[`OnDemandRoutes`](../interfaces/OnDemandRoutes)

#### Returns

`object`

##### notify()

> **notify**(`notification`): `Promise`\<`void`\>

###### Parameters

###### notification

[`Notification`](Notification)

###### Returns

`Promise`\<`void`\>

##### notifyLater()

> **notifyLater**(`notification`): `Promise`\<`void`\>

###### Parameters

###### notification

[`Notification`](Notification)

###### Returns

`Promise`\<`void`\>

#### Example

```ts
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](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/notifications/src/NotificationManager.ts#L213)

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

#### Parameters

##### notifiable

`Notifiable`

##### notification

[`Notification`](Notification)

#### Returns

`Promise`\<`void`\>

#### Example

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