# Receive alert push notifications

Canonical page: https://docs.ovok.com/native-sdk/guide/how-to/push-notifications

**Complexity:** 2 of 5 · **Client:** React Native (`@ovok/native`) · **Time:** about 20 minutes

Ovok runs the project's omni-channel alerts rule on each alert event Signals sends, and tells the people it names by push and email. This guide makes a signed-in person's device receive that push. A project admin turns the feature on and sets up the push provider in the Ovok Console.

## Install expo-notifications [Terminal] [#install-expo-notifications-terminal]

```bash
npx expo install expo-notifications
```

- Turn on the `notifications` option of the `@ovok/native` app plugin, which adds the expo-notifications plugin.
- For APNs or FCM, configure your iOS push entitlement and Firebase files as the expo-notifications docs describe.

## Register the device after sign-in [Client-side] [#register-the-device-after-sign-in-client-side]

```ts
import { requestPushNotificationPermission } from '@ovok/native/background-sync';
import { registerPushDevice } from '@ovok/native';

if ((await requestPushNotificationPermission()) === 'granted') {
  const unregister = await registerPushDevice(ovok, { kind: 'expo', appId: 'com.example.care' });
}
```

- `kind` follows the project's push provider: `expo` for Expo, `native` for APNs, FCM or a relay. `native` registers the device's own APNs or FCM token.
- For `expo`, pass `projectId` when the app config has no EAS project id.
- `registerPushDevice` registers the token to the signed-in person, and registers it again whenever the token changes.
- It resolves to a function. Call that function on sign-out, before the session ends: it stops listening for token changes and removes the device from Ovok.

## Open the alert from a notification [Client-side] [#open-the-alert-from-a-notification-client-side]

```ts
import * as Notifications from 'expo-notifications';

Notifications.addNotificationResponseReceivedListener((response) => {
  const data = response.notification.request.content.data;

  if (data.type === 'ovok.alert') {
    router.push(`/patients/${String(data.patientId)}/alerts/${String(data.alertId)}`);
  }
});
```

- Each alert push carries `data` with `type: 'ovok.alert'`, `alertId`, `patientId` and `event`, the Signals alert event it was sent for, such as `alert.triggered` or `alert.refired`.
- The lock screen shows "New alert" in the person's language, never a name or a value.

## Test your integration [#test-your-integration]

1. In the Ovok Console, turn on Omni-channel alerts, set up the push provider, and set a rule that names `push` and a role this person has for `alert.triggered`.
2. Sign in on a device and call `registerPushDevice`.
3. Call `ovok.push.devices.list()`. Confirm the device is listed.
4. Raise a Signals alert for a patient this person is told about. Confirm the push arrives, carries `event: 'alert.triggered'`, and opens the alert.
5. Call the function `registerPushDevice` resolved to. Confirm `ovok.push.devices.list()` no longer lists the device.

| Scenario | How to trigger it | Expected result |
| --- | --- | --- |
| Same token registered again | Call `registerPushDevice` twice on one device. | One device is listed. |
| Token changes | Reinstall the app, or restore it on a new phone. | The new token is registered without another call. |
| expo-notifications missing | Call `registerPushDevice` without it installed. | The call throws and names the missing module. |
| Web push subscription | Call it with `kind: 'native'` on the web. | The call throws a `TypeError`. |

## See also [#see-also]

- [The Ovok client](../modules/next.md)
- [Background sync](../modules/background-sync.md) for notification permission.
- [`ovok.push` in the JavaScript SDK](https://docs.ovok.com/web-sdk/core/namespaces/push)
- [Troubleshooting](troubleshooting.md)
