I'm trying to send multiple notifications from one cloud function. There are two use cases:
1. In a group chat, I've to create two separate payloads for android and iOS devices and then send notifications through the same cloud function for both the payloads.
2. There is a specific case, wherein, on an event on a collection, I need to send multiple messages to the same recipient.
var promises = new Array();
if (androidMemberToken.length > 0) {
var androidPromise = admin.messaging().sendToDevice(androidMemberToken, payload, options)
.then(function(response) {
console.log("Message sent: ", response);
})
.catch(function(error) {
console.log("Error sending message: ", error, payload);
});
promises.push(androidPromise);
}
if (iosMemberToken.length > 0) {
payload['notification'] = info;
var iosPromise = admin.messaging().sendToDevice(iosMemberToken, payload, options)
.then(function(response) {
console.log("Message sent: ", response);
})
.catch(function(error) {
console.log("Error sending message: ", error, payload);
});
promises.push(iosPromise);
}
return Promise.all(promises);
This is for group chat. I'm not getting any error message, however the notifications are not sent. Cloud Function logs do not show any success/error messages. What should be the correct approach for the above two cases for sending multiple notifications?