Search code examples
pythondjangofirebase-cloud-messaging

How to add a link in fcm-django notification?


I am working on a project where I am using fcm-django for sending push notifications to a devices. I want to include a link in the notification that opens a specific page in the web app when clicked. How can I add a link to the notification using fcm-django?

Here is my code

from firebase_admin.messaging import Message
from firebase_admin.messaging import Notification
from fcm_django.models import FCMDevice

fcm_devices_of_this_user = FCMDevice.objects.filter(user=user_obj, active=True)
if fcm_devices_of_this_user:
   fcm_devices_of_this_user.send_message(
      MESSAGE(
        notification=NOTIFICATION(title=notification_for, body=message)
      )
   )

Any help would be appreciated.


Solution

  • Here is the answer of above question...

    from firebase_admin.messaging import Message
    from firebase_admin.messaging import Notification, WebpushConfig, WebpushFCMOptions
    from fcm_django.models import FCMDevice
    
    fcm_devices_of_this_user = FCMDevice.objects.filter(user=user_obj, active=True)
    if fcm_devices_of_this_user:
       fcm_devices_of_this_user.send_message(
          MESSAGE(
            notification=NOTIFICATION(title=notification_for, body=message),
            webpush=WebpushConfig(fcm_options=WebpushFCMOptions(link="https://facebook.com"))
          )
       )