Skip to content

Instantly share code, notes, and snippets.

@RayyanNafees
Last active June 24, 2021 15:18
Show Gist options
  • Save RayyanNafees/6300d1df8d15b21c664cbe4a1b04817d to your computer and use it in GitHub Desktop.
Save RayyanNafees/6300d1df8d15b21c664cbe4a1b04817d to your computer and use it in GitHub Desktop.
# setup firebase_admin first
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from firebase_admin.messaging import send_multicast,MulticastMessage, Notification
@api_view(['POST'])
def notify(request, format=None):
firebase_storage()
tokens = request.data.get('tokens', ['token'])
title = request.data.get('title', 'title')
body = request.data.get('body', 'msg body')
image = request.data.get('imageUrl', '')
notif = Notification(title, body, image)
MCmsg = firebase_admin.messaging.MulticastMessage(tokens=tokens, notification=notif)
BatchResp = firebase_admin.messaging.send_multicast(MCmsg)
print(str(BatchResp))
return Response(
{'status': 'Success', 'details': 'notification sent!'}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment