simulacion de estados y flujo de notificacion, modificacion de estilos en todas las vistas
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
import firebase_admin
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from firebase_admin import credentials, messaging
|
||||
|
||||
_firebase_initialized = False
|
||||
@@ -27,9 +29,13 @@ def send_to_topic(topic: str, payload: dict):
|
||||
"""Envía una notificación push a todos los dispositivos suscritos a un topic (ej. RUTA-01)."""
|
||||
title = payload.get("title", "")
|
||||
body = payload.get("body", "")
|
||||
# `data` viaja como Dict[str, str] en FCM; permite que el cliente
|
||||
# clasifique el evento (event, routeId) en notifications_screen.dart.
|
||||
raw_data = payload.get("data") or {}
|
||||
data: dict[str, str] = {str(k): str(v) for k, v in raw_data.items() if v is not None}
|
||||
|
||||
if not _firebase_initialized:
|
||||
print(f"[MOCK PUSH] -> Topic: {topic} | Título: '{title}' | Mensaje: '{body}'")
|
||||
print(f"[MOCK PUSH] -> Topic: {topic} | Título: '{title}' | Mensaje: '{body}' | Data: {data}")
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -38,9 +44,29 @@ def send_to_topic(topic: str, payload: dict):
|
||||
title=title,
|
||||
body=body,
|
||||
),
|
||||
data=data or None,
|
||||
topic=topic,
|
||||
)
|
||||
response = messaging.send(message)
|
||||
print(f"Push enviado al topic '{topic}' exitosamente. MessageID: {response}")
|
||||
except Exception as e:
|
||||
print(f"Error al enviar push al topic '{topic}': {e}")
|
||||
print(f"Error al enviar push al topic '{topic}': {e}")
|
||||
|
||||
def send_whatsapp_alert(phone: str, message: str):
|
||||
"""
|
||||
Envía un WhatsApp usando la API gratuita de CallMeBot.
|
||||
"""
|
||||
print("\n" + "="*50)
|
||||
print(f"🟢 [WHATSAPP TRIGGER] Preparando mensaje para {phone}")
|
||||
print(f"💬 Mensaje: {message}")
|
||||
print("="*50 + "\n")
|
||||
|
||||
# REEMPLAZA ESTO POR EL CÓDIGO QUE TE DIO EL BOT EN WHATSAPP:
|
||||
apikey = "6756808" # <--- BORRA "TU_API_KEY_AQUI" Y PON TU CÓDIGO REAL AQUÍ
|
||||
safe_msg = urllib.parse.quote(message)
|
||||
url = f"https://api.callmebot.com/whatsapp.php?phone={phone}&text={safe_msg}&apikey={apikey}"
|
||||
|
||||
try:
|
||||
urllib.request.urlopen(url, timeout=5)
|
||||
except Exception as e:
|
||||
print(f"Error enviando WhatsApp real: {e}")
|
||||
Reference in New Issue
Block a user