appfeel / node-pushnotifications

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

error when using a long expiry (from firebase cloud messaging) #161

Closed ldikmans closed 2 years ago

ldikmans commented 2 years ago

We have a use case where we send users a push notification if they can execute a new step. Usually these steps will be available for a couple of days. But especially in holiday season, steps might be available for 6 weeks or even longer.

APNS allows us to set a date, without limiting the duration. However, firebase cloud messaging rejects the message with "node-gcm Invalid request (400): Invalid value (3621207) for "time_to_live": must be between 0 and 2419200"

I guess for sendGCM.js the code could be changed like from this:

const ttlFromExpiry = (expiry) => expiry - Math.floor(Date.now() / 1000);

to this: const ttlFromExpiry = (expiry) => expiry-Math.floor(Date.now()/1000) > 2419200 ? 2419200 : expiry - Math.floor(Date.now() / 1000);

alex-friedl commented 2 years ago

Thanks for reporting this @ldikmans

Bugfix released in v1.7.1