diff --git a/backend/fastapi/app/fcm_notification.py b/backend/fastapi/app/fcm_notification.py index e9f8384..a5a072f 100644 --- a/backend/fastapi/app/fcm_notification.py +++ b/backend/fastapi/app/fcm_notification.py @@ -1,18 +1,34 @@ -from pyfcm import FCMNotification +import firebase_admin +from firebase_admin import credentials +from firebase_admin import messaging + from .config import Config -push_service = FCMNotification(Config.fcm_server_key) +cred_path = Config.cred_path +cred = credentials.Certificate(cred_path) +firebase_admin.initialize_app(cred) + async def send_push_notification(token, title, body, data): - result = push_service.notify_single_device( + '''result = push_service.notify_single_device( registration_id=token, message_title=title, message_body=body, data_message=data + )''' + + message = messaging.Message( + notification=messaging.Notification( + title=title, + body=body + ), + data=data, + token=token ) - print("[INFO] push notification sent") - return result + response = messaging.send(message) + + print('Successfully sent message:', response)