appfeel / node-pushnotifications

Push notifications for GCM, APNS, MPNS, AMZ (automatic detection from device token)
MIT License
534 stars 126 forks source link

GCM giving error with new push notification #20

Closed zelin closed 7 years ago

zelin commented 7 years ago

I am getting this error whenever GCM is being used to send new push notification using new library updated yeseterday

{ method: 'gcm',
11|city    |   multicastId: [],
11|city    |   success: 0,
11|city    |   failure: 1,
11|city    |   message: 
11|city    |    [ { regId: 'APA91bG0Zvg_f8T6bv8XPIFFVRFN9_5IWUjYcPTw6aQcvzGRCXSwFWxAtLHLz42H08nGJeavSxASHeKTYPFXpvidZMw7T7Mp_EfYWKMeH3bHTtFzdjIiwfKdZ9TpQaowOjN6WC9_SVTY',
11|city    |        error: 
11|city    |         Error: Key 'tokens' is not a valid recipient key.
11|city    |             at extractRecipient (/var/www/html/test/node_modules/node-gcm/lib/sender.js:240:35)
11|city    |             at getRequestBody (/var/www/html/test/node_modules/node-gcm/lib/sender.js:189:16)
11|city    |             at Sender.sendNoRetry (/var/www/html/test/node_modules/node-gcm/lib/sender.js:132:5)
11|city    |             at Sender.send (/var/www/html/test/node_modules/node-gcm/lib/sender.js:26:21)
11|city    |             at Timeout._onTimeout (/var/www/html/test/node_modules/node-gcm/lib/sender.js:90:14)
11|city    |             at tryOnTimeout (timers.js:232:11)
11|city    |             at Timer.listOnTimeout (timers.js:202:5) } ] }

The token and the key is valid

miqmago commented 7 years ago

Please, could you verify if it works now?

zelin commented 7 years ago

Yes GCM is now working fine, however the apn is giving error. I have seen ur test file and i am sending this

const data = {
                        title: title,
                        body : message,
                        alert: message
                    };

However its crashing at

TypeError: Cannot set property 'aps' of undefined
11|city    |     at Object.Notification.toJSON (/var/www/html/test/node_modules/apn/lib/notification/index.js:105:19)
11|city    |     at Object.stringify (native)
miqmago commented 7 years ago

Please, could you try with this data?

                  const data = {
                        title: title,
                        body : message,
                        alert: message,
                        custom: {},
                  };

If this works will fix, otherwise will need some work to find the bug.

miqmago commented 7 years ago

Also, with this data object, message will be used as alert and title will be ignored in ios. You have two options:

const data = {
    title: title,
    body : message,
    custom: {},
};

or

const data = {
    title: title,
    body : message,
    alert: {
        title: title,
        body : message,
    },
    custom: {},
};
zelin commented 7 years ago

With both data types i am getting this, Error: MissingTopic 11|city | at /var/www/html/test/node_modules/node-pushnotifications/lib/sendAPN.js:62:28

miqmago commented 7 years ago

I'm not sure if this will fix the problem, please, could you try it now? The problem I think it was related to default parameters.

Right now it should work with this data object:

const data = {
    title: title,
    body : message,
};

If this does not work, it means that topic is mandatory. I will update the docs then (you should include topic field in data).