Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

click_action attribute for web push notification through FCM

My questions is some what similar to (question) but with some differences. I am using FCM Admin SDK, but still do not see an option to send the click_action attribute for Web Push notifications. I checked out admin.messaging.NotificationMessagePayload as well, but looks like this is only applicable to Android and iOS.

As per the comments in the above questions, this click_action is not available for web push using http v1 API (and I think FCM admin SDK as well)

Please help me on how to send the click_action attribute for a web push notification using FCM Admin SDK. If there are any other workarounds, that would be helpful as well.

Thanks in advance.

like image 912
addicted20015 Avatar asked May 03 '18 06:05

addicted20015


People also ask

What is collapse key in FCM?

The collapse key collapses only the notifications bearing the same collapse key. If a user sends 10 notifications with the same collapse key (for example, "SCORE") and 2 notifications without any collapse key and they are not received by the device as the device was offline.

How does FCM push notification work?

The FCM backend receives the message request, generates a message ID and other metadata, and sends it to the platform specific transport layer. When the device is online, the message is sent via the platform-specific transport layer to the device. On the device, the client app receives the message or notification.


2 Answers

There is some confusion on how to open a page once you click on the notification popup. The documentation asks to use FCMOptions link attribute however it does not correctly open the page but just brings the browser to the foreground with the last tab to focus(). The solution to this is to change the payload to use click_action.

"notification":{
   "body":"this is the notification text",
   "title":"New Notification",
   "click_action":"https://theURLyouwanttoopen.com/"
}

Check more

like image 172
mixdev Avatar answered Oct 05 '22 04:10

mixdev


I've got the same issue here.

After some trial, as Adrien said, it works but just not documented yet.

And also not included in admin SDK as well. (at least in Python, which I'm using)

Refer to another answer to the same question https://stackoverflow.com/a/52764782/1318878

You can use custom data to do it.

Here's how I create a notification with click action in Python:

notification=messaging.WebpushNotification(
    title=<your_title>,
    body=<your_body>,
    custom_data={"click_action": <your_url>}
)
like image 22
rexx Avatar answered Oct 05 '22 04:10

rexx