Payload not properly sent to node-apn
toriqo opened this issue · 2 comments
The payload
and rawPayload
properties on the notification are not properly formatted as node-apn requires it here
I only need to send this object as a PushKit (VoIP) notification but I can't construct my object properly.
{
"aps": {"alert":"some message"},
"data":{
"Key": {
"AnotherKey": "value",
"Key": "value",
"SomeKey": "value"
}
}
}
The payload attribute seems to be ignored as it's not forwarding data
in the notification.
Usage example:
{
title: 'some title', // REQUIRED for Android
topic: '(bundle).voip', // REQUIRED for iOS (apn and gcm)
data: {}, // payload for android
/* The topic of the notification. When using token-based authentication, specify the bundle ID of the app.
* When using certificate-based authentication, the topic is usually your app's bundle ID.
* More details can be found under
* https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
*/
body: 'some body',
priority: 'high', // gcm, apn. Supported values are 'high' or 'normal' (gcm). Will be translated to 10 and 5 for apn. Defaults to 'high'
// collapseKey: '', // gcm for android, used as collapseId in apn
contentAvailable: false, // gcm, apn. node-apn will translate true to 1 as required by apn.
// delayWhileIdle: true, // gcm for android
// restrictedPackageName: '', // gcm for android
dryRun: false, // gcm for android
icon: '', // gcm for android
// image: '', // gcm for android
// style: '', // gcm for android
// picture: '', // gcm for android
// tag: '', // gcm for android
// color: '', // gcm for android
// clickAction: '', // gcm for android. In ios, category will be used if not supplied
retries: 1, // gcm, apn
// badge: 2, // gcm for ios, apn
sound: 'sound.m4r', // gcm, apn
// android_channel_id: '', // gcm - Android Channel ID
alert: 'new pushkit',
payload: {
data: {
Key: {
AnotherKey: 'value',
Key: 'value',
SomeKey: 'value'
}
}
},
silent: false, // apn, will override badge, sound, alert and priority if set to true
/*
* A string is also accepted as a payload for alert
* Your notification won't appear on ios if alert is empty object
* If alert is an empty string the regular 'title' and 'body' will show in Notification
*/
pushType: 'voip', // apn. valid values are 'alert' and 'background'
expiry: Math.floor(Date.now() / 1000) + 28 * 86400, // unit is seconds. if both expiry and timeToLive are given, expiry will take precedence
}
@toriqo In order to set the payload
property for APN you need to pass your data
object into the custom
property, e.g.
{
title: 'some title',
pushType: 'voip',
alert: 'new pushkit',
custom: {
data: {
Key: {
AnotherKey: 'value',
Key: 'value',
SomeKey: 'value'
}
}
}
}
This is documented in https://github.com/appfeel/node-pushnotifications#apn:
{
...
payload: data.custom || {}
...
}
Thanks. It works.
FYI: I saw the data.custom in the docs but the info is a bit blurry there, as the APN object still has the payload
key in it making me think I have to send it. No mention anywhere about the custom
property.