Initial commit
This commit is contained in:
17
src/main/java/com/example/dto/base/BaseRequest.java
Normal file
17
src/main/java/com/example/dto/base/BaseRequest.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.example.dto.base;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.PROPERTY,
|
||||
property = "type"
|
||||
)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = NotificationRequest.class, name = "NOTIFICATION"),
|
||||
})
|
||||
public sealed interface BaseRequest
|
||||
permits NotificationRequest{
|
||||
String type();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.dto.base;
|
||||
|
||||
public record ConversationContext(
|
||||
String userId,
|
||||
String sessionId,
|
||||
String userMessageText,
|
||||
String primaryPhoneNumber
|
||||
) {}
|
||||
26
src/main/java/com/example/dto/base/NotificationRequest.java
Normal file
26
src/main/java/com/example/dto/base/NotificationRequest.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.example.dto.base;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record NotificationRequest(
|
||||
@JsonProperty("requestId") String requestId,
|
||||
@JsonProperty("sessionId") String sessionId,
|
||||
@JsonProperty("mensaje") String message,
|
||||
@JsonProperty("SIC") String SIC,
|
||||
@Valid Usuario usuario,
|
||||
@JsonProperty("pantalla_contexto") String pantallaContexto,
|
||||
@JsonProperty("canal") String canal
|
||||
) implements BaseRequest {
|
||||
@Override
|
||||
public String type() {
|
||||
return "NOTIFICATION";
|
||||
}
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record Usuario(
|
||||
String telefono,
|
||||
String nickname
|
||||
) {
|
||||
}
|
||||
}
|
||||
9
src/main/java/com/example/dto/base/UsuarioDTO.java
Normal file
9
src/main/java/com/example/dto/base/UsuarioDTO.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.example.dto.base;
|
||||
|
||||
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,35 @@
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
public enum ConversationEntryType {
|
||||
USER_MESSAGE,
|
||||
AGENT_RESPONSE
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ConversationSessionDTO(
|
||||
String sessionId,
|
||||
String userId,
|
||||
String telefono,
|
||||
Instant createdAt,
|
||||
Instant lastModified,
|
||||
List<ConversationEntryDTO> entries
|
||||
) {
|
||||
public ConversationSessionDTO(String sessionId, String userId, String telefono, Instant createdAt, Instant lastModified, List<ConversationEntryDTO> entries) {
|
||||
this.sessionId = sessionId;
|
||||
this.userId = userId;
|
||||
this.telefono = telefono;
|
||||
this.createdAt = createdAt;
|
||||
this.lastModified = lastModified;
|
||||
this.entries = Collections.unmodifiableList(new ArrayList<>(entries));
|
||||
}
|
||||
|
||||
public static ConversationSessionDTO create(String sessionId, String userId, String telefono) {
|
||||
Instant now = Instant.now();
|
||||
return new ConversationSessionDTO(sessionId, userId, telefono, now, now, Collections.emptyList());
|
||||
}
|
||||
|
||||
public ConversationSessionDTO withAddedEntry(ConversationEntryDTO newEntry) {
|
||||
List<ConversationEntryDTO> updatedEntries = new ArrayList<>(this.entries);
|
||||
updatedEntries.add(newEntry);
|
||||
return new ConversationSessionDTO(this.sessionId, this.userId, this.telefono, this.createdAt, Instant.now(), updatedEntries);
|
||||
}
|
||||
|
||||
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.entries);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public record DetectIntentResponseDTO(
|
||||
@JsonProperty("responseId") String responseId,
|
||||
@JsonProperty("queryResult") QueryResultDTO queryResult
|
||||
) {}
|
||||
6
src/main/java/com/example/dto/dialogflow/IntentDTO.java
Normal file
6
src/main/java/com/example/dto/dialogflow/IntentDTO.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
public record IntentDTO(
|
||||
String name,
|
||||
String displayName
|
||||
) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
public record QueryInputDTO(TextInputDTO text, String languageCode) {}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
import java.util.Map;
|
||||
public record QueryParamsDTO(Map<String, Object> parameters) {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
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,3 @@
|
||||
package com.example.dto.dialogflow;
|
||||
|
||||
public record TextInputDTO(String text) {}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.example.dto.gemini;
|
||||
|
||||
import com.example.dto.dialogflow.ConversationEntryType;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.cloud.Timestamp;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record ConversationEntrySummaryDTO(
|
||||
@JsonProperty("text") String text,
|
||||
@JsonProperty("timestamp") Timestamp timestamp,
|
||||
Optional<ConversationEntryType> type,
|
||||
@JsonProperty("intentDisplayName") String intentDisplayName,
|
||||
@JsonProperty("parameters") Map<String, Object> parameters,
|
||||
@JsonProperty("webhookStatus") String webhookStatus,
|
||||
@JsonProperty("canal") String canal
|
||||
) {
|
||||
@JsonCreator
|
||||
public ConversationEntrySummaryDTO(
|
||||
@JsonProperty("text") String text,
|
||||
@JsonProperty("timestamp") Timestamp timestamp,
|
||||
@JsonProperty("type") String typeString,
|
||||
@JsonProperty("intentDisplayName") String intentDisplayName,
|
||||
@JsonProperty("parameters") Map<String, Object> parameters,
|
||||
@JsonProperty("webhookStatus") String webhookStatus,
|
||||
@JsonProperty("canal") String canal
|
||||
) {
|
||||
this(
|
||||
text,
|
||||
timestamp,
|
||||
Optional.ofNullable(typeString).map(t -> {
|
||||
try {
|
||||
return ConversationEntryType.valueOf(t);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.println("Warning: Invalid ConversationEntryType string during deserialization: " + t);
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
intentDisplayName,
|
||||
parameters,
|
||||
webhookStatus,
|
||||
canal
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.dto.gemini;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.cloud.Timestamp;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record ConversationSessionSummaryDTO(
|
||||
@JsonProperty("sessionId") String sessionId,
|
||||
@JsonProperty("userId") String userId,
|
||||
@JsonProperty("startTime") Timestamp startTime,
|
||||
@JsonProperty("lastUpdated") Timestamp lastUpdated,
|
||||
@JsonProperty("entries") List<ConversationEntrySummaryDTO> entries
|
||||
) {
|
||||
@JsonCreator
|
||||
public ConversationSessionSummaryDTO(
|
||||
@JsonProperty("sessionId") String sessionId,
|
||||
@JsonProperty("userId") String userId,
|
||||
@JsonProperty("startTime") Timestamp startTime,
|
||||
@JsonProperty("lastUpdated") Timestamp lastUpdated,
|
||||
@JsonProperty("entries") List<ConversationEntrySummaryDTO> entries
|
||||
) {
|
||||
this.sessionId = sessionId;
|
||||
this.userId = userId;
|
||||
this.startTime = startTime;
|
||||
this.lastUpdated = lastUpdated;
|
||||
this.entries = entries != null ? entries : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.example.dto.gemini;
|
||||
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record ConversationSummaryRequest(
|
||||
@NotBlank(message = "Session ID is required.")
|
||||
String sessionId,
|
||||
@NotBlank(message = "Prompt for summarization is required.")
|
||||
String prompt,
|
||||
@Min(value = 0, message = "Temperature must be between 0.0 and 1.0.")
|
||||
@Max(value = 1, message = "Temperature must be between 0.0 and 1.0.")
|
||||
Float temperature,
|
||||
@Min(value = 1, message = "Max Output Tokens must be at least 1.")
|
||||
Integer maxOutputTokens,
|
||||
@NotBlank(message = "model is required.")
|
||||
String modelName
|
||||
) {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.dto.gemini;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public record ConversationSummaryResponse(
|
||||
@NotBlank
|
||||
String summaryText
|
||||
) {}
|
||||
Reference in New Issue
Block a user