.
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
"""
|
||||
Copyright 2025 Google. This software is provided as-is, without warranty or
|
||||
representation for any use or purpose. Your use of it is subject to your
|
||||
agreement with Google.
|
||||
|
||||
Quick Reply content service for loading FAQ screens.
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
from ..config import Settings
|
||||
from ..models.quick_replies import QuickReplyDTO, QuestionDTO
|
||||
from ..models.quick_replies import QuickReplyScreen, QuickReplyQuestions
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -33,7 +25,7 @@ class QuickReplyContentService:
|
||||
f"QuickReplyContentService initialized with path: {self.quick_replies_path}"
|
||||
)
|
||||
|
||||
async def get_quick_replies(self, screen_id: str) -> QuickReplyDTO | None:
|
||||
async def get_quick_replies(self, screen_id: str) -> QuickReplyScreen:
|
||||
"""
|
||||
Load quick reply screen content by ID.
|
||||
|
||||
@@ -41,11 +33,14 @@ class QuickReplyContentService:
|
||||
screen_id: Screen identifier (e.g., "pagos", "home")
|
||||
|
||||
Returns:
|
||||
Quick reply DTO or None if not found
|
||||
Quick reply DTO
|
||||
|
||||
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")
|
||||
return QuickReplyDTO(
|
||||
return QuickReplyScreen(
|
||||
header="empty",
|
||||
body=None,
|
||||
button=None,
|
||||
@@ -58,7 +53,7 @@ class QuickReplyContentService:
|
||||
try:
|
||||
if not file_path.exists():
|
||||
logger.warning(f"Quick reply file not found: {file_path}")
|
||||
return None
|
||||
raise ValueError(f"Quick reply file not found for screen_id: {screen_id}")
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
@@ -66,7 +61,7 @@ class QuickReplyContentService:
|
||||
# Parse questions
|
||||
preguntas_data = data.get("preguntas", [])
|
||||
preguntas = [
|
||||
QuestionDTO(
|
||||
QuickReplyQuestions(
|
||||
titulo=q.get("titulo", ""),
|
||||
descripcion=q.get("descripcion"),
|
||||
respuesta=q.get("respuesta", ""),
|
||||
@@ -74,7 +69,7 @@ class QuickReplyContentService:
|
||||
for q in preguntas_data
|
||||
]
|
||||
|
||||
quick_reply = QuickReplyDTO(
|
||||
quick_reply = QuickReplyScreen(
|
||||
header=data.get("header"),
|
||||
body=data.get("body"),
|
||||
button=data.get("button"),
|
||||
@@ -89,10 +84,10 @@ class QuickReplyContentService:
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Error parsing JSON file {file_path}: {e}", exc_info=True)
|
||||
return None
|
||||
raise ValueError(f"Invalid JSON format in quick reply file for screen_id: {screen_id}") from e
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Error loading quick replies for screen {screen_id}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return None
|
||||
raise ValueError(f"Error loading quick replies for screen_id: {screen_id}") from e
|
||||
|
||||
Reference in New Issue
Block a user