I am using the node firebase admin to send messages to Android devices. All works. Except when I try to send messages to multiple topics. In the example code below I simply subscribe to 2 topics and directly afterwards i send a notifications to multiple topics in a condition. Nothing arrives on my Phone. When you just send to one topic, the notification arrives successfully. I don't get why it is not working. There is no error response from the firebase admin. just: 'projects/admob-app-id-xxxx/messages/xxxx'
var admin = require("firebase-admin");
var serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://admob-app-id-xxxxx.firebaseio.com"
});
var registrationTokens = ["xxxxx"];
var topica = "AAA";
var topicb = "BBB";
var data = {};
var message = {
condition : "'"+topica+"' in topics || '"+topicb+"' in topics",
data: {'message':JSON.stringify(data)},
android: {
ttl: 36000 * 1000,
priority: 'normal',
collapseKey: "test"
}
};
admin.messaging().subscribeToTopic(registrationTokens, topica)
.then(function(response) {
admin.messaging().subscribeToTopic(registrationTokens, topicb)
.then(function(response) {
admin.messaging().send(message, dryRun)
.then((response) => {
console.log('success', response);
}).catch((error) => {
console.log('error', error);
});
})
.catch(function(error) {
console.log('Error subscribing to topic:', error);
});
})
.catch(function(error) {
console.log('Error subscribing to topic:', error);
});