How to send an actionable push notification through Ionic? - push-notification

I am currently using Airnotifier and Firebase Cloud Messaging. From some other questions and after trying by myself, it seems Firebase does not support actionable notifications. Is there a way to create one somehow, or can we somehow send a request to the user's device and the application on that device can create an actionable local notification?
UPDATE: Just checked with the FCM API and SDK, title and body fields are accepted but actions and click_action are not seen anywhere. Is there a way to verify if those data have been given or if those are the correct name for the fields?
UPDATE2: gcm.notification.actions has shown in the notification received in iOS, but not click_action which I included in the notification field.
UPDATE3: It seems the "actions" field magically disappears after the "schedule" function is called in ionic's local notification plug in.

Related

Disable automatic display of notification by firebase

I would just like to receive the notification data via the OnMessageReceived method and then display a custom notification with Unity's MobileNotification or UTNotification.
Any information in the notification property of a message is automatically handled by the system when the app is not active. If you don't want the system to automatically display a notification, make sure that your message contains no notification property. Data only messages are not displayed by the system automatically.
For more on this, also see the Firebase documentation on message types.
While it is possible to add data properties to an FCM message that is sent through the Firebase console in the Custom data section of the Additional options, there is no way to send a data only message. Messages sent through the Firebase console will always have a notification property, which is what triggers the system to display them.
If you want to send data-only messages, the simplest way is through a CURL command as shown here: How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

Firebase custom notifications with FlutterFire

Thanks to Firebase and FlutterFire, it's easy to send regular notifications from the servers to the users' devices. Those notifications include a title, a body, and an image url. But what about creating a no-that-simple notification, like Telegram's or WhatsApp's?
The simple question is to avoid sending a Notification from the server, and instead set the data field to the push message. But according to the FlutterFire documentation:
Data only messages are considered low priority by devices when your application is in the background or terminated, and will be ignored
So, it sounds like if we want to have a reliable delivery system, we should add a Notification to our push messages. But that notification is so simple. And, again, according to the documentation:
If your message is a notification one (includes a notification property), the Firebase SDKs will intercept this and display a visible notification to your users (assuming you have requested permission & the user has notifications enabled)
So: If I want a reliable system, I have to send Notifications, but I do it, I can't tell FlutterFire to use my custom notifications.
So the question is: how to show custom notifications with FlutterFire?
What I want to achieve is something like this:
I'm going to try setting the priority of the push notification.
You can however explicitly increase the priority by sending additional properties on the FCM payload:
On Android, set the priority field to high.
On Apple (iOS & macOS), set the content-available field to true.
On the server side code, it looks like:
message.setAndroidConfig(AndroidConfig.builder().setPriority(AndroidConfig.Priority.HIGH).build());
message.setApnsConfig(ApnsConfig.builder().setAps(Aps.builder().setContentAvailable(true).build()).build());

Flutter and Firebase: Dynamic push notifications like Whatsapp

Most tutorials I've seen on the topic of notifications either broadcast notifications through the Firebase Console, or create in-app notifications that don't work if the app is in the background or is closed completely.
Is there a way to make notifications pop up dynamically using Flutter and Firebase even when the app is closed? Something like Whatsapp or Instagram notifications.
Reference image for what I mean by notifications like Whatsapp: https://www.techidence.com/wp-content/uploads/2020/10/WhatsApp-Nootifications.jpg
You won't be able to generate dynamic notifications directly from Flutter. Since to do this, the App has to be active. Usually you would send these kind of notifications from some kind of backend. Google Cloud Messaging exposes an API for this, which allows you to send POST requests to an Endpoint, and Google handles the sending of the actual notification.
Check this article under the point "1. Send Notification"
https://medium.com/#selvaganesh93/firebase-cloud-messaging-important-rest-apis-be79260022b5

How to send a push notification from the Firebase console to a specific GCM/FCM device token ID

In Urban Airship, when I am composing a notification, I can target specific users by searching for a Urban Airship channel_id (device ID):
I sent from Urban Airship the push notification that I am showing above, and I received it successfully. Now I want to do the same thing, send a push notification to a specific device, but now using the Firebase console. The problem is that in Firebase, in the step where I need to specify the target, it only allows me to choose User segment or topic. I was expecting to see a third option: Target specific users (for sending notifications to one or many specific GCM/FCM device token IDs. So my alternative is to add a GCM/FCM device token ID to a topic and then send the push notification to that topic, which is something that I have successfully done before. Nonetheless, that would be a workaround and not the way I would prefer to do this. Is it possible to send push notifications to specific users (by defining the target GCM/FCM device token IDs) from the Firebase console? Thank you.
UPDATE 1: See how the Firebase console (https://console.firebase.google.com/) only shows User segment and Topic as the Target:
First Step:
Second Step:
Third Step:
By design, the notification feature in the console is for sending out broadcast-type events. Sending user-specific alerts would be more of a programmatic operation done through the API.
For sending test messages, there is a console tool for this, explained here.
Note that it is possible to send a notification to one device by subscribing a device to any topic and sending the notification to that topic in the console (keep in mind topics are public and you can't prevent users from signing up to them; fine for testing most likely).
Another alternative is to send a message via HTTP or curl. Perhaps the best resource for this is the quickstart/messaging example.

Does Ionic 2 support private & public Firebase notifications?

I'm thinking to work on firebase notifications in the last few days but I want to some answers for this few questions:
Does Ionic2 support firebase notifications ?
Will notification show in the top of screen when my application closed or it should be work in the background ?
Is firebase notification sent on time or it may take long time ?
If I assumed Ionic 2 can send private notifications (to my device only), so can I send public notification for all application users ?
If the answer of all questions "yes", wish you give me any useful links that may help me (if you have a time)
In addition to Gabriel's answer:
The default behavior for notifications is for it to show on the top part of the screen. I haven't worked on Ionic before, but AFAIK, the behavior should compared to Android.
With that said, you should refer to the Handling Messages part of the FCM docs.
There are factors to consider that may affect the time it takes for the device to receive a message, but as FCM's behavior, it would try it's best to send the message, as soon as feasible (see my answer here).
Gonna itemize this further:
Specific device only - Yup. When sending the message, just specify the registration token(s) that should recieve that message.
All devices - Yup. You could use the Firebase Notifications Console. But if you intend to send the message by using the REST API, you have to make sure that the devices are subscribed accordingly to your custom global topic.
About the device-to-device Gabriel mentioned, I think it should be worded as server to specific device(s).
Yes it does, and it works fine with FCM (Firebase Cloud Messaging, aka GCM - Google Cloud Messaging). It supports subscribing to topics and device-to-device notification via HTTP client. The topics subscriptions and device-to-device both require FCM plugin.
Yes, they'll appear on top of your device screen as any push notification, you'll just need to code how it'll behave after receiving it, like execute something if the notification is tapped, or do something if it's received and the app is already open (foreground), it's all up to you.
It's sent on time, i've never had delay problems, the longer it took to send the notification and i receive in my device was 10 seconds. But as far as i know it "stores" your notification for 24 hours, so if the servers go down or something happen the notification has a life time of 24 hours to be sent.
You can, as said in first answer, subscribe your users to topics. Let's say you want a topic to sent message so all users can receive, you can have an all topic, or have one only for logged users, one only for users who bought products, you can even get all users tokens and send one by one, but it's much better having them subscribe to topics.
Topics notifications can be sent via the Firebase project console. Device-to-device is sent by your app code.
To send device-to-device you'll need a token, it's provided by the FCM plugin (link above) and you'll need to store this token somewhere, like in your user node on Firebase. I usualy use the user device ID provided by the Device plugin to have his token, since the user can have multiple devices and log in all then, this'll prevent token overriding.
I don't know good tutorials about configuring FCM with Firebase, if i find something i'll edit the question and add it for you, but stick to the ionic native link and the FCM plugin github page.
Hope this helps.

Resources