jlcvp / fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM) for Android & iOS & Web Notification and data push
MIT License
125 stars 48 forks source link

Successfully with response but client doesn't get notification #12

Closed HyeonjuPark closed 7 years ago

HyeonjuPark commented 7 years ago

Successfully sent with response: {"multicast_id":5979505685602066267,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1479724040861830%0000000000000000"}]} I put my own server key and message token and client app is implemented with FirebaseMessagingService and FirebaseInstanceIDService. When I run the server, it returns success response like above message. However, client app doesn't get any notification. what am I missed?

antoinerousseau commented 7 years ago

Try to use the Firebase Notifications console

https://console.firebase.google.com/project/<your-project>/notification

To send one manually to be sure that the issue is not on the device

jlcvp commented 7 years ago

If you're using iOS, please take a look at #7 and #8. If you're at Android, make sure you've properly generated the google-services.json. Additionally, can you inform your send object format?

HyeonjuPark commented 7 years ago

Notification sent from Firebase Notification console works well.

`var fcm_message = {
    to: 'MESSAGE_TOKEN',
    collapse_key: 'test message',

    notification: {
        title: 'Title of test push notification',
        body: 'Body of test push notification'
    },

    data: {
        key: 'test value',
        another_key: 'test another key'
    }
};

I'm using Android and this is the object that is almost not changed from the sample you gave. Is it okay to use "Firebase Cloud Messaging token" in "to" property?

jlcvp commented 7 years ago

@HyeonjuPark The MESSAGE_TOKEN must be the user device token, or a topic the device is already subscribed with a format like "/topics/YOURTOPIC".

To get this device token look at this firebase documentation page

EDIT: Typo, 'topic' -> 'topics'

HyeonjuPark commented 7 years ago

Thanks a lot! Getting the user device token following the link, I got the notification. However, when I used topic like this

to: '/topic/test', //server
FirebaseMessaging.getInstance().subscribeToTopic("test"); //client

it didn't work. Seems something I'm wrong again. Is there a way to broadcast all users?

jlcvp commented 7 years ago

@HyeonjuPark sorry for the typo, the correct is plural -> /topics/YOURTOPIC

To broadcast a message to all users you can use the firebase console, or subscribe all your clients in a central topic defined by you.

HyeonjuPark commented 7 years ago

I'm sorry to reply late. It works!! thanks I really appreciate for your kind response.

jlcvp commented 7 years ago

Glad it worked. Feel free to report any other issue.

Priyadarshanipp commented 6 years ago

@jlcvp My registration token is correct and notifications are sent by the server but didn't received by client app. What is the problem? I tried refreshing the token as well.

jlcvp commented 6 years ago

@Priyadarshanipp Can you give more information?

  1. how is your message structured?
  2. Are you using the device registration in theFirebaseInstanceId.getInstance().getToken() method?
  3. If you're sending a topic, make sure device is subscribed to it
prabu-theappsolutes commented 6 years ago

module NotificationHelper require 'fcm' def send_notification(location, message,user_id ) firebase_key = Rails.application.secrets.firebase_key

user = User.find_by(id: user_id)
fcm = FCM.new(firebase_key)
registration_ids= [user.device_token] # an array of one or more client registration tokens
options = {:data => {message: message}, location: location}
response = fcm.send(registration_ids, options)

end end

honeyTops commented 4 years ago

Hi I am facing the same issue. I am also not able to get the notification on device This is my message object : let message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera) to:"Users device token", collapse_key: "your_collapse_key",

notification: {
  title: "Title of your push notification",
  body: "Body of your push notification"
},

data: {
  //you can send only notification or only data(or include both)
  my_key: "my value",
  my_another_key: "my another value"
}

};