From 2c722c1166c4b7248b297d2a57b473b9e200004d Mon Sep 17 00:00:00 2001 From: Anibal Angulo Date: Fri, 20 Feb 2026 05:06:56 +0000 Subject: [PATCH] Fix type errors --- .../models/notification.py | 20 +++++++++---------- .../routers/quick_replies.py | 2 +- .../services/conversation_manager.py | 16 +++++++-------- .../services/firestore_service.py | 12 +++++++++-- .../services/redis_service.py | 6 +++--- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/capa_de_integracion/models/notification.py b/src/capa_de_integracion/models/notification.py index 8cef14b..4bda0f4 100644 --- a/src/capa_de_integracion/models/notification.py +++ b/src/capa_de_integracion/models/notification.py @@ -69,16 +69,16 @@ class Notification(BaseModel): New Notification instance with current timestamp """ - return cls( - idNotificacion=id_notificacion, - telefono=telefono, - timestampCreacion=datetime.now(UTC), - texto=texto, - nombreEventoDialogflow=nombre_evento_dialogflow, - codigoIdiomaDialogflow=codigo_idioma_dialogflow, - parametros=parametros or {}, - status=status, - ) + return cls.model_validate({ + "idNotificacion": id_notificacion, + "telefono": telefono, + "timestampCreacion": datetime.now(UTC), + "texto": texto, + "nombreEventoDialogflow": nombre_evento_dialogflow, + "codigoIdiomaDialogflow": codigo_idioma_dialogflow, + "parametros": parametros or {}, + "status": status, + }) class NotificationSession(BaseModel): diff --git a/src/capa_de_integracion/routers/quick_replies.py b/src/capa_de_integracion/routers/quick_replies.py index 37bda78..2fb965d 100644 --- a/src/capa_de_integracion/routers/quick_replies.py +++ b/src/capa_de_integracion/routers/quick_replies.py @@ -105,7 +105,7 @@ async def start_quick_reply_session( pantalla_contexto, ) return QuickReplyScreenResponse( - response_id=session_id, quick_replies=quick_replies, + responseId=session_id, quick_replies=quick_replies, ) except ValueError as e: diff --git a/src/capa_de_integracion/services/conversation_manager.py b/src/capa_de_integracion/services/conversation_manager.py index def2f50..88dcb77 100644 --- a/src/capa_de_integracion/services/conversation_manager.py +++ b/src/capa_de_integracion/services/conversation_manager.py @@ -84,16 +84,16 @@ class ConversationManagerService: await self.redis_service.save_session(session) # Step 2: Check for pantallaContexto in existing session - if session.pantallaContexto: + if session.pantalla_contexto: # Check if pantallaContexto is stale (10 minutes) if self._is_pantalla_context_valid(session.last_modified): logger.info( "Detected 'pantallaContexto' in session: %s. " "Delegating to QuickReplies flow.", - session.pantallaContexto, + session.pantalla_contexto, ) response = await self._manage_quick_reply_conversation( - request, session.pantallaContexto, + request, session.pantalla_contexto, ) if response: # Save user message to Firestore @@ -214,9 +214,9 @@ class ConversationManagerService: # Step 3i: Return response object return DetectIntentResponse( - response_id=str(uuid4()), - query_result=QueryResult( - response_text=assistant_response, + responseId=str(uuid4()), + queryResult=QueryResult( + responseText=assistant_response, parameters=None, ), quick_replies=None, @@ -265,8 +265,8 @@ class ConversationManagerService: # Create response with the matched quick reply answer return DetectIntentResponse( - response_id=str(uuid4()), - query_result=QueryResult(response_text=matched_answer, parameters=None), + responseId=str(uuid4()), + queryResult=QueryResult(responseText=matched_answer, parameters=None), quick_replies=quick_reply_screen, ) diff --git a/src/capa_de_integracion/services/firestore_service.py b/src/capa_de_integracion/services/firestore_service.py index 3bb75b9..7c94652 100644 --- a/src/capa_de_integracion/services/firestore_service.py +++ b/src/capa_de_integracion/services/firestore_service.py @@ -39,7 +39,7 @@ class FirestoreService: self.db.close() logger.info("Firestore client closed") - def _session_ref(self, session_id: str) -> firestore.DocumentReference: + def _session_ref(self, session_id: str) -> firestore.AsyncDocumentReference: """Get Firestore document reference for session.""" return self.db.collection(self.conversations_collection).document(session_id) @@ -284,7 +284,9 @@ class FirestoreService: # ====== Notification Methods ====== - def _notification_ref(self, notification_id: str) -> firestore.DocumentReference: + def _notification_ref( + self, notification_id: str, + ) -> firestore.AsyncDocumentReference: """Get Firestore document reference for notification.""" return self.db.collection(self.notifications_collection).document( notification_id, @@ -370,6 +372,12 @@ class FirestoreService: return session_data = doc.to_dict() + if not session_data: + logger.warning( + "Notification session %s has no data in Firestore", + session_id, + ) + return notifications = session_data.get("notificaciones", []) # Update status for all notifications diff --git a/src/capa_de_integracion/services/redis_service.py b/src/capa_de_integracion/services/redis_service.py index a1ac49a..0f86a0c 100644 --- a/src/capa_de_integracion/services/redis_service.py +++ b/src/capa_de_integracion/services/redis_service.py @@ -291,10 +291,10 @@ class RedisService: else: # Create new session updated_session = NotificationSession( - session_id=notification_session_id, + sessionId=notification_session_id, telefono=phone_number, - fecha_creacion=datetime.now(UTC), - ultima_actualizacion=datetime.now(UTC), + fechaCreacion=datetime.now(UTC), + ultimaActualizacion=datetime.now(UTC), notificaciones=[new_entry], )