UPDATE 22-sept

This commit is contained in:
PAVEL PALMA
2025-09-22 11:51:44 -06:00
parent 6120b8d6c2
commit 7abf774d95
6 changed files with 29 additions and 21 deletions

View File

@@ -89,7 +89,7 @@ public class MessageEntryFilter {
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)));
try {
@@ -103,18 +103,16 @@ public class MessageEntryFilter {
String resultCategory = switch (geminiResponse != null ? geminiResponse.trim().toUpperCase() : "") {
case CATEGORY_CONVERSATION -> {
logger.info("Classified as {}. Input: '{}'", CATEGORY_CONVERSATION);
logger.debug("Classified as {}. Input: '{}'", CATEGORY_CONVERSATION, queryInputText);
logger.info("Classified as {}.", CATEGORY_CONVERSATION);
yield CATEGORY_CONVERSATION;
}
case CATEGORY_NOTIFICATION -> {
logger.info("Classified as {}. Input: '{}'", CATEGORY_NOTIFICATION);
logger.debug("Classified as {}. Input: '{}'", CATEGORY_NOTIFICATION, queryInputText);
logger.info("Classified as {}.", CATEGORY_NOTIFICATION);
yield CATEGORY_NOTIFICATION;
}
default -> {
logger.warn("Gemini returned an unrecognised classification or was null/blank: '{}'. Expected '{}' or '{}'. Input: '{}'. Returning {}.",
geminiResponse, CATEGORY_CONVERSATION, CATEGORY_NOTIFICATION, queryInputText, CATEGORY_UNKNOWN);
logger.warn("Gemini returned an unrecognised classification or was null/blank: '{}'. Expected '{}' or '{}'. Returning {}.",
geminiResponse, CATEGORY_CONVERSATION, CATEGORY_NOTIFICATION, CATEGORY_UNKNOWN);
yield CATEGORY_UNKNOWN;
}
};

View File

@@ -96,15 +96,15 @@ public class NotificationContextResolver {
if (geminiResponse != null && !geminiResponse.isBlank()) {
if (geminiResponse.trim().equalsIgnoreCase(CATEGORY_DIALOGFLOW)) {
logger.info("Resolved to {}. Input: '{}'", CATEGORY_DIALOGFLOW, queryInputText);
logger.info("Resolved to {}.", CATEGORY_DIALOGFLOW);
return CATEGORY_DIALOGFLOW;
} else {
logger.info("Resolved to a specific response. Input: '{}'", queryInputText);
logger.info("Resolved to a specific response.");
return geminiResponse;
}
} else {
logger.warn("Gemini returned a null or blank response. Input: '{}'. Returning {}.",
queryInputText, CATEGORY_DIALOGFLOW);
logger.warn("Gemini returned a null or blank response. Returning {}.",
CATEGORY_DIALOGFLOW);
return CATEGORY_DIALOGFLOW;
}
} catch (Exception e) {

View File

@@ -171,7 +171,7 @@ public class ConversationManagerService {
.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)
.flatMap(session -> handleMessageClassification(context, request, session))
.switchIfEmpty(Mono.defer(() -> {
@@ -283,8 +283,8 @@ public class ConversationManagerService {
return memoryStoreNotificationService.getSessionByTelefono(userPhoneNumber)
.switchIfEmpty(Mono.defer(() -> {
String newSessionId = SessionIdGenerator.generateStandardSessionId();
logger.info("No existing notification session found for phone number {}. Creating new session: {}",
userPhoneNumber, newSessionId);
logger.info("No existing notification session found for phone number. Creating new session: {}",
newSessionId);
return Mono.just(ConversationSessionDTO.create(newSessionId, userId, userPhoneNumber));
}))
.flatMap(session -> {
@@ -398,8 +398,7 @@ public class ConversationManagerService {
}
if (resolvedUserId == null || resolvedUserId.trim().isEmpty()) {
resolvedUserId = "user_by_phone_" + primaryPhoneNumber.replaceAll("[^0-9]", "");
logger.warn("User ID not provided in query parameters. Using derived ID from phone number: {}",
resolvedUserId);
logger.warn("User ID not provided in query parameters. Using derived ID from phone number");
}
if (request.queryInput() == null || request.queryInput().text() == null ||
request.queryInput().text().text() == null || request.queryInput().text().text().trim().isEmpty()) {

View File

@@ -89,7 +89,7 @@ public class NotificationManagerService {
obfuscatedRequest.text(), eventName, defaultLanguageCode, parameters, "active");
Mono<Void> persistenceMono = memoryStoreNotificationService.saveOrAppendNotificationEntry(newNotificationEntry)
.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)
.subscribe(
ignored -> logger.debug(
@@ -100,8 +100,8 @@ public class NotificationManagerService {
// 2. Resolve or create a conversation session
Mono<ConversationSessionDTO> sessionMono = memoryStoreNotificationService.getSessionByTelefono(telefono)
.doOnNext(session -> logger.info("Found existing conversation session {} for phone number {}",
session.sessionId(), telefono))
.doOnNext(session -> logger.info("Found existing conversation session {} for phone number",
session.sessionId()))
.flatMap(session -> {
Map<String, Object> prefixedParameters = new HashMap<>();
if (obfuscatedRequest.hiddenParameters() != null) {

View File

@@ -76,7 +76,7 @@ public class MemoryStoreQRService {
})
.doOnSuccess(session -> {
if (session != null) {
logger.info("Successfully retrieved quick reply session {} by phone number",
logger.info("Successfully retrieved quick reply session {}",
session.sessionId());
} else {
logger.info("No quick reply session found in Redis for phone number");

View File

@@ -46,7 +46,12 @@ public class TextObfuscator {
textToInspect = textToInspect.replace(quote, "[TELEFONO]");
break;
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]");
break;
case "CLABE_INTERBANCARIA":
@@ -69,6 +74,7 @@ public class TextObfuscator {
break;
}
}
textToInspect = cleanDireccion(textToInspect);
return textToInspect;
}
@@ -79,4 +85,9 @@ public class TextObfuscator {
cleanQuote.getChars(cleanQuote.length() - 4, cleanQuote.length(), last4, 0);
return new String(last4);
}
private static String cleanDireccion(String quote) {
String output = quote.replaceAll("\\[DIRECCION\\](?:(?:,\\s*|\\s+)\\[DIRECCION\\])*", "[DIRECCION]");
return output.trim();
}
}