Search code examples
firebasefirebase-cloud-messagingweb-notifications

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.


Solution

  • 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>}
    )