This commit is contained in:
2026-02-20 04:38:32 +00:00
committed by Anibal Angulo
parent 5fecad8e2d
commit 52a674959c
20 changed files with 309 additions and 283 deletions

View File

@@ -2,12 +2,15 @@ import asyncio
import logging
from uuid import uuid4
from ..config import Settings
from ..models.notification import ExternalNotificationRequest, Notification
from .redis_service import RedisService
from .firestore_service import FirestoreService
from .dlp_service import DLPService
from capa_de_integracion.config import Settings
from capa_de_integracion.models.notification import (
ExternalNotificationRequest,
Notification,
)
from .dlp_service import DLPService
from .firestore_service import FirestoreService
from .redis_service import RedisService
logger = logging.getLogger(__name__)
@@ -15,8 +18,7 @@ PREFIX_PO_PARAM = "notification_po_"
class NotificationManagerService:
"""
Manages notification processing and integration with conversations.
"""Manages notification processing and integration with conversations.
Handles push notifications from external systems, stores them in
Redis/Firestore, and triggers Dialogflow event detection.
@@ -28,9 +30,8 @@ class NotificationManagerService:
redis_service: RedisService,
firestore_service: FirestoreService,
dlp_service: DLPService,
):
"""
Initialize notification manager.
) -> None:
"""Initialize notification manager.
Args:
settings: Application settings
@@ -38,6 +39,7 @@ class NotificationManagerService:
redis_service: Redis caching service
firestore_service: Firestore persistence service
dlp_service: Data Loss Prevention service
"""
self.settings = settings
self.redis_service = redis_service
@@ -49,10 +51,9 @@ class NotificationManagerService:
logger.info("NotificationManagerService initialized")
async def process_notification(
self, external_request: ExternalNotificationRequest
self, external_request: ExternalNotificationRequest,
) -> None:
"""
Process a push notification from external system.
"""Process a push notification from external system.
Flow:
1. Validate phone number
@@ -71,6 +72,7 @@ class NotificationManagerService:
Raises:
ValueError: If phone number is missing
"""
telefono = external_request.telefono
@@ -101,17 +103,17 @@ class NotificationManagerService:
# Save notification to Redis (with async Firestore write-back)
await self.redis_service.save_or_append_notification(new_notification_entry)
logger.info(
f"Notification for phone {telefono} cached. Kicking off async Firestore write-back"
f"Notification for phone {telefono} cached. Kicking off async Firestore write-back",
)
# Fire-and-forget Firestore write (matching Java's .subscribe() behavior)
async def save_notification_to_firestore():
async def save_notification_to_firestore() -> None:
try:
await self.firestore_service.save_or_append_notification(
new_notification_entry
new_notification_entry,
)
logger.debug(
f"Notification entry persisted to Firestore for phone {telefono}"
f"Notification entry persisted to Firestore for phone {telefono}",
)
except Exception as e:
logger.error(