.
This commit is contained in:
@@ -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
|
||||
) {}
|
||||
Reference in New Issue
Block a user