I’m kinda a newbie in Spring Boot. I’m trying to create an API in Spring Boot to process a webhook request from Dialogflow ES. My Agent is configured correctly in the Dialogflow web platform and I can get the request JSON from the webhook (if I receive the RequestBodyas a String).
But, if I change the controller Requestbody parameter to Google’s WebhookRequest class I get the following error: [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type ‘application/json;charset=UTF-8’ is not supported]
Is there any simpler way or better way that I could use to automatically parse the webhook request JSON into this class?
I saw this example and tried to follow but I doesn’t seem to work:
https://innovationm.co/dialogflow-integration-in-spring-boot-a-developers-guide/
Where is a piece of my code:
import com.google.cloud.dialogflow.v2beta1.WebhookRequest;
import com.google.cloud.dialogflow.v2beta1.WebhookResponse;
import org.opi.finance.bot.Investy.specs.Intent;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class FulfillmentController {
@GetMapping("/")
public ResponseEntity<String> privateAPI() {
return new ResponseEntity<>(
"This is a private API that will be use for a financial bot!",
HttpStatus.OK);
}
@PostMapping("/")
public WebhookResponse dfFulfillmentHandler(@RequestBody WebhookRequest request){
System.out.println("The header of the request is: " + authorization);
System.out.println("The body of the request is: " + request);
// TODO: get intent from body
String intent = "test";
// TODO: get requester name from body
String requesterName = "Someone";
....
}
}