Add support for prev notification collection structure
All checks were successful
CI / ci (pull_request) Successful in 19s

This commit is contained in:
Anibal Angulo
2026-03-10 18:51:23 +00:00
parent 1803d011d0
commit b911c92e05
4 changed files with 80 additions and 50 deletions

View File

@@ -8,51 +8,54 @@ Usage:
uv run utils/register_notification_firestore.py <phone>
Reads project/database/collection settings from config.yaml.
The generated notification follows the latest English-camelCase schema
used in the production collection (``artifacts/default-app-id/notifications``).
"""
import random
import sys
import time
import uuid
from datetime import datetime, timezone
import yaml
from google.cloud.firestore import Client
from google.cloud.firestore import Client, SERVER_TIMESTAMP
NOTIFICATION_TEMPLATES = [
{
"texto": "Se detectó un cargo de $1,500 en tu cuenta",
"parametros": {
"text": "Se detectó un cargo de $1,500 en tu cuenta",
"parameters": {
"notification_po_transaction_id": "TXN15367",
"notification_po_amount": 5814,
},
},
{
"texto": (
"text": (
"💡 Recuerda que puedes obtener tu Adelanto de Nómina en"
" cualquier momento, sólo tienes que seleccionar Solicitud"
" adelanto de Nómina en tu app."
),
"parametros": {
"parameters": {
"notification_po_Categoria": "Adelanto de Nómina solicitud",
"notification_po_caption": "Adelanto de Nómina",
},
},
{
"texto": (
"text": (
"Estás a un clic de Programa de Lealtad, entra a tu app y"
" finaliza Tu contratación en instantes. ⏱ 🤳"
),
"parametros": {
"parameters": {
"notification_po_Categoria": "Tarjeta de Crédito Contratación",
"notification_po_caption": "Tarjeta de Crédito",
},
},
{
"texto": (
"text": (
"🚀 ¿Listo para obtener tu Cápsula Plus? Continúa en tu app"
" y termina al instante. Conoce más en: va.app"
),
"parametros": {},
"parameters": {},
},
]
@@ -75,15 +78,16 @@ def main() -> None:
collection_path = cfg["notifications_collection_path"]
doc_ref = db.collection(collection_path).document(phone)
now = datetime.now(tz=timezone.utc)
template = random.choice(NOTIFICATION_TEMPLATES)
notification = {
"id_notificacion": str(uuid.uuid4()),
"notificationId": str(uuid.uuid4()),
"telefono": phone,
"timestamp_creacion": time.time(),
"texto": template["texto"],
"nombre_evento_dialogflow": "notificacion",
"codigo_idioma_dialogflow": "es",
"parametros": template["parametros"],
"timestampCreacion": now,
"text": template["text"],
"event": "notificacion",
"languageCode": "es",
"parameters": template["parameters"],
"status": "active",
}
@@ -92,14 +96,23 @@ def main() -> None:
data = doc.to_dict() or {}
notifications = data.get("notificaciones", [])
notifications.append(notification)
doc_ref.update({"notificaciones": notifications})
doc_ref.update({
"notificaciones": notifications,
"ultimaActualizacion": SERVER_TIMESTAMP,
})
else:
doc_ref.set({"notificaciones": [notification]})
doc_ref.set({
"sessionId": "",
"telefono": phone,
"fechaCreacion": SERVER_TIMESTAMP,
"ultimaActualizacion": SERVER_TIMESTAMP,
"notificaciones": [notification],
})
total = len(doc_ref.get().to_dict().get("notificaciones", []))
print(f"✅ Registered notification for {phone}")
print(f" ID: {notification['id_notificacion']}")
print(f" Text: {template['texto'][:80]}...")
print(f" ID: {notification['notificationId']}")
print(f" Text: {template['text'][:80]}...")
print(f" Collection: {collection_path}")
print(f" Total notifications for this phone: {total}")