Fix lint errors

This commit is contained in:
2026-02-20 04:59:56 +00:00
parent bcdc41ecd5
commit 58393a538e
19 changed files with 442 additions and 321 deletions

View File

@@ -1,3 +1,5 @@
"""Conversation router for detect-intent endpoints."""
import logging
from typing import Annotated
@@ -23,6 +25,7 @@ async def detect_intent(
Args:
request: External conversation request from client
conversation_manager: Conversation manager service instance
Returns:
Dialogflow detect intent response
@@ -32,12 +35,12 @@ async def detect_intent(
logger.info("Received detect-intent request")
response = await conversation_manager.manage_conversation(request)
logger.info("Successfully processed detect-intent request")
return response
except ValueError as e:
logger.error(f"Validation error: {e!s}", exc_info=True)
raise HTTPException(status_code=400, detail=str(e))
logger.exception("Validation error")
raise HTTPException(status_code=400, detail=str(e)) from e
except Exception as e:
logger.error(f"Error processing detect-intent: {e!s}", exc_info=True)
raise HTTPException(status_code=500, detail="Internal server error")
logger.exception("Error processing detect-intent")
raise HTTPException(status_code=500, detail="Internal server error") from e
else:
return response

View File

@@ -1,3 +1,5 @@
"""Notification router for processing push notifications."""
import logging
from typing import Annotated
@@ -31,6 +33,7 @@ async def process_notification(
Args:
request: External notification request with text, phone, and parameters
notification_manager: Notification manager service instance
Returns:
None (204 No Content)
@@ -46,9 +49,9 @@ async def process_notification(
# Match Java behavior: process but don't return response body
except ValueError as e:
logger.error(f"Validation error: {e!s}", exc_info=True)
raise HTTPException(status_code=400, detail=str(e))
logger.exception("Validation error")
raise HTTPException(status_code=400, detail=str(e)) from e
except Exception as e:
logger.error(f"Error processing notification: {e!s}", exc_info=True)
raise HTTPException(status_code=500, detail="Internal server error")
logger.exception("Error processing notification")
raise HTTPException(status_code=500, detail="Internal server error") from e

View File

@@ -1,9 +1,11 @@
"""Quick replies router for FAQ session management."""
import logging
from typing import Annotated
from uuid import uuid4
from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel
from pydantic import BaseModel, Field
from capa_de_integracion.dependencies import (
get_firestore_service,
@@ -20,19 +22,25 @@ router = APIRouter(prefix="/api/v1/quick-replies", tags=["quick-replies"])
class QuickReplyUser(BaseModel):
"""User information for quick reply requests."""
telefono: str
nombre: str
class QuickReplyScreenRequest(BaseModel):
"""Request model for quick reply screen."""
usuario: QuickReplyUser
pantallaContexto: str
pantalla_contexto: str = Field(alias="pantallaContexto")
model_config = {"populate_by_name": True}
class QuickReplyScreenResponse(BaseModel):
responseId: str
"""Response model for quick reply screen."""
response_id: str = Field(alias="responseId")
quick_replies: QuickReplyScreen
@@ -52,25 +60,31 @@ async def start_quick_reply_session(
Args:
request: Quick reply screen request
redis_service: Redis service instance
firestore_service: Firestore service instance
quick_reply_content_service: Quick reply content service instance
Returns:
Detect intent response with quick reply questions
"""
try:
telefono = request.usuario.telefono
pantalla_contexto = request.pantallaContexto
if not telefono or not telefono.strip():
def _validate_phone(phone: str) -> None:
if not phone or not phone.strip():
msg = "Phone number is required"
raise ValueError(msg)
try:
telefono = request.usuario.telefono
pantalla_contexto = request.pantalla_contexto
_validate_phone(telefono)
session = await firestore_service.get_session_by_phone(telefono)
if session:
session_id = session.sessionId
session_id = session.session_id
await firestore_service.update_pantalla_contexto(
session_id, pantalla_contexto,
)
session.pantallaContexto = pantalla_contexto
session.pantalla_contexto = pantalla_contexto
else:
session_id = str(uuid4())
user_id = f"user_by_phone_{telefono.replace(' ', '').replace('-', '')}"
@@ -81,7 +95,9 @@ async def start_quick_reply_session(
# Cache session
await redis_service.save_session(session)
logger.info(
f"Created quick reply session {session_id} for screen: {pantalla_contexto}",
"Created quick reply session %s for screen: %s",
session_id,
pantalla_contexto,
)
# Load quick replies
@@ -89,13 +105,13 @@ async def start_quick_reply_session(
pantalla_contexto,
)
return QuickReplyScreenResponse(
responseId=session_id, quick_replies=quick_replies,
response_id=session_id, quick_replies=quick_replies,
)
except ValueError as e:
logger.error(f"Validation error: {e}", exc_info=True)
raise HTTPException(status_code=400, detail=str(e))
logger.exception("Validation error")
raise HTTPException(status_code=400, detail=str(e)) from e
except Exception as e:
logger.error(f"Error starting quick reply session: {e}", exc_info=True)
raise HTTPException(status_code=500, detail="Internal server error")
logger.exception("Error starting quick reply session")
raise HTTPException(status_code=500, detail="Internal server error") from e