How-to guides

Receive alert push notifications

Register a device for Omni-channel alerts push after sign-in, keep it registered when its token changes, and open the alert a notification names.

  • Stable unknown
  • Release candidate not available
  • Development since 1.17.0-dev.2305+58d9b20

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-notificationsTerminal

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-inClient-side

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 notificationClient-side

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

  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.
ScenarioHow to trigger itExpected result
Same token registered againCall registerPushDevice twice on one device.One device is listed.
Token changesReinstall the app, or restore it on a new phone.The new token is registered without another call.
expo-notifications missingCall registerPushDevice without it installed.The call throws and names the missing module.
Web push subscriptionCall it with kind: 'native' on the web.The call throws a TypeError.

See also

Last updated on

On this page