Programmer12
Programmer12

Reputation: 119

Messaging not working in Python firebase-admin

I am trying to send notifications to topics in firebase using python. However, I am having a problem.

This is the error message: message = messaging.Message( NameError: name 'messaging' is not defined

This is the code:

import firebase_admin
from firebase_admin import credentials


cred = credentials.Certificate("path")
firebase_admin.initialize_app(cred)

topic = 'TestTopic'
def sendPush(title, msg):
    message = messaging.Message(
        data = {
            'title': 'TestTitle',
            'body': 'sometest',
        },
        topic=topic
    )

    response = messaging.send(message)


sendPush('hello', 'test')

Any help is greatly appreciated. Thank you

Upvotes: 1

Views: 889

Answers (1)

user11527247
user11527247

Reputation: 238

I think, you forgot to define this:

from firebase_admin import messaging

Upvotes: 2

Related Questions