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',
);
  • token reads the current token; it throws a StateError when the source has none yet. onTokenRefresh emits each new token, which is registered again.
  • Registering the same token again answers the same device. The token is never returned.
  • registerPushDevice completes 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, list and unregister directly 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, expo or relay. A relay's whsec_ signing secret is answered once, by create.
  • logic is JSON Logic that 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) throws an OvokValidationException.
  • preview answers the notify entries for that event, each with the people its roles resolve to for that patient. event is alert.triggered when omitted. Add notifications to try a rule before you save it. Nothing is sent.

See also

Last updated on

On this page