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

@@ -1,9 +1,11 @@
import json
import logging
from ..config import Settings
from ..models.quick_replies import QuickReplyScreen, QuickReplyQuestions
from capa_de_integracion.config import Settings
from capa_de_integracion.models.quick_replies import (
QuickReplyQuestions,
QuickReplyScreen,
)
logger = logging.getLogger(__name__)
@@ -11,23 +13,22 @@ logger = logging.getLogger(__name__)
class QuickReplyContentService:
"""Service for loading quick reply screen content from JSON files."""
def __init__(self, settings: Settings):
"""
Initialize quick reply content service.
def __init__(self, settings: Settings) -> None:
"""Initialize quick reply content service.
Args:
settings: Application settings
"""
self.settings = settings
self.quick_replies_path = settings.base_path / "quick_replies"
logger.info(
f"QuickReplyContentService initialized with path: {self.quick_replies_path}"
f"QuickReplyContentService initialized with path: {self.quick_replies_path}",
)
async def get_quick_replies(self, screen_id: str) -> QuickReplyScreen:
"""
Load quick reply screen content by ID.
"""Load quick reply screen content by ID.
Args:
screen_id: Screen identifier (e.g., "pagos", "home")
@@ -37,6 +38,7 @@ class QuickReplyContentService:
Raises:
ValueError: If the quick reply file is not found
"""
if not screen_id or not screen_id.strip():
logger.warning("screen_id is null or empty. Returning empty quick replies")
@@ -53,11 +55,12 @@ class QuickReplyContentService:
try:
if not file_path.exists():
logger.warning(f"Quick reply file not found: {file_path}")
msg = f"Quick reply file not found for screen_id: {screen_id}"
raise ValueError(
f"Quick reply file not found for screen_id: {screen_id}"
msg,
)
with open(file_path, "r", encoding="utf-8") as f:
with open(file_path, encoding="utf-8") as f:
data = json.load(f)
# Parse questions
@@ -80,20 +83,22 @@ class QuickReplyContentService:
)
logger.info(
f"Successfully loaded {len(preguntas)} quick replies for screen: {screen_id}"
f"Successfully loaded {len(preguntas)} quick replies for screen: {screen_id}",
)
return quick_reply
except json.JSONDecodeError as e:
logger.error(f"Error parsing JSON file {file_path}: {e}", exc_info=True)
msg = f"Invalid JSON format in quick reply file for screen_id: {screen_id}"
raise ValueError(
f"Invalid JSON format in quick reply file for screen_id: {screen_id}"
msg,
) from e
except Exception as e:
logger.error(
f"Error loading quick replies for screen {screen_id}: {e}",
exc_info=True,
)
msg = f"Error loading quick replies for screen_id: {screen_id}"
raise ValueError(
f"Error loading quick replies for screen_id: {screen_id}"
msg,
) from e