UPDATE sessions
This commit is contained in:
@@ -235,15 +235,24 @@ public class ConversationManagerService {
|
|||||||
private Mono<DetectIntentResponseDTO> proceedWithConversation(ConversationContext context,
|
private Mono<DetectIntentResponseDTO> proceedWithConversation(ConversationContext context,
|
||||||
DetectIntentRequestDTO request, ConversationSessionDTO session) {
|
DetectIntentRequestDTO request, ConversationSessionDTO session) {
|
||||||
Instant now = Instant.now();
|
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.",
|
logger.info("Recent Session Found: Session {} is within the 30-minute threshold. Proceeding to Dialogflow.",
|
||||||
session.sessionId());
|
session.sessionId());
|
||||||
return processDialogflowRequest(session, request, context.userId(), context.userMessageText(),
|
return processDialogflowRequest(session, request, context.userId(), context.userMessageText(),
|
||||||
context.primaryPhoneNumber(), false);
|
context.primaryPhoneNumber(), false);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
logger.info(
|
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());
|
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())
|
return memoryStoreConversationService.getMessages(session.sessionId())
|
||||||
.collectList()
|
.collectList()
|
||||||
// Adding use the TextWithLimits to truncate according to business rule 30 days/60 messages
|
// Adding use the TextWithLimits to truncate according to business rule 30 days/60 messages
|
||||||
@@ -252,7 +261,7 @@ public class ConversationManagerService {
|
|||||||
.flatMap(conversationHistory -> {
|
.flatMap(conversationHistory -> {
|
||||||
// Inject historial (max 60 msgs / 30 días / 50KB)
|
// Inject historial (max 60 msgs / 30 días / 50KB)
|
||||||
DetectIntentRequestDTO newRequest = request.withParameter(CONV_HISTORY_PARAM, conversationHistory);
|
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);
|
context.primaryPhoneNumber(), false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user