0

I set it up according to the manual of Google cloud and brought the sample code from the repository. If I write a body with postman and send a request, I can get a response, but when I use the chatbot, neither body nor parameters are delivered.

@RestController
@RequiredArgsConstructor
public class DialogController {
    private final GsonFactory gsonFactory;

    @PostMapping("/api/dialog")
    public ResponseEntity<?> dialogFlowWebHook(@RequestBody String requestStr, HttpServletRequest servletRequest) throws IOException {
        try {

            GoogleCloudDialogflowV2WebhookResponse response = new GoogleCloudDialogflowV2WebhookResponse();
            GoogleCloudDialogflowV2WebhookRequest request = gsonFactory.createJsonParser(requestStr).parse(GoogleCloudDialogflowV2WebhookRequest.class);

            Map<String, Object> params = request.getQueryResult().getParameters();
            System.out.println("params = " + params);
            System.out.println("request = " + request);

            System.out.println(request.getQueryResult().getDiagnosticInfo());

            if (params.size() > 0) {
                response.setFulfillmentText("here is parameters " + params.toString());
            }

            else {
                if (request.getQueryResult().getQueryText().equals("1000")) {
                    response.setFulfillmentText("eat");
                } else
                    response.setFulfillmentText("No");
            }

            return new ResponseEntity<GoogleCloudDialogflowV2WebhookResponse>(response, HttpStatus.OK);
        } catch (Exception ex) {
            return new ResponseEntity<Object>(ex.getMessage(), HttpStatus.BAD_REQUEST);
        }
    }
}

0 Answers0