Files
int-layer/src/capa_de_integracion/routers/notification.py
2026-02-20 19:32:54 +00:00

61 lines
2.1 KiB
Python

"""Notification router for processing push notifications."""
import logging
from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException
from capa_de_integracion.dependencies import get_notification_manager
from capa_de_integracion.models.notification import ExternalNotificationRequest
from capa_de_integracion.services import NotificationManagerService
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api/v1/dialogflow", tags=["notifications"])
@router.post("/notification", status_code=200)
async def process_notification(
request: ExternalNotificationRequest,
notification_manager: Annotated[
NotificationManagerService,
Depends(
get_notification_manager,
),
],
) -> None:
"""Process push notification from external system.
This endpoint receives notifications (e.g., "Your card was blocked") and:
1. Stores them in Redis/Firestore
2. Associates them with the user's conversation session
3. Triggers a Dialogflow event
When the user later sends a message asking about the notification
("Why was it blocked?"), the message filter will classify it as
NOTIFICATION and route to the appropriate handler.
Args:
request: External notification request with text, phone, and parameters
notification_manager: Notification manager service instance
Returns:
None (204 No Content)
Raises:
HTTPException: 400 if validation fails, 500 for internal errors
"""
try:
logger.info("Received notification request")
await notification_manager.process_notification(request)
logger.info("Successfully processed notification request")
# Match Java behavior: process but don't return response body
except ValueError as e:
logger.exception("Validation error")
raise HTTPException(status_code=400, detail=str(e)) from e
except Exception as e:
logger.exception("Error processing notification")
raise HTTPException(status_code=500, detail="Internal server error") from e