Omni-channel alerts and push
Learn how to register a device for alert push with your own token source, and how admins set and preview the rule that decides who hears of each alert.
- Stable unknown
- Release candidate not available
- Development since 0.2.0-dev.51+80996d9
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.push holds a signed-in person's devices and the project's push provider. ovok.omnichannelAlerts reads, sets and previews the rule, for project admins. registerPushDevice keeps the signed-in person's device registered.
Register the device after sign-in
The SDK has no push plugin of its own. Pass the token source your app already uses, such as firebase_messaging:
final messaging = FirebaseMessaging.instance;
await messaging.requestPermission();
final unregister = await registerPushDevice(
ovok,
token: messaging.getToken,
onTokenRefresh: messaging.onTokenRefresh,
platform: Platform.isIOS ? 'ios' : 'android',
appId: 'com.example.care',
);tokenreads the current token; it throws aStateErrorwhen the source has none yet.onTokenRefreshemits each new token, which is registered again.- Registering the same token again answers the same device. The token is never returned.
registerPushDevicecompletes with a function. Call it on sign-out, before the session ends: it stops listening and removes the device from Ovok.- Use
ovok.push.devices.register,listandunregisterdirectly when you manage tokens yourself.
Open the alert from a notification
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.
FirebaseMessaging.onMessageOpenedApp.listen((message) {
if (message.data['type'] == 'ovok.alert') {
openAlert(message.data['patientId'], message.data['alertId']);
}
});Set up push and the rule
await ovok.push.provider.create({'provider': 'relay', 'url': 'https://push.example.com/ovok'});
await ovok.projects.settings.update('OMNICHANNEL_ALERTS_ENABLED', true);
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']}},
[],
],
},
});
final preview = await ovok.omnichannelAlerts.preview({
'patientId': patientId,
'event': 'alert.refired',
});- These calls are for project admins.
- The push provider is
fcm,apns,expoorrelay. A relay'swhsec_signing secret is answered once, bycreate. logicis JSON Logic that answersnotifyentries, each namingchannelsand 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.valueandpatient.id.eventis one ofalert.triggered,alert.empty,alert.note,alert.inactive,alert.refired,alert.resolvedandalert.acknowledged. - Channels are
pushandemail; roles arepractitioner,caregiver,relatedPersonandsharedWith. An unknown label (UNKNOWN_NOTIFY_LABELS) or a rule that cannot run on every event (INVALID_NOTIFICATIONS) throws anOvokValidationException. previewanswers thenotifyentries for that event, each with the people its roles resolve to for that patient.eventisalert.triggeredwhen omitted. Addnotificationsto try a rule before you save it. Nothing is sent.
See also
Last updated on