Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Send Message to Multiple Topics

I've been trying to send cloud messages to users who subscribed to multiple topics through an API call (POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send) with the following body:

{
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer MY_ACCESS_TOKEN`
  },
  body: {
    "message": {
      "condition": "'cat' in topics || 'dog' in topics",
      "notification": {
        "title": "Message Title",
        "body": "Message Body" 
      }
    }
  }
}

I wrote this config according to the FCM documentation. I can get a response similar to this:

{
  "name": "projects/myproject-b5ae1/messages/5735743068807585451"
}

but no messages were received by any devices.

I've used the access token for other APIs, which works. I'm also aware that the FCM documentation also provided a different body for the cURL request, which I also tried but not working.

The weird thing is if I only provide one topic in the condition, a message is actually successfully sent to subscribed devices. Am I writing something wrong?

I've already referenced other solutions on Stackoverflow but everything is still not working:

Firebase API call with multiple topics in condition

How to send FCM Push Notifications to multiple topics

like image 580
kevguy Avatar asked Jan 15 '18 03:01

kevguy


1 Answers

After talking to Firebase Support, they pointed out the problem I'm having here is a known bug they are still trying to fix. And there's no specific timeline for a fix yet.

Therefore, there's no problem with my code and I'll have to figure out a workaround myself if I really want to use the "||"(OR) operator.

My current workaround is keep track of subscribers with a database (since Firebase doesn't offer subscribers querying), then implement the OR condition myself by finding a union of subscribers to different topics.

enter image description here

P.S. I just don't get why the downvotes, I actually found a bug here and referenced all the solutions I could found on SO before asking the question here.

like image 164
kevguy Avatar answered Sep 26 '22 21:09

kevguy