-1

i am developping an android application based on a wordpress blog where users can post their own articles, i work with WP REST API to get posts , comments and users ...

I would like to send a notification automatically to the user when his article got a new comment , i have installed FCM correctly and tested the simple forme of notifications but i need to :

  • Trigger FCM Notification on new comment sent ( Or just on a button click )
  • Specify receiver so the notification is sent to logged in user with the right email/username

I thought of

  • working with setting User Property for every user logged like this :

mFirebaseAnalytics.setUserProperty("user_name_for_notification", "the_username");

  • Sending notification for all devices then handle it in onMessageReceived

but i don't think those are good ideas

So , any ideas where to start

thank you

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
AYMEN SOUMER
  • 175
  • 2
  • 8
  • did you tried with `add_action('comment_post','php_function_to_notify')` ? – Ali Qorbani Dec 07 '19 at 12:30
  • how can i send notification to the specific user from php_function_to_notify – AYMEN SOUMER Dec 07 '19 at 14:50
  • I mean you can add actions to the comment post in wordpress. Its directly runs when a user submit a comment. I don't know how firebase works but for example you can localize an script and use it for send notify. If you don't know how. Plz read about it – Ali Qorbani Dec 07 '19 at 15:55

1 Answers1

1

FCM can send notifications with three different targeting methods:

  1. to a specific FCM token/instance ID token, which identifies an installation of a specific application on a specific device.
  2. to a group of such device/instance IDs.
  3. to a specific topic, which FCM clients can subscribe to.

Firebase Cloud Messaging does not have the concept of a user, therefor it cannot target users directly. If you want to target users, you will have to map them to one of the targeting methods outline above.

The most common ways that I know of:

  1. Store the token(s) for a user in a database under their UID, and then send to the user's token(s) when you need to target the user.
  2. Give each user their own topic, based on their UID. Have the app subscribe to that topic, and send message to the user's topic when you need to target them.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807