andreialecu / node-apn-http2

Communicate with Apple Push Notification Service via native Node.js v8.8.1+ HTTP2 module (node-apn drop-in)
MIT License
26 stars 10 forks source link

Payload is being ignored #8

Open tosbaha opened 5 years ago

tosbaha commented 5 years ago

It seems payload key from my note doesn't get delivered. When I receive the payload with didReceiveRemoteNotification I only see aps key. I don't see the payload. If I send following payload by Pusher app, eveything works as expected.

{"_id":"111","aps":{"badge":1,"alert":{"title":"Some title","body":"Some Body"},"content-available":1}}

Here is my code

        let note = new apn.Notification();
        note.expiry = 0;
        note.badge = 1;
        note.collapseId = job._id;
        note.alert = {
            title: "Some Title",
            body: "Some Body",
        }
        note.contentAvailable = 1;
        note.payload = { '_id': job.id };
        note.topic = "com.my.topic";

        console.log('Note: ' + JSON.stringify(note)); // When I print I also don't see `payload`
        const devices = await Database.getAllDevices(job.owner);
        const tokens = _.map(devices, 'token');
        const result = await apnProvider.send(note, tokens);

EDIT: I found the error if payload has a null value, then payload gets ignored. Since I made a typo in job.id; it sets _id as null, and that value is lost during return Object.assign({}, this.payload, { aps: this.apsPayload() }); So it seems, you can't use null in the payload.