2

I'm trying to use django-push-notifications library in my Django REST backend project. I have used Firebase Cloud Messaging. Here is the implementation;

settings.py

PUSH_NOTIFICATIONS_SETTINGS = {
    "FCM_API_KEY": "private key from FCM app"
}

views.py

user, created = User.objects.get_or_create(email=email, username=username)

if created:
    GCMDevice.objects.create(registration_id="token", cloud_message_type="FCM", user=user)

models.py

@receiver(post_save, sender=Action)
def create_new_action(sender, instance, created, **kwargs):
    if created:
        devices = GCMDevice.objects.filter(Q(user=instance.admin)|Q(user__in=instance.users.all()))
        msg = "New action is created in %s" % instance.name
        devices.send_message(msg)

My question is what should registration_id be while I'm creating the GCMDevice object for each registered user?

Aslı Kök
  • 616
  • 8
  • 19

2 Answers2

0

registration_id come from your frontend

actually you must have an api that get user(frontend) fcm token or get it(fcm token) in user registration or login api's

Hossein Asadi
  • 768
  • 1
  • 6
  • 15
0

The registration_id is the same as the endpoint key from the client-side PushSubscription object. which looks like this:

{
    "endpoint": "https://fcm.googleapis.com/fcm/send/...",
    "expirationTime": null,
    "keys": {
        "p256dh": "...",
        "auth": "..."
    }
}
Joshua S
  • 169
  • 1
  • 10