File size: 1,028 Bytes
35cdf61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import firebase_admin
from firebase_admin import credentials
from firebase_admin import messaging 

cred = credentials.Certificate('./env/firebase/faceanimate-firebase-adminsdk-lnj8m-8fefd36f2f.json')
default_app = firebase_admin.initialize_app(cred)

class FCM:
    def __init__(self):
        pass

    def push_notification(title, body, image, topic='testTopic'):
        notification = messaging.Notification(
            title=title,
            body=body,
            image=image,
        )
        message = messaging.Message(
            notification=notification,
            topic=topic,
        )
        response = messaging.send(message)
        if response:
            return True
        return False

    def push_message_to_user(data, registration_token):
        message = messaging.Message(
            data=data,
            token=registration_token,
        )
        response = messaging.send(message)
        if response:
            return True
        return False

    def __del__(self):
        pass