UPDATE sessions

This commit is contained in:
PAVEL PALMA
2026-01-27 13:02:33 -06:00
parent b3c2930476
commit b6c7bdbd0d

View File

@@ -235,15 +235,24 @@ public class ConversationManagerService {
private Mono<DetectIntentResponseDTO> proceedWithConversation(ConversationContext context,
DetectIntentRequestDTO request, ConversationSessionDTO session) {
Instant now = Instant.now();
if (Duration.between(session.lastModified(), now).toMinutes() > SESSION_RESET_THRESHOLD_MINUTES) {
if (Duration.between(session.lastModified(), now).toMinutes() < SESSION_RESET_THRESHOLD_MINUTES) {
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 30-minute threshold. Fetching history and continuing with same session.",
"Old Session Found: Session {} is older than the 30-minute threshold.",
session.sessionId());
// Generar un nuevo ID de sesión
String newSessionId = SessionIdGenerator.generateStandardSessionId();
logger.info("Creating new session {} from old session {} due to timeout.", newSessionId, session.sessionId());
// Crear un nuevo DTO de sesión basado en la antigua, pero con el nuevo ID
ConversationSessionDTO newSession = ConversationSessionDTO.create(newSessionId, context.userId(), context.primaryPhoneNumber());
return memoryStoreConversationService.getMessages(session.sessionId())
.collectList()
// Adding use the TextWithLimits to truncate according to business rule 30 days/60 messages
@@ -252,7 +261,7 @@ public class ConversationManagerService {
.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(),
return processDialogflowRequest(newSession, newRequest, context.userId(), context.userMessageText(),
context.primaryPhoneNumber(), false);
});
}