quickstart-js icon indicating copy to clipboard operation
quickstart-js copied to clipboard

I want to know how to add an image for the web notification?

Open szjSmiling opened this issue 7 years ago • 4 comments

I config like this: notification: { image: '' } but doesn't work

szjSmiling avatar Aug 15 '19 08:08 szjSmiling

@szjSmiling Could you try using webpush -> notification -> image field?

kroikie avatar Aug 15 '19 16:08 kroikie

@szjSmiling note that you need to have the message object when sending a message. Eg:

message: {
  token: 'token of client receiving the message',
  notification: {
    title: 'my notification title',
    body: 'my notification body',
    image: 'url to notification image'
  }
}

kroikie avatar Aug 15 '19 16:08 kroikie

Using the example in https://github.com/firebase/quickstart-js/tree/master/messaging the following 2 ways of specifying an image work

1) Using a full URL

  • As suggested by Arthur above

image

2) Using a relative URL

  • relative to the site where the push is set up image

Curl request used from the Readme in that sample code

curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "Portugal vs. Denmark",
    "body": "5 to 1",
    "icon": "firebase-logo.png",
    "click_action": "http://localhost:8081"
  },
  "to": "YOUR-IID-TOKEN"
}' "https://fcm.googleapis.com/fcm/send"

thewheat avatar Oct 12 '19 03:10 thewheat

Thanks for the detailed info, @thewheat!

jhuleatt avatar Dec 12 '19 23:12 jhuleatt