# Omni-channel alerts

Canonical page: https://docs.ovok.com/python-sdk/namespaces/omnichannel-alerts

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.omnichannel_alerts` reads, sets and previews that rule. It is for project admins, and it needs the `OMNICHANNEL_ALERTS_ENABLED` setting on.

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

```python
ovok.projects.settings.update("OMNICHANNEL_ALERTS_ENABLED", True)

ovok.omnichannel_alerts.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`. An unknown label (`UNKNOWN_NOTIFY_LABELS`) or a rule that cannot run on every event (`INVALID_NOTIFICATIONS`) raises `OvokValidationError`.
- `retrieve` reads the rule under `notifications`, None when the project has none. `remove` deletes it.

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

```python
preview = ovok.omnichannel_alerts.preview({"patientId": patient_id, "event": "alert.refired"})

for entry in preview["notify"]:
    print(entry["channels"], [person["display"] for person in entry["recipients"]])
```

- 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. Add `alert` to set the sample alert's `code`, `reason`, `message` or `value`, and `notifications` to try a rule before you save it. Nothing is sent.

## See also [#see-also]

- [Push](/python-sdk/namespaces/push)
- [Projects](/python-sdk/namespaces/projects)
- [`OmnichannelAlertsResource` reference](/python-sdk/reference/resources/omnichannel_alerts#omnichannelalertsresource)
