.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
public DetectIntentRequestDTO withParameters(java.util.Map<String, Object> parameters) {
|
||||
// Create a new QueryParamsDTO with the updated session parameters
|
||||
QueryParamsDTO updatedQueryParams = this.queryParams().withSessionParameters(parameters);
|
||||
|
||||
// Return a new DetectIntentRequestDTO instance with the updated QueryParamsDTO
|
||||
return new DetectIntentRequestDTO(
|
||||
this.queryInput(),
|
||||
updatedQueryParams
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.example.dto.quickreplies.QuickReplyDTO;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record DetectIntentResponseDTO(
|
||||
@JsonProperty("responseId") String responseId,
|
||||
@JsonProperty("queryResult") QueryResultDTO queryResult,
|
||||
@JsonProperty("quick_replies") QuickReplyDTO quickReplies
|
||||
) {
|
||||
public DetectIntentResponseDTO(String responseId, QueryResultDTO queryResult) {
|
||||
this(responseId, queryResult, null);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
) {}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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 forUser(String text, Map<String, Object> parameters) {
|
||||
return new ConversationEntryDTO(
|
||||
ConversationEntryEntity.USUARIO,
|
||||
ConversationEntryType.CONVERSACION,
|
||||
Instant.now(),
|
||||
text,
|
||||
parameters,
|
||||
null);
|
||||
}
|
||||
|
||||
public static ConversationEntryDTO forAgent(QueryResultDTO agentQueryResult) {
|
||||
String fulfillmentText = (agentQueryResult != null && agentQueryResult.responseText() != null) ? agentQueryResult.responseText() : "";
|
||||
Map<String, Object> parameters = (agentQueryResult != null) ? agentQueryResult.parameters() : null;
|
||||
|
||||
return new ConversationEntryDTO(
|
||||
ConversationEntryEntity.AGENTE,
|
||||
ConversationEntryType.CONVERSACION,
|
||||
Instant.now(),
|
||||
fulfillmentText,
|
||||
parameters,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static ConversationEntryDTO forAgentWithMessage(String text) {
|
||||
return new ConversationEntryDTO(
|
||||
ConversationEntryEntity.AGENTE,
|
||||
ConversationEntryType.CONVERSACION,
|
||||
Instant.now(),
|
||||
text,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
public static ConversationEntryDTO forSystem(String text) {
|
||||
return new ConversationEntryDTO(
|
||||
ConversationEntryEntity.SISTEMA,
|
||||
ConversationEntryType.CONVERSACION,
|
||||
Instant.now(),
|
||||
text,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ConversationEntryDTO forSystem(String text, Map<String, Object> parameters) {
|
||||
return new ConversationEntryDTO(
|
||||
ConversationEntryEntity.SISTEMA,
|
||||
ConversationEntryType.CONVERSACION,
|
||||
Instant.now(),
|
||||
text,
|
||||
parameters,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static ConversationEntryDTO forLlmConversation(String text) {
|
||||
return new ConversationEntryDTO(
|
||||
ConversationEntryEntity.LLM,
|
||||
ConversationEntryType.CONVERSACION,
|
||||
Instant.now(),
|
||||
text,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static ConversationEntryDTO forLlmConversation(String text, Map<String, Object> parameters) {
|
||||
return new ConversationEntryDTO(
|
||||
ConversationEntryEntity.LLM,
|
||||
ConversationEntryType.CONVERSACION,
|
||||
Instant.now(),
|
||||
text,
|
||||
parameters,
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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 enum ConversationEntryEntity {
|
||||
USUARIO,
|
||||
AGENTE,
|
||||
SISTEMA,
|
||||
LLM
|
||||
}
|
||||
@@ -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 ConversationEntryType {
|
||||
INICIO,
|
||||
CONVERSACION,
|
||||
LLM
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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 ConversationMessageDTO(
|
||||
MessageType type,
|
||||
Instant timestamp,
|
||||
String text,
|
||||
Map<String, Object> parameters,
|
||||
String canal
|
||||
) {
|
||||
}
|
||||
@@ -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.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import java.time.Instant;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record ConversationSessionDTO(
|
||||
String sessionId,
|
||||
String userId,
|
||||
String telefono,
|
||||
Instant createdAt,
|
||||
Instant lastModified,
|
||||
String lastMessage,
|
||||
String pantallaContexto
|
||||
) {
|
||||
public ConversationSessionDTO(String sessionId, String userId, String telefono, Instant createdAt, Instant lastModified, String lastMessage, String pantallaContexto) {
|
||||
this.sessionId = sessionId;
|
||||
this.userId = userId;
|
||||
this.telefono = telefono;
|
||||
this.createdAt = createdAt;
|
||||
this.lastModified = lastModified;
|
||||
this.lastMessage = lastMessage;
|
||||
this.pantallaContexto = pantallaContexto;
|
||||
}
|
||||
|
||||
public static ConversationSessionDTO create(String sessionId, String userId, String telefono) {
|
||||
Instant now = Instant.now();
|
||||
return new ConversationSessionDTO(sessionId, userId, telefono, now, now, null, null);
|
||||
}
|
||||
|
||||
public ConversationSessionDTO withLastMessage(String lastMessage) {
|
||||
return new ConversationSessionDTO(this.sessionId, this.userId, this.telefono, this.createdAt, Instant.now(), lastMessage, this.pantallaContexto);
|
||||
}
|
||||
|
||||
public ConversationSessionDTO withTelefono(String newTelefono) {
|
||||
if (newTelefono != null && !newTelefono.equals(this.telefono)) {
|
||||
return new ConversationSessionDTO(this.sessionId, this.userId, newTelefono, this.createdAt, this.lastModified, this.lastMessage, this.pantallaContexto);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConversationSessionDTO withPantallaContexto(String pantallaContexto) {
|
||||
return new ConversationSessionDTO(this.sessionId, this.userId, this.telefono, this.createdAt, this.lastModified, this.lastMessage, pantallaContexto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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,
|
||||
@JsonProperty("pantallaContexto") String pantallaContexto //optional field for quick-replies
|
||||
) {
|
||||
public ExternalConvRequestDTO {}
|
||||
}
|
||||
@@ -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 enum MessageType {
|
||||
USER,
|
||||
AGENT,
|
||||
SYSTEM,
|
||||
LLM
|
||||
}
|
||||
@@ -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.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
|
||||
) {}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
public QueryParamsDTO withSessionParameters(Map<String, Object> parameters) {
|
||||
Map<String, Object> updatedParams = new HashMap<>(this.parameters());
|
||||
updatedParams.putAll(parameters);
|
||||
return new QueryParamsDTO(updatedParams);
|
||||
}
|
||||
}
|
||||
@@ -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 java.util.Map;
|
||||
|
||||
public record QueryResultDTO(
|
||||
@JsonProperty("responseText") String responseText,
|
||||
@JsonProperty("parameters") Map<String, Object> parameters
|
||||
) {}
|
||||
@@ -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) {}
|
||||
@@ -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
|
||||
) {}
|
||||
@@ -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
|
||||
) {}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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,
|
||||
@JsonProperty("parametrosOcultos") java.util.Map<String, String> hiddenParameters
|
||||
) {
|
||||
public ExternalNotRequestDTO {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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
|
||||
String status
|
||||
) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user