Mobile Native Notifications with FlowEngine

Description

Nowadays smartphones are increasingly considered a key part of any digital solution. Their increased computing capacities and the higher speed of Internet connections enable a new horizon of connected applications. Some IoT applications today use smartphones as gateways, but it is also normal to use the smartphone as a notification and awareness tool in some cases where speed is key.

That is why we have developed a new node for the onesait Platform Flow Engine: onesaitplatform-firebase-notification. This node has integration with Firebase. Firebase is a Google platform that helps developers manage the backend of their mobile applications. Some of the features of the platform are open to everyone, and that is the case of the cloud messaging function.

This article shows an example of native notifications for Android applications using the onesait Platform Flow Engine. The guide will highlight the process required to carry out the example using the onesait Platform modules, while the Firebase-specific task will only be mentioned but not explained in detail. Please contact us for additional information on how to integrate your mobile app within the Firebase platform.

For this example, we have built a custom Android application (app) with basic design and functionality:

This app has native integration with Firebase, which allows it to be connected to Firebase and receive native notifications (to learn more about the integration with Firebase, follow this link).

The behavior of the application is as follows:

  1. First, once the app is installed, it connects to Firebase and is given a Device Token. This token is unique to the Android device, although it can be updated later. It is advisable to monitor these changes using the callback inside the onNewToken method of your class, which extends FirebaseMessagingService.

  2. Every time a new token is granted, or when the user clicks the REGISTER DEVICE TOKEN button, the given token is sent to the onesait Platform. These token keys are stored in the NativeNotifKeys ontology, which looks like this (For this example, the application will be a messaging application, and the user will be the IMEI code of the host smartphone):

  3. To perform step 2, the NativeNotifKeys ontology must be created (it already exists in the demo environment), and an API endpoint will be created in the environment. This API will publish this ontology via a URL, with INSERT capabilities. For this example, this is what the API definition looks like:

  4. Now the app, which already has a valid Firebase token, has replicated this information in the onesait Platform, allowing developers to take advantage of this data and send notifications to these devices. But you still have to enable a way to push messages through the onesait Platform to end devices. That is why you must define this ontology, to record incoming messages:

  5. After the creation of the ontology, you have to define the rule to send the messages inserted in the notificationMessage ontology to the end devices. Use the onesait Platform Flow Engine module to perform this operation:

  6. The first block only inserts notification message in the platform. The second block then uses a onesaitplatform-notification-endpoint node to subscribe to the previous inserts in the notificationMessage ontology. This node will insert the message in the onesaitplatform-firebase-notification node, which handles the Firebase integration for the demo app.

  7. With the flow configured, and before starting to send notifications, let’s explore two different types of messages that we have integrated into the example:

    1. Notification to a single, specific device.

    2. Notification to all devices subscribed to a specific theme (or topic).

  8. To change this behavior, there is a topic field within the notificationMessage ontology. If it is blank ("topic":""), then the firebase-notification node will send this notification to the device corresponding to the user field within the message, using the current Firebase token updated by the app via the NativeNotifKeys API. These are the message, the output of the Flow Engine and how the notification appears on the mobile phone:

  

The notification appears quickly with the title and body that you define in the ontology instance. Firebase claims that over 95% of the notifications they send, are delivered within a 250-milisecond interval.

The last step will be to send notifications to a group of devices subscribed to a certain theme. To do that, first you have to go to the app and press the SUBSCRIBE TO NEWS button:

And then change the topic to “news” in the flow engine insertion:

To test the theme-based notifications, it is best to install the sample app on more than one phone so you can see the difference. From one phone, the result will be the arrival of the notification:

The time diagram to understand the complete flow of actions is this:

Now try it yourself and let us know how it went!

If you have any questions or requests, please contact us at support@onesaitplatform.com