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 46 forks source link

Successfully with response but client doesn't get notifications #34

Closed naumanahmad17 closed 6 years ago

naumanahmad17 commented 6 years ago

Successfully sent message: { results: [ { messageId: '0:1511508709940437%6f2857526f285752' } ], canonicalRegistrationTokenCount: 0, failureCount: 0, successCount: 1, multicastId: 5428886452395349000 }

i put own server details.when i try to send notification using firebase console it successfully send notification but i am unable to send notification using fcm-node.

juicycool92 commented 6 years ago

same here, any solutions folks? it work at console notification, but not node :(

naumanahmad17 commented 6 years ago

can you please share the payload ?

juicycool92 commented 6 years ago

app.js

...
var admin = require("firebase-admin");

var serviceAccount = require('./config/serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.applicationDefault(),
  databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'

});
var registrationToken = 'dMVUN5CVhH8:APA91bHNFX69huyYeyFa0gsptEHezZwTIrtiGpStyoS3CCue_CBxNPIpBA_MXPJfhQhiZI-I_i901Z7FAZHwBr67KZGDftoW-hQRG22joDLTV5mxDI9znMRE2aBujYl93_EjxW-L8boS';

var payload = {
          data: {
              title: "hello",
              body: "world"
          } 
        }; 
        admin.messaging().sendToDevice(registrationToken, payload)
          .then(function(response) {
            console.log('Successfully sent message:', response);
          })
          .catch(function(error) {
            console.log('Error sending message:', error);
          });
...

console :

Successfully sent message: { results: [ { messageId: '0:1512568973984718%e05724c6f9fd7ecd' } ],
  canonicalRegistrationTokenCount: 0,
  failureCount: 0,
  successCount: 1,
  multicastId: 6341110490948248000 }

im preety sure im following official firebases guide, but its not working at all(sigh)

naumanahmad17 commented 6 years ago

var payload = { notification: { title: 'Title of test push notification', body: 'Body of test push notification', click_action:"FCM_PLUGIN_ACTIVITY" }, data: { orderId:"123", pickLocation:"g10", dropLocation:"f10 ", orderType:"Posted" } };

you are doing it the wrong way you are sending data message you need to send notification object along the data message.

the following link will help you understand the difference between Notification message and data messages.

https://firebase.google.com/docs/cloud-messaging/concept-options

just add the notification object and it will do the magic :)

jlcvp commented 6 years ago

AS @naumanahmad17 pointed out, the automatic notification generation is through the notification object in the payload.

Use the data object only when you need to push more "data" into your background service.

juicycool92 commented 6 years ago

thankyou folks! i understand now, and make code works :>

Sohailze commented 1 year ago

device_token eT9LUtfEQRe1htdCSEVZIy:APA91bED2CktD_qPhQOJTEhDNv2Jd_soLsVnfBbtAzTj6m6Gl45JAHtOfTGUrUL0wkK5IUJoWKpygiffMLFVXkUZPeFcWqRR4OKHOPdSWFOCwmosnXH853l9Ddt2EWmtmrxGMuZd1hVi 0|index | Notification { 0|index | results: [ { error: [FirebaseMessagingError] } ], 0|index | canonicalRegistrationTokenCount: 0, 0|index | failureCount: 1, 0|index | successCount: 0, 0|index | multicastId: 8352222041017097000 0|index | }

when this error we get kinldy help me?

juicycool92 commented 1 year ago

@Sohailze I suggest to use firebase-admin-node instead. as mentioned "kind of deprecated" on very top of readme file, firebase-admin-node can now send push easily.