# ovok.omnichannelAlerts

Canonical page: https://docs.ovok.com/web-sdk/core/namespaces/omnichannelalerts

Ovok keeps the project's omni-channel alerts rule and runs it on each alert event Signals sends. The rule names who to tell and over which channel, and Ovok tells them by push and email. `ovok.omnichannelAlerts` reads, sets and previews that rule. It is for project admins, and it needs the `OMNICHANNEL_ALERTS_ENABLED` setting on.

## Turn it on [#turn-it-on]

```ts
await ovok.projects.settings.update('OMNICHANNEL_ALERTS_ENABLED', true);
```

## Set the rule [#set-the-rule]

```ts
await ovok.omnichannelAlerts.rules.update({
  logic: {
    if: [
      { '==': [{ var: 'event' }, 'alert.triggered'] },
      { notify: { channels: ['push', 'email'], to: ['practitioner', 'caregiver'] } },
      { '==': [{ var: 'event' }, 'alert.refired'] },
      { notify: { channels: ['push', 'email'], to: ['relatedPerson', 'sharedWith'] } },
      [],
    ],
  },
});
```

- `logic` is JSON Logic. It answers `notify` entries, each naming `channels` and the roles to tell (`to`), or an empty list to tell nobody.
- The logic can read `event`, `alert.id`, `alert.code`, `alert.reason`, `alert.message`, `alert.value` and `patient.id`.
- `event` is one of `alert.triggered`, `alert.empty`, `alert.note`, `alert.inactive`, `alert.refired`, `alert.resolved` and `alert.acknowledged`.
- Channels are `push` and `email`. Roles are `practitioner`, `caregiver`, `relatedPerson` and `sharedWith`. Any other label is refused with `UNKNOWN_NOTIFY_LABELS`, and a rule that cannot run on every event is refused with `INVALID_NOTIFICATIONS`; both are validation errors.
- `retrieve` reads the rule, and `notifications` is null when the project has none. `remove` deletes it, so nobody is told of a new alert event.

## Preview who it reaches [#preview-who-it-reaches]

```ts
const { notify } = await ovok.omnichannelAlerts.preview({
  patientId,
  event: 'alert.refired',
});

for (const entry of notify) {
  console.log(entry.channels, entry.recipients.map((person) => person.display));
}
```

- Each entry lists the people its roles resolve to for that patient, and whether each has an email address on file.
- `event` is `alert.triggered` when omitted. Pass `alert` to set the sample alert's `code`, `reason`, `message` or `value`.
- Pass `notifications` to try a rule before you save it. Nothing is sent.
- The calls go to `v1/omnichannel-alerts/rules` and `v1/omnichannel-alerts/preview`.

## See also [#see-also]

- [omnichannelAlerts API reference](../reference/core/omnichannelalerts.mdx): every method and type.
- [ovok.push](./push.mdx) to register devices and set up the push provider.
- [ovok.projects](./projects.mdx) for project settings.
- [Errors and retries](../errors-and-retries.mdx)
