Right message structure
This commit is contained in:
parent
9649610e91
commit
325f0d8664
@ -1,48 +1,38 @@
|
||||
module.exports = {
|
||||
createPayload: function createPayload(req) {
|
||||
// Payload according to
|
||||
// https://firebase.google.com/docs/reference/admin/node/TokenMessage
|
||||
var payload = {
|
||||
android: {
|
||||
collapseKey: "haclient"
|
||||
collapseKey: "haclient",
|
||||
notification: {
|
||||
icon: "mini_icon",
|
||||
clickAction: "FLUTTER_NOTIFICATION_CLICK",
|
||||
channelId: "ha_notify"
|
||||
}
|
||||
},
|
||||
notification: {},
|
||||
data: {
|
||||
click_action: "FLUTTER_NOTIFICATION_CLICK"
|
||||
},
|
||||
data: {},
|
||||
};
|
||||
var updateRateLimits = true;
|
||||
|
||||
if (req.body.data) {
|
||||
// Allow setting of ttl
|
||||
// https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidConfig.html#optional-ttl
|
||||
if (req.body.data.ttl) {
|
||||
payload.android.ttl = req.body.data.ttl;
|
||||
}
|
||||
|
||||
// https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidConfig.html#optional-priority
|
||||
if (req.body.data.priority) {
|
||||
payload.android.priority = req.body.data.priority;
|
||||
}
|
||||
|
||||
if (req.body.data.image) {
|
||||
payload.notification.image = req.body.data.image;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.body.message) {
|
||||
payload.data.message = req.body.message;
|
||||
if (req.body.message in ['request_location_update', 'clear_notification']) {
|
||||
updateRateLimits = false
|
||||
} else {
|
||||
payload.notification.body = req.body.message;
|
||||
}
|
||||
payload.notification.body = req.body.message;
|
||||
}
|
||||
|
||||
if (req.body.title) {
|
||||
payload.data.title = req.body.title
|
||||
if (req.body.message in ['request_location_update', 'clear_notification']) {
|
||||
updateRateLimits = false
|
||||
} else {
|
||||
payload.notification.title = req.body.title;
|
||||
payload.notification.title = req.body.title;
|
||||
}
|
||||
|
||||
// https://firebase.google.com/docs/reference/admin/node/admin.messaging.AndroidNotification
|
||||
if (req.body.data) {
|
||||
if (req.body.data.image) {
|
||||
payload.notification.imageUrl = req.body.data.image;
|
||||
}
|
||||
for (const key of ['tag', 'color', 'channelId']) {
|
||||
if (req.body.data[key]) {
|
||||
payload.android.notification[key] = String(req.body.data[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user