FIX error 500

This commit is contained in:
PAVEL PALMA
2026-01-07 23:04:51 -06:00
parent a828de3990
commit b7b773be2e
7 changed files with 379 additions and 11 deletions

View File

@@ -4,6 +4,7 @@
*/
package com.example.mapper.conversation;
import com.google.cloud.Timestamp;
import com.example.dto.dialogflow.conversation.ConversationMessageDTO;
import com.example.dto.dialogflow.conversation.MessageType;
@@ -31,9 +32,16 @@ public class ConversationMessageMapper {
}
public ConversationMessageDTO fromMap(Map<String, Object> map) {
Object timeObject = map.get("tiempo");
Instant timestamp = null;
if (timeObject instanceof Timestamp) {
timestamp = ((Timestamp) timeObject).toDate().toInstant();
} else if (timeObject instanceof Instant) {
timestamp = (Instant) timeObject;
}
return new ConversationMessageDTO(
MessageType.valueOf((String) map.get("entidad")),
(Instant) map.get("tiempo"),
timestamp,
(String) map.get("mensaje"),
(Map<String, Object>) map.get("parametros"),
(String) map.get("canal")

View File

@@ -239,22 +239,25 @@ public class ConversationManagerService {
DetectIntentRequestDTO request, ConversationSessionDTO session) {
Instant now = Instant.now();
if (Duration.between(session.lastModified(), now).toMinutes() < SESSION_RESET_THRESHOLD_MINUTES) {
logger.info("Recent Session Found: Session {} is within the 10-minute threshold. Proceeding to Dialogflow.",
logger.info("Recent Session Found: Session {} is within the 30-minute threshold. Proceeding to Dialogflow.",
session.sessionId());
return processDialogflowRequest(session, request, context.userId(), context.userMessageText(),
context.primaryPhoneNumber(), false);
} else {
logger.info(
"Old Session Found: Session {} is older than the threshold. Fetching history and continuing with same session.",
"Old Session Found: Session {} is older than the 30-minute threshold. Fetching history and continuing with same session.",
session.sessionId());
return memoryStoreConversationService.getMessages(session.sessionId()).collectList()
.map(conversationContextMapper::toTextFromMessages)
.defaultIfEmpty("")
.flatMap(conversationHistory -> {
DetectIntentRequestDTO newRequest = request.withParameter(CONV_HISTORY_PARAM, conversationHistory);
return processDialogflowRequest(session, newRequest, context.userId(), context.userMessageText(),
context.primaryPhoneNumber(), false);
});
return memoryStoreConversationService.getMessages(session.sessionId())
.collectList()
// Adding use the TextWithLimits to truncate according to business rule 30 days/60 messages
.map(messages -> conversationContextMapper.toTextWithLimits(session, messages))
.defaultIfEmpty("")
.flatMap(conversationHistory -> {
// Inject historial (max 60 msgs / 30 días / 50KB)
DetectIntentRequestDTO newRequest = request.withParameter(CONV_HISTORY_PARAM, conversationHistory);
return processDialogflowRequest(session, newRequest, context.userId(), context.userMessageText(),
context.primaryPhoneNumber(), false);
});
}
}