X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d679452e8cede72656beb1e14b48a1b3e82e79c0..e17ba704033aba068a935c1beb42d1f306e6a114:/src/push/utils.py?ds=inline diff --git a/src/push/utils.py b/src/push/utils.py new file mode 100644 index 000000000..98f035919 --- /dev/null +++ b/src/push/utils.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +import firebase_admin +from firebase_admin import credentials, messaging +from django.conf import settings + +cred = credentials.Certificate(settings.FCM_PRIVATE_KEY_PATH) +firebase_admin.initialize_app(cred) + +TOPIC = 'wolnelektury' + + +def send_fcm_push(title, body, image_url=None): + # See documentation on defining a message payload. + data = {} + if image_url: + data['imageUrl'] = image_url + message = messaging.Message( + notification=messaging.Notification( + title=title, + body=body, + ), + data=data, + topic=TOPIC, + ) + message_id = messaging.send(message) + return message_id