Halil Yıldırım
Halil Yıldırım

Reputation: 127

Firebase push notification adding action buttons

I am sending push notifications on server side and I am using this http protocol(https://firebase.google.com/docs/cloud-messaging/http-server-ref) and I want to add action buttons like this in issue https://github.com/FirebaseExtended/flutterfire/issues/1484. This is my request body

{
  "registration_ids": [
    "secret"
  ],
  "notification": {
    "title": "New Article",
    "body": "Article content",
    "sound": "default",
    "actions": [
      {
        "action": "like-button",
        "title": "Like",
        "url": "https://example.com"
      },
      {
        "action": "read-more-button",
        "title": "Read more",
        "url": "https://example.com"
      }
    ],
    "click_action": "read-more-button"
  },
  "data": {
    "id": "some uuid",
  }
}

I tried this but nothing show up. How can I solve this issue? Thank you in advance.

Upvotes: 6

Views: 11309

Answers (1)

James He
James He

Reputation: 592

FCM doesn't support this functionality right now. The solution would be to send a data message via FCM and create your own notification.

  1. Send data message with your own key-value pairs:
  "data": {
    "key": "value",
    "key2": "value2"
  }
  1. Receive messages, use a service that extends FirebaseMessagingService.
  2. Override the onMessageReceived callback to create notification based on your data message.

https://firebase.google.com/docs/cloud-messaging/android/receive

Upvotes: 5

Related Questions