UPDATE 22-sept
This commit is contained in:
@@ -89,7 +89,7 @@ public class MessageEntryFilter {
|
|||||||
queryInputText
|
queryInputText
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info("Sending classification request to Gemini for input (first 100 chars): '{}'...",
|
logger.debug("Sending classification request to Gemini for input (first 100 chars): '{}'...",
|
||||||
queryInputText.substring(0, Math.min(queryInputText.length(), 100)));
|
queryInputText.substring(0, Math.min(queryInputText.length(), 100)));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -103,18 +103,16 @@ public class MessageEntryFilter {
|
|||||||
|
|
||||||
String resultCategory = switch (geminiResponse != null ? geminiResponse.trim().toUpperCase() : "") {
|
String resultCategory = switch (geminiResponse != null ? geminiResponse.trim().toUpperCase() : "") {
|
||||||
case CATEGORY_CONVERSATION -> {
|
case CATEGORY_CONVERSATION -> {
|
||||||
logger.info("Classified as {}. Input: '{}'", CATEGORY_CONVERSATION);
|
logger.info("Classified as {}.", CATEGORY_CONVERSATION);
|
||||||
logger.debug("Classified as {}. Input: '{}'", CATEGORY_CONVERSATION, queryInputText);
|
|
||||||
yield CATEGORY_CONVERSATION;
|
yield CATEGORY_CONVERSATION;
|
||||||
}
|
}
|
||||||
case CATEGORY_NOTIFICATION -> {
|
case CATEGORY_NOTIFICATION -> {
|
||||||
logger.info("Classified as {}. Input: '{}'", CATEGORY_NOTIFICATION);
|
logger.info("Classified as {}.", CATEGORY_NOTIFICATION);
|
||||||
logger.debug("Classified as {}. Input: '{}'", CATEGORY_NOTIFICATION, queryInputText);
|
|
||||||
yield CATEGORY_NOTIFICATION;
|
yield CATEGORY_NOTIFICATION;
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
logger.warn("Gemini returned an unrecognised classification or was null/blank: '{}'. Expected '{}' or '{}'. Input: '{}'. Returning {}.",
|
logger.warn("Gemini returned an unrecognised classification or was null/blank: '{}'. Expected '{}' or '{}'. Returning {}.",
|
||||||
geminiResponse, CATEGORY_CONVERSATION, CATEGORY_NOTIFICATION, queryInputText, CATEGORY_UNKNOWN);
|
geminiResponse, CATEGORY_CONVERSATION, CATEGORY_NOTIFICATION, CATEGORY_UNKNOWN);
|
||||||
yield CATEGORY_UNKNOWN;
|
yield CATEGORY_UNKNOWN;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -96,15 +96,15 @@ public class NotificationContextResolver {
|
|||||||
|
|
||||||
if (geminiResponse != null && !geminiResponse.isBlank()) {
|
if (geminiResponse != null && !geminiResponse.isBlank()) {
|
||||||
if (geminiResponse.trim().equalsIgnoreCase(CATEGORY_DIALOGFLOW)) {
|
if (geminiResponse.trim().equalsIgnoreCase(CATEGORY_DIALOGFLOW)) {
|
||||||
logger.info("Resolved to {}. Input: '{}'", CATEGORY_DIALOGFLOW, queryInputText);
|
logger.info("Resolved to {}.", CATEGORY_DIALOGFLOW);
|
||||||
return CATEGORY_DIALOGFLOW;
|
return CATEGORY_DIALOGFLOW;
|
||||||
} else {
|
} else {
|
||||||
logger.info("Resolved to a specific response. Input: '{}'", queryInputText);
|
logger.info("Resolved to a specific response.");
|
||||||
return geminiResponse;
|
return geminiResponse;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Gemini returned a null or blank response. Input: '{}'. Returning {}.",
|
logger.warn("Gemini returned a null or blank response. Returning {}.",
|
||||||
queryInputText, CATEGORY_DIALOGFLOW);
|
CATEGORY_DIALOGFLOW);
|
||||||
return CATEGORY_DIALOGFLOW;
|
return CATEGORY_DIALOGFLOW;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class ConversationManagerService {
|
|||||||
.error(new IllegalArgumentException("Phone number is required to manage conversation sessions."));
|
.error(new IllegalArgumentException("Phone number is required to manage conversation sessions."));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Primary Check (MemoryStore): Looking up session for phone number: {}", userPhoneNumber);
|
logger.info("Primary Check (MemoryStore): Looking up session for phone number");
|
||||||
return memoryStoreConversationService.getSessionByTelefono(userPhoneNumber)
|
return memoryStoreConversationService.getSessionByTelefono(userPhoneNumber)
|
||||||
.flatMap(session -> handleMessageClassification(context, request, session))
|
.flatMap(session -> handleMessageClassification(context, request, session))
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
.switchIfEmpty(Mono.defer(() -> {
|
||||||
@@ -283,8 +283,8 @@ public class ConversationManagerService {
|
|||||||
return memoryStoreNotificationService.getSessionByTelefono(userPhoneNumber)
|
return memoryStoreNotificationService.getSessionByTelefono(userPhoneNumber)
|
||||||
.switchIfEmpty(Mono.defer(() -> {
|
.switchIfEmpty(Mono.defer(() -> {
|
||||||
String newSessionId = SessionIdGenerator.generateStandardSessionId();
|
String newSessionId = SessionIdGenerator.generateStandardSessionId();
|
||||||
logger.info("No existing notification session found for phone number {}. Creating new session: {}",
|
logger.info("No existing notification session found for phone number. Creating new session: {}",
|
||||||
userPhoneNumber, newSessionId);
|
newSessionId);
|
||||||
return Mono.just(ConversationSessionDTO.create(newSessionId, userId, userPhoneNumber));
|
return Mono.just(ConversationSessionDTO.create(newSessionId, userId, userPhoneNumber));
|
||||||
}))
|
}))
|
||||||
.flatMap(session -> {
|
.flatMap(session -> {
|
||||||
@@ -398,8 +398,7 @@ public class ConversationManagerService {
|
|||||||
}
|
}
|
||||||
if (resolvedUserId == null || resolvedUserId.trim().isEmpty()) {
|
if (resolvedUserId == null || resolvedUserId.trim().isEmpty()) {
|
||||||
resolvedUserId = "user_by_phone_" + primaryPhoneNumber.replaceAll("[^0-9]", "");
|
resolvedUserId = "user_by_phone_" + primaryPhoneNumber.replaceAll("[^0-9]", "");
|
||||||
logger.warn("User ID not provided in query parameters. Using derived ID from phone number: {}",
|
logger.warn("User ID not provided in query parameters. Using derived ID from phone number");
|
||||||
resolvedUserId);
|
|
||||||
}
|
}
|
||||||
if (request.queryInput() == null || request.queryInput().text() == null ||
|
if (request.queryInput() == null || request.queryInput().text() == null ||
|
||||||
request.queryInput().text().text() == null || request.queryInput().text().text().trim().isEmpty()) {
|
request.queryInput().text().text() == null || request.queryInput().text().text().trim().isEmpty()) {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public class NotificationManagerService {
|
|||||||
obfuscatedRequest.text(), eventName, defaultLanguageCode, parameters, "active");
|
obfuscatedRequest.text(), eventName, defaultLanguageCode, parameters, "active");
|
||||||
Mono<Void> persistenceMono = memoryStoreNotificationService.saveOrAppendNotificationEntry(newNotificationEntry)
|
Mono<Void> persistenceMono = memoryStoreNotificationService.saveOrAppendNotificationEntry(newNotificationEntry)
|
||||||
.doOnSuccess(v -> {
|
.doOnSuccess(v -> {
|
||||||
logger.info("Notification for phone {} cached. Kicking off async Firestore write-back.", telefono);
|
logger.info("Notification for phone cached. Kicking off async Firestore write-back.");
|
||||||
firestoreNotificationService.saveOrAppendNotificationEntry(newNotificationEntry)
|
firestoreNotificationService.saveOrAppendNotificationEntry(newNotificationEntry)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
ignored -> logger.debug(
|
ignored -> logger.debug(
|
||||||
@@ -100,8 +100,8 @@ public class NotificationManagerService {
|
|||||||
|
|
||||||
// 2. Resolve or create a conversation session
|
// 2. Resolve or create a conversation session
|
||||||
Mono<ConversationSessionDTO> sessionMono = memoryStoreNotificationService.getSessionByTelefono(telefono)
|
Mono<ConversationSessionDTO> sessionMono = memoryStoreNotificationService.getSessionByTelefono(telefono)
|
||||||
.doOnNext(session -> logger.info("Found existing conversation session {} for phone number {}",
|
.doOnNext(session -> logger.info("Found existing conversation session {} for phone number",
|
||||||
session.sessionId(), telefono))
|
session.sessionId()))
|
||||||
.flatMap(session -> {
|
.flatMap(session -> {
|
||||||
Map<String, Object> prefixedParameters = new HashMap<>();
|
Map<String, Object> prefixedParameters = new HashMap<>();
|
||||||
if (obfuscatedRequest.hiddenParameters() != null) {
|
if (obfuscatedRequest.hiddenParameters() != null) {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class MemoryStoreQRService {
|
|||||||
})
|
})
|
||||||
.doOnSuccess(session -> {
|
.doOnSuccess(session -> {
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
logger.info("Successfully retrieved quick reply session {} by phone number",
|
logger.info("Successfully retrieved quick reply session {}",
|
||||||
session.sessionId());
|
session.sessionId());
|
||||||
} else {
|
} else {
|
||||||
logger.info("No quick reply session found in Redis for phone number");
|
logger.info("No quick reply session found in Redis for phone number");
|
||||||
|
|||||||
@@ -46,7 +46,12 @@ public class TextObfuscator {
|
|||||||
textToInspect = textToInspect.replace(quote, "[TELEFONO]");
|
textToInspect = textToInspect.replace(quote, "[TELEFONO]");
|
||||||
break;
|
break;
|
||||||
case "DIRECCION":
|
case "DIRECCION":
|
||||||
case "STREET_ADDRESS":
|
case "DIR_COLONIA":
|
||||||
|
case "DIR_DEL_MUN":
|
||||||
|
case "DIR_INTERIOR":
|
||||||
|
case "DIR_ESQUINA":
|
||||||
|
case "DIR_CIUDAD_EDO":
|
||||||
|
case "DIR_CP":
|
||||||
textToInspect = textToInspect.replace(quote, "[DIRECCION]");
|
textToInspect = textToInspect.replace(quote, "[DIRECCION]");
|
||||||
break;
|
break;
|
||||||
case "CLABE_INTERBANCARIA":
|
case "CLABE_INTERBANCARIA":
|
||||||
@@ -69,6 +74,7 @@ public class TextObfuscator {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
textToInspect = cleanDireccion(textToInspect);
|
||||||
return textToInspect;
|
return textToInspect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,4 +85,9 @@ public class TextObfuscator {
|
|||||||
cleanQuote.getChars(cleanQuote.length() - 4, cleanQuote.length(), last4, 0);
|
cleanQuote.getChars(cleanQuote.length() - 4, cleanQuote.length(), last4, 0);
|
||||||
return new String(last4);
|
return new String(last4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String cleanDireccion(String quote) {
|
||||||
|
String output = quote.replaceAll("\\[DIRECCION\\](?:(?:,\\s*|\\s+)\\[DIRECCION\\])*", "[DIRECCION]");
|
||||||
|
return output.trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user