1

I am trying to send FCN messages to a closed user group using the HTTP v1 protocol.

Note: By my definition a "closed user group" is a group that users can not enter themself. Only an admin or a server-side program with certain credentials can add a user to the group.

My first tests using a topic were successful:

POST https://fcm.googleapis.com/v1/projects/<my_project_id>/messages:send
Authorization: Bearer <oauth token from GoogleCredential.getAccessToken()>
Content-Type: application/json; UTF-8
{
    "message": {
        "notification": {
            "title": "Sample title",
            "body": "Sample body 15:33:31"
        },
        "android": {
            "ttl": "172800s"
        },
        "topic": "MyTopic"
    }
}

My problem is that topics aren't closed. Any user can subscribe on any topic and I can't limit it (one can only hide the option but on code-level you can still subscribe to every topic).

The only possible approach I see is to create an Audience and specify explicitly users by their user-id to belong to the audience. I did this and I have now an Audience but there seems to be no way to specify an audience as message receiver. I tried to use the condition field of the message object (instead of the topic field), however it seems that one can only specify topics in it.

Is there a way to send a message to an Audience group? Or is there an alternative way to achieve sending a message to a closed user group?

JMax
  • 1,134
  • 1
  • 11
  • 20
  • Have you looked into [Device Groups](https://firebase.google.com/docs/cloud-messaging/android/device-group)? See [Managing Device Groups here](https://stackoverflow.com/q/42515390/4625829) – AL. Dec 19 '17 at 03:30
  • After posing here I also found the API documentation about device groups. Besides the fact that it is not supported by any SDK it uses the legacy HTTP protocol and there seems to be noting equivalent in the current API. Furthermore when I send a message to a device group via HTTP v1 protocol the notifications do not show up. The same message sent to a single device works without problems. – JMax Dec 19 '17 at 09:03
  • Device groups sounded like several devices of the same user to me (besides that it seems to be deprecated) – Günter Zöchbauer Jan 16 '18 at 10:44
  • I guess you need to make the client store the FCM token in the database. You can limit using security rules which user is allowed to register for what topic. Then a cloud function (or some other client that is allowed to read the registered FCM tokens from the database) sends the message to all registered FCM tokens. I haven't found a better way yet. – Günter Zöchbauer Jan 16 '18 at 10:47

0 Answers0