Support for first fulfillment

This commit is contained in:
Julien Lengrand-Lambert
2019-10-23 11:03:03 +02:00
parent 80e20bcdac
commit 1ed7cbba04
8 changed files with 64 additions and 2 deletions

View File

@@ -10,6 +10,13 @@ A simple project using dialog flow
* Create DialogFlow agent coupled to project [dialogflow-fun-agent](https://dialogflow.cloud.google.com/#/agent/ac522b80-e75b-40cd-9493-269fbb4ef634/intents)
* Create service account and set environment variable.
## Google Resources for me
- [View logs](https://console.cloud.google.com/logs/viewer?project=dialogflow-fun&minLogLevel=0&expandAll=false&timestamp=2019-10-23T07:50:18.827000000Z&customFacets=&limitCustomFacetWidth=true&dateRangeStart=2019-10-23T06:50:19.080Z&dateRangeEnd=2019-10-23T07:50:19.080Z&interval=PT1H&resource=gae_app%2Fmodule_id%2Fdefault&logName=projects%2Fdialogflow-fun%2Flogs%2Fstdout&logName=projects%2Fdialogflow-fun%2Flogs%2Fstderr&logName=projects%2Fdialogflow-fun%2Flogs%2Fappengine.googleapis.com%252Frequest_log&scrollTimestamp=2019-10-23T07:48:44.904582000Z)
- [Dialog Flow project](https://dialogflow.cloud.google.com/#/agent/ac522b80-e75b-40cd-9493-269fbb4ef634/intents)
- [App Engine Dashboard](https://console.cloud.google.com/appengine?project=dialogflow-fun&serviceId=default&duration=PT6H)
- [The app in the cloud](https://dialogflow-fun.appspot.com/)
## Useful references
- [Reference guide](https://cloud.google.com/dialogflow/docs/reference/libraries/java)

View File

@@ -19,6 +19,11 @@
</properties>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-dialogflow</artifactId>
<version>0.114.0-alpha</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>

View File

@@ -1,5 +1,9 @@
package fr.lengrand.dialogflowfunapi;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.cloud.dialogflow.v2beta1.WebhookRequest;
import fr.lengrand.dialogflowfunapi.dialogflow.data.DialogFlowResponse;
import fr.lengrand.dialogflowfunapi.dialogflow.data.DialogFlowWebHookRequest;
import fr.lengrand.dialogflowfunapi.openbankproject.OpenBankClient;
import fr.lengrand.dialogflowfunapi.openbankproject.auth.Auth;
import fr.lengrand.dialogflowfunapi.openbankproject.data.balance.Balance;
@@ -8,12 +12,15 @@ import fr.lengrand.dialogflowfunapi.openbankproject.data.transactions.Transactio
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.StringWriter;
@SpringBootApplication
@RestController
@@ -38,13 +45,21 @@ public class DialogflowFunApiApplication {
}
}
@PostMapping(value = "/fulfillment")
public DialogFlowResponse fulfillment(@RequestBody DialogFlowWebHookRequest request) throws IOException {
System.out.println("Received fullfillment!");
System.out.println(request);
System.out.println("#################" + request.queryResult.intent.displayName);
System.out.println("#################" + request.queryResult.intent.name);
return new DialogFlowResponse("You requested to see your balance using " + request.queryResult.intent.displayName);
}
@GetMapping("/")
public String hello() {
return "hello from your bank API!";
}
// TODO : Take inputs from requests
@GetMapping("/token")
public String auth() throws IOException, InterruptedException {
return auth.getToken().isPresent()? auth.getToken().get() : "No token!";

View File

@@ -0,0 +1,7 @@
package fr.lengrand.dialogflowfunapi.dialogflow.data;
public class DialogFlowIntent {
public String name;
public String displayName;
}

View File

@@ -0,0 +1,8 @@
package fr.lengrand.dialogflowfunapi.dialogflow.data;
public class DialogFlowQueryResult {
public String queryRequest;
public DialogFlowIntent intent;
}

View File

@@ -0,0 +1,11 @@
package fr.lengrand.dialogflowfunapi.dialogflow.data;
public class DialogFlowResponse {
public DialogFlowResponse(String fulfillment_text){
this.fulfillment_text = fulfillment_text;
}
public String fulfillment_text;
}

View File

@@ -0,0 +1,8 @@
package fr.lengrand.dialogflowfunapi.dialogflow.data;
public class DialogFlowWebHookRequest {
public String responseId;
public String session;
public DialogFlowQueryResult queryResult;
}

1
stream-logs.sh Executable file
View File

@@ -0,0 +1 @@
gcloud app logs tail -s default