1

I'm building an app using Firebase Notifications where a user can enter their zip code and then receive notifications for specific events happening in their locality.

How do I only send notifications to a specific user? I've tried including Zip Code in the Advanced Options sections of Firebase Notifications, but it still sends the notification to all users.

AL.
  • 33,241
  • 9
  • 119
  • 257
Gibraltar
  • 1,046
  • 8
  • 20

3 Answers3

2

Seems like Topics is what you are looking for. When the user enters their zipcode you can subscribe them to a topic eg: /topics/zip then you can send to the appropriate zipcode from the console. Subscribing will create the topic if it does not already exist.

Note: Topics can take up to 24 hours to show up in the console after they are created.

Arthur Thompson
  • 8,335
  • 3
  • 26
  • 31
0

It seems you are trying to Send Notifications to a User Segment in the Firebase Console. However, it seems that the specific detail you're targeting is not an option that is available in the console.

As of right now, the only available User Segments you can send to are (these can be modified in the Target Section when Sending a Notification):

  • (User) Audience
    • All Users
    • Purchasers
  • (Device) Language
    • English (I think it may vary depending on the language you're using)
  • (App) Version
    • Contains
    • Does not contain
    • Exact Match
    • Regular Expression

With the above being clear, I think the only way for you to send to those specific users in a specific Zip Code, you should be implementing the push from your server app, wherein you collect the users profiles with the corresponding Zip Code, and then push the messages to their registration tokens.

I think the links mentioned in this answer will help you:

Firebase Cloud Messaging has server-side APIs that you can call to send messages. See https://firebase.google.com/docs/cloud-messaging/server.

Sending a message can be as simple as using curl to call a HTTP end-point. See https://firebase.google.com/docs/cloud-messaging/server#implementing-http-connection-server-protocol

curl -X POST --header "Authorization: key=<API_ACCESS_KEY>" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"<YOUR_DEVICE_ID_TOKEN>\",\"notification\":{\"body\":\"Yellow\"} \"priority":\"10"}"
Community
  • 1
  • 1
AL.
  • 33,241
  • 9
  • 119
  • 257
0

There will be below ways to do it,

  1. Topic messaging - subscribe to a topic with a specific audience, and send notifications with that topic name.

  2. Firebase Tokens - You can write the logic on the server to send the notifications to specific firebase token IDs.

abhi.nalavade
  • 176
  • 1
  • 9