@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
package com.example.mapper.conversation;
|
||||
import com.google.cloud.Timestamp;
|
||||
|
||||
import com.example.dto.dialogflow.conversation.ConversationMessageDTO;
|
||||
import com.example.dto.dialogflow.conversation.MessageType;
|
||||
@@ -32,16 +31,9 @@ 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")),
|
||||
timestamp,
|
||||
(Instant) map.get("tiempo"),
|
||||
(String) map.get("mensaje"),
|
||||
(Map<String, Object>) map.get("parametros"),
|
||||
(String) map.get("canal")
|
||||
|
||||
@@ -239,25 +239,22 @@ 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 30-minute threshold. Proceeding to Dialogflow.",
|
||||
logger.info("Recent Session Found: Session {} is within the 10-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 threshold. Fetching history and continuing with same session.",
|
||||
session.sessionId());
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user