0

So I am developing an app with many users, I want to be able to send cloud messages on a user using their UID as a destination. Its kind of like sending an SMS message to a specific phone number.

The cloud message should be send on button click, and sent to the user with the particular UID.

My application is an Mobile SOS.

I have 2 application an admin application(Responders) and client app(Users who request for SOS)

what I want to do is, when a user sends an SOS, all the admin accounts will recieve a notification even if the application is on background or closed. then when the admins(rescuers) responds to this on button click, the specific user that sent this will recieve a notification that help is on the way, and only that user will see the notification.

is this all possible?

My data structure for the emergency list(SOS Requests from the users)

    Firebase-root
 |
 --- Emergencies (collection)
       |
       --- -NGdm9B7kdtbQlZ-_YHh (I used push keys)(document)
       |    |
       |    --- //emergency properties
       |    --- UID (The UID is within this document (It is the user that sent the SOS)
       |
       --- NGdm9B7kdtbQlZ-_YHh (I used push keys)(document)
            |
            --- //emergency properties
            --- UID (The UID is within this document (It is the user that sent the SOS)

For the users list, theres another collection for that like this:

    Firebase-root
 |
 --- users (collection)
       |
       --- 4bNpqxVy7.... (UID)(document)
       |    |
       |    --- //user properties
       |    
       |
       --- J2xMEbKO....(UID)(document)
            |
            --- //user properties
Timow
  • 17
  • 5
  • 1
    You can use [FCM Token](https://stackoverflow.com/questions/37671380/what-is-fcm-token-in-firebase) for this. – Lalit Fauzdar Nov 13 '22 at 13:50
  • can I send it to a particular UID using the application and only that user can see it? – Timow Nov 13 '22 at 14:02
  • 1
    Use Firestore. Create a document that contains the user's FCM token when they raise the alarm. Use a Cloud Function that triggers on this document creation and that sends the FCM notification to all admins. The admin that responds can then use the FCM token in the document that has been created to send a message to the correct user. – codebod Nov 13 '22 at 14:14
  • I have explained in one of my tutorials step by step, how you can send [notifications](https://www.youtube.com/watch?v=6RzB4HXzQyA&t=3s&list=PLn2n4GESV0AmXOWOam729bC47v0d0Ohee&index=17) to specific users using Node.js. You can also take a look at my answer from this [post](https://stackoverflow.com/questions/48298993/push-notifications-on-content-change/48299840). – Alex Mamo Nov 13 '22 at 16:05
  • Thank you I will check on that @AlexMamo – Timow Nov 14 '22 at 05:58
  • I''ll take a look on that too @codebod – Timow Nov 14 '22 at 05:58
  • @AlexMamo [post](https://stackoverflow.com/questions/48298993/push-notifications-on-content-change/48299840) can I used this code on firebase realtime database? since that is the one I used on my app – Timow Nov 14 '22 at 07:09
  • That was an example of you can send notifications. The solution is for Firestore, but you can achieve the same thing for the Realtime Database. – Alex Mamo Nov 14 '22 at 07:15
  • @AlexMamo can I still do it even if my data structure is like this: (I have updated my post) – Timow Nov 14 '22 at 07:27
  • @codebod I already developed my app using realtime database, can I still use FCM with realtime database? – Timow Nov 14 '22 at 07:35
  • There are no collections in the Realtime Database, but you can create a similar schema there too. – Alex Mamo Nov 14 '22 at 07:46
  • @AlexMamo oh sorry, however, that is how my data structure looks like. Will I still be able to store notifications on that? and does the notifications get updated when the user requests for another SOS? – Timow Nov 14 '22 at 07:53
  • If you follow what exists in those resources you'll be able to send notifications. – Alex Mamo Nov 14 '22 at 08:21

0 Answers0