.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.controller;
|
||||
|
||||
import com.example.dto.dialogflow.base.DetectIntentResponseDTO;
|
||||
import com.example.dto.dialogflow.conversation.ExternalConvRequestDTO;
|
||||
import com.example.mapper.conversation.ExternalConvRequestMapper;
|
||||
import com.example.service.conversation.ConversationManagerService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/dialogflow")
|
||||
public class ConversationController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConversationController.class);
|
||||
private final ConversationManagerService conversationManagerService;
|
||||
|
||||
public ConversationController(ConversationManagerService conversationManagerService,
|
||||
ExternalConvRequestMapper externalRequestToDialogflowMapper) {
|
||||
this.conversationManagerService = conversationManagerService;
|
||||
}
|
||||
|
||||
@PostMapping("/detect-intent")
|
||||
public Mono<DetectIntentResponseDTO> detectIntent(@Valid @RequestBody ExternalConvRequestDTO request) {
|
||||
return conversationManagerService.manageConversation(request)
|
||||
.doOnSuccess(response -> logger.info("Successfully processed direct Dialogflow request"))
|
||||
.doOnError(error -> logger.error("Error processing direct Dialogflow request: {}", error.getMessage(), error));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.example.controller;
|
||||
|
||||
import com.example.service.base.DataPurgeService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/data-purge")
|
||||
public class DataPurgeController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataPurgeController.class);
|
||||
private final DataPurgeService dataPurgeService;
|
||||
|
||||
public DataPurgeController(DataPurgeService dataPurgeService) {
|
||||
this.dataPurgeService = dataPurgeService;
|
||||
}
|
||||
|
||||
@DeleteMapping("/all")
|
||||
public Mono<Void> purgeAllData() {
|
||||
logger.warn("Received request to purge all data. This is a destructive operation.");
|
||||
return dataPurgeService.purgeAllData()
|
||||
.doOnSuccess(voidResult -> logger.info("Successfully purged all data."))
|
||||
.doOnError(error -> logger.error("Error purging all data.", error));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.controller;
|
||||
|
||||
import com.example.dto.llm.webhook.WebhookRequestDTO;
|
||||
import com.example.dto.llm.webhook.SessionInfoDTO;
|
||||
import com.example.dto.llm.webhook.WebhookResponseDTO;
|
||||
import com.example.service.llm.LlmResponseTunerService;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/llm")
|
||||
public class LlmResponseTunerController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LlmResponseTunerController.class);
|
||||
|
||||
private final LlmResponseTunerService llmResponseTunerService;
|
||||
|
||||
public LlmResponseTunerController(LlmResponseTunerService llmResponseTunerService) {
|
||||
this.llmResponseTunerService = llmResponseTunerService;
|
||||
}
|
||||
|
||||
@PostMapping("/tune-response")
|
||||
public Mono<WebhookResponseDTO> tuneResponse(@RequestBody WebhookRequestDTO request) {
|
||||
String uuid = (String) request.getSessionInfo().getParameters().get("uuid");
|
||||
return llmResponseTunerService
|
||||
.getValue(uuid)
|
||||
.map(
|
||||
value -> {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("webhook_success", true);
|
||||
parameters.put("response", value);
|
||||
SessionInfoDTO sessionInfo = new SessionInfoDTO(parameters);
|
||||
return new WebhookResponseDTO(sessionInfo);
|
||||
})
|
||||
.defaultIfEmpty(createErrorResponse("No response found for the given UUID.", false))
|
||||
.onErrorResume(
|
||||
e -> {
|
||||
logger.error("Error tuning response: {}", e.getMessage());
|
||||
return Mono.just(
|
||||
createErrorResponse("An internal error occurred.", true));
|
||||
});
|
||||
}
|
||||
|
||||
private WebhookResponseDTO createErrorResponse(String errorMessage, boolean isError) {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("webhook_success", false);
|
||||
parameters.put("error_message", errorMessage);
|
||||
SessionInfoDTO sessionInfo = new SessionInfoDTO(parameters);
|
||||
return new WebhookResponseDTO(sessionInfo);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<Map<String, String>> handleException(Exception e) {
|
||||
logger.error("An unexpected error occurred: {}", e.getMessage());
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("error", "Internal Server Error");
|
||||
response.put("message", "An unexpected error occurred. Please try again later.");
|
||||
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ExceptionHandler(IllegalArgumentException.class)
|
||||
public ResponseEntity<Map<String, String>> handleIllegalArgumentException(
|
||||
IllegalArgumentException e) {
|
||||
logger.error("Bad request: {}", e.getMessage());
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("error", "Bad Request");
|
||||
response.put("message", e.getMessage());
|
||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.controller;
|
||||
|
||||
import com.example.dto.dialogflow.notification.ExternalNotRequestDTO;
|
||||
import com.example.service.notification.NotificationManagerService;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/dialogflow")
|
||||
public class NotificationController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConversationController.class);
|
||||
private final NotificationManagerService notificationManagerService;
|
||||
|
||||
public NotificationController(NotificationManagerService notificationManagerService) {
|
||||
this.notificationManagerService = notificationManagerService;
|
||||
}
|
||||
|
||||
@PostMapping("/notification")
|
||||
public Mono<Void> processNotification(@Valid @RequestBody ExternalNotRequestDTO request) {
|
||||
return notificationManagerService.processNotification(request)
|
||||
.doOnSuccess(response -> logger.info("Successfully processed direct Dialogflow request"))
|
||||
.doOnError(error -> logger.error("Error processing direct Dialogflow request: {}", error.getMessage(), error))
|
||||
.then();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.controller;
|
||||
|
||||
import com.example.dto.dialogflow.base.DetectIntentResponseDTO;
|
||||
import com.example.dto.quickreplies.QuickReplyScreenRequestDTO;
|
||||
import com.example.service.quickreplies.QuickRepliesManagerService;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/quick-replies")
|
||||
public class QuickRepliesController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(QuickRepliesController.class);
|
||||
private final QuickRepliesManagerService quickRepliesManagerService;
|
||||
|
||||
public QuickRepliesController(QuickRepliesManagerService quickRepliesManagerService) {
|
||||
this.quickRepliesManagerService = quickRepliesManagerService;
|
||||
}
|
||||
|
||||
@PostMapping("/screen")
|
||||
public Mono<DetectIntentResponseDTO> startSessionAndGetReplies(@Valid @RequestBody QuickReplyScreenRequestDTO request) {
|
||||
return quickRepliesManagerService.startQuickReplySession(request)
|
||||
.doOnSuccess(response -> logger.info("Successfully processed quick reply request"))
|
||||
.doOnError(error -> logger.error("Error processing quick reply request: {}", error.getMessage(), error));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user