Last active
June 24, 2021 15:18
-
-
Save RayyanNafees/6300d1df8d15b21c664cbe4a1b04817d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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