diff --git a/src/main/java/com/example/service/base/MessageEntryFilter.java b/src/main/java/com/example/service/base/MessageEntryFilter.java index d55bc49..7d887b7 100644 --- a/src/main/java/com/example/service/base/MessageEntryFilter.java +++ b/src/main/java/com/example/service/base/MessageEntryFilter.java @@ -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; } }; diff --git a/src/main/java/com/example/service/base/NotificationContextResolver.java b/src/main/java/com/example/service/base/NotificationContextResolver.java index ac9c198..c6fa4d2 100644 --- a/src/main/java/com/example/service/base/NotificationContextResolver.java +++ b/src/main/java/com/example/service/base/NotificationContextResolver.java @@ -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) { diff --git a/src/main/java/com/example/service/conversation/ConversationManagerService.java b/src/main/java/com/example/service/conversation/ConversationManagerService.java index d04236d..92994ac 100644 --- a/src/main/java/com/example/service/conversation/ConversationManagerService.java +++ b/src/main/java/com/example/service/conversation/ConversationManagerService.java @@ -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()) { diff --git a/src/main/java/com/example/service/notification/NotificationManagerService.java b/src/main/java/com/example/service/notification/NotificationManagerService.java index efe192c..2450c4f 100644 --- a/src/main/java/com/example/service/notification/NotificationManagerService.java +++ b/src/main/java/com/example/service/notification/NotificationManagerService.java @@ -89,7 +89,7 @@ public class NotificationManagerService { obfuscatedRequest.text(), eventName, defaultLanguageCode, parameters, "active"); Mono 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 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 prefixedParameters = new HashMap<>(); if (obfuscatedRequest.hiddenParameters() != null) { diff --git a/src/main/java/com/example/service/quickreplies/MemoryStoreQRService.java b/src/main/java/com/example/service/quickreplies/MemoryStoreQRService.java index 49836ab..8398495 100644 --- a/src/main/java/com/example/service/quickreplies/MemoryStoreQRService.java +++ b/src/main/java/com/example/service/quickreplies/MemoryStoreQRService.java @@ -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"); diff --git a/src/main/java/com/example/util/TextObfuscator.java b/src/main/java/com/example/util/TextObfuscator.java index a402251..05a447c 100644 --- a/src/main/java/com/example/util/TextObfuscator.java +++ b/src/main/java/com/example/util/TextObfuscator.java @@ -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(); + } }