UPDATE 12-ago-2025

This commit is contained in:
PAVEL PALMA
2025-08-12 16:09:32 -06:00
parent 55fcf3b7d6
commit 849095374f
74 changed files with 2656 additions and 669 deletions

View File

@@ -1,35 +0,0 @@
package com.example.dto.dialogflow;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.time.Instant;
import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_NULL)
public record ConversationEntryDTO(
ConversationEntryType type,
Instant timestamp,
String text,
String intentDisplayName,
Map<String, Object> parameters,
String webhookStatus,
String canal
) {
public static ConversationEntryDTO forUser(String text) {
return new ConversationEntryDTO(ConversationEntryType.USER_MESSAGE, Instant.now(),
text, null, null, null, null);
}
public static ConversationEntryDTO forAgent(QueryResultDTO agentQueryResult) {
String fulfillmentText = (agentQueryResult != null && agentQueryResult.responseText() != null) ? agentQueryResult.responseText() : "";
return new ConversationEntryDTO(
ConversationEntryType.AGENT_RESPONSE,
Instant.now(),
fulfillmentText,
null,
agentQueryResult.parameters(),
null,
null
);
}
}

View File

@@ -1,6 +0,0 @@
package com.example.dto.dialogflow;
public enum ConversationEntryType {
USER_MESSAGE,
AGENT_RESPONSE
}

View File

@@ -1,25 +0,0 @@
package com.example.dto.dialogflow;
import com.example.dto.base.UsuarioDTO;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public record DetectIntentRequestDTO(
@JsonProperty("session") String sessionId,
@JsonProperty("queryInput") QueryInputDTO queryInput,
@JsonProperty("queryParams") QueryParamsDTO queryParams,
@JsonProperty("usuario") UsuarioDTO usuario,
String userId
) {
public DetectIntentRequestDTO withSessionId(String newSessionId) {
return new DetectIntentRequestDTO(
newSessionId,
this.queryInput(),
this.queryParams(),
this.usuario(),
this.userId()
);
}
}

View File

@@ -1,8 +0,0 @@
package com.example.dto.dialogflow;
import com.fasterxml.jackson.annotation.JsonProperty;
public record DetectIntentResponseDTO(
@JsonProperty("responseId") String responseId,
@JsonProperty("queryResult") QueryResultDTO queryResult
) {}

View File

@@ -1,6 +0,0 @@
package com.example.dto.dialogflow;
public record IntentDTO(
String name,
String displayName
) {}

View File

@@ -1,3 +0,0 @@
package com.example.dto.dialogflow;
public record QueryInputDTO(TextInputDTO text, String languageCode) {}

View File

@@ -1,4 +0,0 @@
package com.example.dto.dialogflow;
import java.util.Map;
public record QueryParamsDTO(Map<String, Object> parameters) {}

View File

@@ -1,3 +0,0 @@
package com.example.dto.dialogflow;
public record TextInputDTO(String text) {}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.base;
import com.example.dto.dialogflow.conversation.QueryInputDTO;
import com.example.dto.dialogflow.conversation.QueryParamsDTO;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public record DetectIntentRequestDTO(
@JsonProperty("queryInput") QueryInputDTO queryInput,
@JsonProperty("queryParams") QueryParamsDTO queryParams
) {
public DetectIntentRequestDTO withParameter(String key, Object value) {
// Create a new QueryParamsDTO with the updated session parameter
QueryParamsDTO updatedQueryParams = this.queryParams().withSessionParameter(key, value);
// Return a new DetectIntentRequestDTO instance with the updated QueryParamsDTO
return new DetectIntentRequestDTO(
this.queryInput(),
updatedQueryParams
);
}
}

View File

@@ -0,0 +1,14 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.base;
import com.example.dto.dialogflow.conversation.QueryResultDTO;
import com.fasterxml.jackson.annotation.JsonProperty;
public record DetectIntentResponseDTO(
@JsonProperty("responseId") String responseId,
@JsonProperty("queryResult") QueryResultDTO queryResult
) {}

View File

@@ -0,0 +1,13 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
public record ConversationContext(
String userId,
String sessionId,
String userMessageText,
String primaryPhoneNumber
) {}

View File

@@ -0,0 +1,53 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.time.Instant;
import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_NULL)
public record ConversationEntryDTO(
ConversationEntryEntity entity,
ConversationEntryType type,
Instant timestamp,
String text,
Map<String, Object> parameters,
String canal
) {
public static ConversationEntryDTO forUser(String text) {
return new ConversationEntryDTO(
ConversationEntryEntity.USUARIO,
ConversationEntryType.CONVERSACION,
Instant.now(),
text,
null,
null);
}
public static ConversationEntryDTO forAgent(QueryResultDTO agentQueryResult) {
String fulfillmentText = (agentQueryResult != null && agentQueryResult.responseText() != null) ? agentQueryResult.responseText() : "";
return new ConversationEntryDTO(
ConversationEntryEntity.AGENTE,
ConversationEntryType.CONVERSACION,
Instant.now(),
fulfillmentText,
agentQueryResult.parameters(),
null
);
}
public static ConversationEntryDTO forSystem(String text) {
return new ConversationEntryDTO(
ConversationEntryEntity.SISTEMA,
ConversationEntryType.CONVERSACION,
Instant.now(),
text,
null,
null
);
}
}

View File

@@ -0,0 +1,12 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
public enum ConversationEntryEntity {
USUARIO,
AGENTE,
SISTEMA
}

View File

@@ -0,0 +1,11 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
public enum ConversationEntryType {
INICIO,
CONVERSACION
}

View File

@@ -1,4 +1,9 @@
package com.example.dto.dialogflow;
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.time.Instant;

View File

@@ -0,0 +1,19 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public record ExternalConvRequestDTO(
@JsonProperty("mensaje") String message,
@JsonProperty("usuario") UsuarioDTO user,
@JsonProperty("canal") String channel,
@JsonProperty("tipo") ConversationEntryType tipo
) {
public ExternalConvRequestDTO {}
}

View File

@@ -0,0 +1,14 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
import com.example.dto.dialogflow.notification.EventInputDTO;
public record QueryInputDTO(
TextInputDTO text, // Can be null if using event
EventInputDTO event,
String languageCode // REQUIRED for both text and event inputs
) {}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@JsonIgnoreProperties(ignoreUnknown = true)
public record QueryParamsDTO(
@JsonProperty("parameters") Map<String, Object> parameters) {
public QueryParamsDTO {
parameters = Objects.requireNonNullElseGet(parameters, HashMap::new);
parameters = new HashMap<>(parameters);
}
public QueryParamsDTO withSessionParameter(String key, Object value) {
Map<String, Object> updatedParams = new HashMap<>(this.parameters());
updatedParams.put(key, value);
return new QueryParamsDTO(updatedParams);
}
}

View File

@@ -1,4 +1,9 @@
package com.example.dto.dialogflow;
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;

View File

@@ -0,0 +1,8 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
public record TextInputDTO(String text) {}

View File

@@ -0,0 +1,14 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.conversation;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
public record UsuarioDTO(
@JsonProperty("telefono") @NotBlank String telefono,
@JsonProperty("nickname") String nickname
) {}

View File

@@ -0,0 +1,10 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.notification;
public record EventInputDTO(
String event
) {}

View File

@@ -0,0 +1,16 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.notification;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public record ExternalNotRequestDTO(
@JsonProperty("texto") String text,
@JsonProperty("telefono") String phoneNumber) {
public ExternalNotRequestDTO {
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose.
* Your use of it is subject to your agreement with Google.
*/
package com.example.dto.dialogflow.notification;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.time.Instant;
import java.util.Map;
import java.util.Objects;
/**
* Represents a notification record to be stored in Firestore and cached in
* Redis.
*/
@JsonIgnoreProperties(ignoreUnknown = true) // Ignorar campos adicionales durante la deserialización
public record NotificationDTO(
String idNotificacion, // ID único para esta notificación (ej. el sessionId usado con Dialogflow)
String telefono,
Instant timestampCreacion, // Momento en que la notificación fue procesada
String texto, // 'texto' original de NotificationRequestDTO (si aplica)
String nombreEventoDialogflow, // Nombre del evento enviado a Dialogflow (ej. "tu Estado de cuenta listo")
String codigoIdiomaDialogflow, // Código de idioma usado para el evento
Map<String, Object> parametros // Parámetros de sesión finales después del procesamiento de// Dialogflow
) {
public NotificationDTO {
Objects.requireNonNull(idNotificacion, "Notification ID cannot be null.");
Objects.requireNonNull(timestampCreacion, "Notification timestamp cannot be null.");
Objects.requireNonNull(nombreEventoDialogflow, "Dialogflow event name cannot be null.");
Objects.requireNonNull(codigoIdiomaDialogflow, "Dialogflow language code cannot be null.");
}
}

View File

@@ -0,0 +1,24 @@
// src/main/java/com/example/dto/dialogflow/notification/NotificationSessionDTO.java
package com.example.dto.dialogflow.notification;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
@JsonIgnoreProperties(ignoreUnknown = true)
public record NotificationSessionDTO(
String sessionId, // The unique session identifier (e.g., the phone number)
String telefono, // The phone number for this session
Instant fechaCreacion, // When the session was first created
Instant ultimaActualizacion, // When the session was last updated
List<NotificationDTO> notificaciones // List of individual notification events
) {
public NotificationSessionDTO {
Objects.requireNonNull(sessionId, "Session ID cannot be null.");
Objects.requireNonNull(telefono, "Phone number cannot be null.");
Objects.requireNonNull(fechaCreacion, "Creation timestamp cannot be null.");
Objects.requireNonNull(ultimaActualizacion, "Last updated timestamp cannot be null.");
Objects.requireNonNull(notificaciones, "Notifications list cannot be null.");
}
}