3

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);
        });
Gillis Haasnoot
  • 2,229
  • 1
  • 19
  • 23

1 Answers1

6

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.

Lee Jensen
  • 2,151
  • 2
  • 21
  • 23
  • Do you have a bug reference? Do you know if this is being worked on? – l1b3rty Dec 19 '19 at 11:43
  • I don't remember the original ticket that I referenced, but I don't believe Google has resolved this issue. I found several tickets. All of them closed or open without resolution. https://github.com/firebase/quickstart-js/issues/183 https://github.com/firebase/firebase-admin-node/issues/277 https://github.com/firebase/firebase-admin-java/issues/104 – Lee Jensen Dec 20 '19 at 16:03
  • I just got a cryptic answer from Firebase support that I can summarize by " this should work but may fail due to having too many users registered". This is obviously wrong as I am just testing with very few users. Waiting for the answer – l1b3rty Dec 21 '19 at 20:36