7

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.

addicted20015
  • 589
  • 6
  • 16
  • I replied here. https://stackoverflow.com/questions/49177428/http-v1-api-click-action-for-webpush-notification/51268298#51268298 – Adrien Jul 12 '18 at 09:45

2 Answers2

4

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

mixdev
  • 2,454
  • 2
  • 27
  • 23
1

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>}
)
rexx
  • 58
  • 1
  • 7
  • 2
    Found another solution: using `WebpushFcmOptions` https://github.com/firebase/firebase-admin-python/issues/202 – rexx Oct 15 '18 at 09:44