firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
366 stars 131 forks source link

ClickAction not working #306

Closed stesvis closed 3 years ago

stesvis commented 3 years ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

I am trying to send a push notification to iOS and Android using FCM and I need to pass a parameter click_action as described here (scroll down): https://github.com/CrossGeeks/FirebasePushNotificationPlugin/blob/master/docs/NotificationActions.md

I tried to add that parameter wherever possible, but I do not receive it in the notification. This is the payload generated by MulticastMessage:

{
  "Tokens": [
    "eEK8smTvsErmvdAhHK3F9v:APA91bFDUeQMDEcBnUHhaLKaIcv4r_SwviUA9fDQcw7HuJkxAkII6OjXOySKiZrLvzbsQG5EQlz4rbRGKYVmwyZ5CD0_SuHTP8ihvudaksXDl7aHZAjJUUgmlMjE93-S9DAi7F1VdpL_"
  ],
  "Data": {
    "Title": "Check-in Reminder",
    "Message": "Tap here to respond with a check-in.",
    "ScheduledCheckIn": "97",
    "click_action": "scheduled_check_in"
  },
  "Notification": {
    "title": "Check-in Reminder",
    "body": "Tap here to respond with a check-in.",
    "image": null,
    "click_action": "scheduled_check_in",
  },
  "Android": {
    "collapse_key": null,
    "restricted_package_name": null,
    "data": {
      "click_action": "scheduled_check_in"
    },
    "notification": {
      "title": null,
      "body": null,
      "icon": null,
      "color": null,
      "sound": null,
      "tag": null,
      "image": null,
      "click_action": "scheduled_check_in",
      "title_loc_key": null,
      "title_loc_args": null,
      "body_loc_key": null,
      "body_loc_args": null,
      "channel_id": null
    },
    "fcm_options": null,
    "priority": null,
    "ttl": null
  },
  "Webpush": null,
  "Apns": {
    "headers": null,
    "fcm_options": null,
    "payload": {
      "aps": {
        "badge": null,
        "category": "scheduled_check_in",
        "click_action": "scheduled_check_in",
        "thread-id": null,
        "alert": null,
        "sound": "default",
        "content-available": 1,
        "mutable-content": null
      }
    }
  }
}

Steps to reproduce:

Use the code above to send a push notification to android or iOS (change the token).

google-oss-bot commented 3 years ago

I found a few problems with this issue:

hiranya911 commented 3 years ago

Can you share the actual C# code you tried? Above is some JSON, and not executable code.

You're also referencing a third party project (FirebasePushNotificationPlugin), and I can't see the relationship between that and the Admin SDK.

stesvis commented 3 years ago

I finally figured it out. It turns out that I have to send two notifications, one to only android devices, where I only set the data field, and one to only iOS devices, where I only set the notification and apns fields.

This way it works and I can see the action button in the notification try in both platforms.

hiranya911 commented 3 years ago

I still cannot determine how to triage this issue. No actual code or test case has been shared. I'm going to close this as incomplete. Please file a new issue with more details, if there's anything else that needs to be addressed in this repo.