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
notificationsoption of the@ovok/nativeapp 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' });
}kindfollows the project's push provider:expofor Expo,nativefor APNs, FCM or a relay.nativeregisters the device's own APNs or FCM token.- For
expo, passprojectIdwhen the app config has no EAS project id. registerPushDeviceregisters 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
datawithtype: 'ovok.alert',alertId,patientIdandevent, the Signals alert event it was sent for, such asalert.triggeredoralert.refired. - The lock screen shows "New alert" in the person's language, never a name or a value.
Test your integration
- In the Ovok Console, turn on Omni-channel alerts, set up the push provider, and set a rule that names
pushand a role this person has foralert.triggered. - Sign in on a device and call
registerPushDevice. - Call
ovok.push.devices.list(). Confirm the device is listed. - Raise a Signals alert for a patient this person is told about. Confirm the push arrives, carries
event: 'alert.triggered', and opens the alert. - Call the function
registerPushDeviceresolved to. Confirmovok.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
- The Ovok client
- Background sync for notification permission.
ovok.pushin the JavaScript SDK- Troubleshooting
Last updated on