-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfirebase_notification.py
More file actions
28 lines (23 loc) · 855 Bytes
/
firebase_notification.py
File metadata and controls
28 lines (23 loc) · 855 Bytes
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
import firebase_admin
from firebase_admin import credentials, messaging
# Inicializa la app de Firebase con el archivo JSON de tu cuenta de servicio
cred = credentials.Certificate("ruta/al/archivo/serviceAccountKey.json")
firebase_admin.initialize_app(cred)
def enviar_notificacion(token, titulo, cuerpo):
# Construye el mensaje
message = messaging.Message(
notification=messaging.Notification(
title=titulo,
body=cuerpo,
),
token=token,
)
# Envía el mensaje
response = messaging.send(message)
print('Mensaje enviado:', response)
# Reemplaza estos valores con los datos de tu cliente
token = 'DEVICE_REGISTRATION_TOKEN'
titulo = 'Título de la Notificación'
cuerpo = 'Este es el cuerpo de la notificación'
# Envía la notificación
enviar_notificacion(token, titulo, cuerpo)