Initial commit

This commit is contained in:
PAVEL PALMA
2025-07-16 13:43:46 -06:00
parent 54cb86ab65
commit fac3550287
46 changed files with 2062 additions and 88 deletions

View File

@@ -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
);
}
}

View File

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

View File

@@ -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;
}
}

View File

@@ -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()
);
}
}

View File

@@ -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
) {}

View File

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

View File

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

View File

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

View File

@@ -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
) {}

View File

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