Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase messaging conditions with multiple topics not working

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);
        });
like image 719
Gillis Haasnoot Avatar asked Nov 15 '25 11:11

Gillis Haasnoot


1 Answers

This is a bug with FCM. You can work around it by breaking up your message post into multiple messages.

Instead sending one message.

't1' in topics || 't2' in topics || 't3' in topics

Send the equivilant three messages.

't1' in topics && !('t2' in topics) && !('t3' in topics)
't2' in topics && !('t3' in topics)
't3' in topics

Note that the 5 topic limit is still in force.

like image 89
Lee Jensen Avatar answered Nov 18 '25 01:11

Lee Jensen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!