Merge branch 'app'
[wolnelektury.git] / src / push / utils.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 import firebase_admin
6 from firebase_admin import credentials, messaging
7 from django.conf import settings
8
9 cred = credentials.Certificate(settings.FCM_PRIVATE_KEY_PATH)
10 firebase_admin.initialize_app(cred)
11
12 TOPIC = 'wolnelektury'
13
14
15 def send_fcm_push(title, body, image_url=None):
16     # See documentation on defining a message payload.
17     data = {}
18     # data = {
19     #     'title': title,
20     #     'body': body,
21     # }
22     if image_url:
23         data['imageUrl'] = image_url
24     message = messaging.Message(
25         notification=messaging.Notification(
26             title=title,
27             body=body,
28         ),
29         data=data,
30         topic=TOPIC,
31     )
32     message_id = messaging.send(message)
33     return message_id