mirror of
https://github.com/jlengrand/dialogflow-fun.git
synced 2026-03-10 08:11:22 +00:00
Merge pull request #1 from jlengrand/project-setup
Print existing agent and entity
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
conf
|
||||
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "CodeLens (Launch) - CreateAgent",
|
||||
"request": "launch",
|
||||
"mainClass": "CreateAgent",
|
||||
"projectName": "dialogflow-fun"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "CodeLens (Launch) - DialogFlow",
|
||||
"request": "launch",
|
||||
"mainClass": "DialogFlow",
|
||||
"projectName": "dialogflow-fun"
|
||||
}
|
||||
]
|
||||
}
|
||||
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"maven.view": "hierarchical"
|
||||
}
|
||||
11
README.md
11
README.md
@@ -3,3 +3,14 @@
|
||||
A simple project using dialog flow
|
||||
|
||||
- Google Cloud project name : [dialogflow-fun](https://console.cloud.google.com/apis/library?project=dialogflow-fun)
|
||||
|
||||
* Create google cloud project
|
||||
* 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.
|
||||
|
||||
## Useful references
|
||||
|
||||
- [Reference guide](https://cloud.google.com/dialogflow/docs/reference/libraries/java)
|
||||
- [Full library reference](https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/dialogflow/v2/package-summary.html)
|
||||
- [Maven dependency](https://search.maven.org/artifact/com.google.cloud/google-cloud-dialogflow/0.114.0-alpha/jar)
|
||||
- [Authentication](https://cloud.google.com/docs/authentication/getting-started)
|
||||
|
||||
49
dialogflow-fun-java/.classpath
Normal file
49
dialogflow-fun-java/.classpath
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="target/generated-sources/annotations">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="m2e-apt" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="m2e-apt" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
4
dialogflow-fun-java/.gitignore
vendored
4
dialogflow-fun-java/.gitignore
vendored
@@ -20,4 +20,6 @@
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
hs_err_pid*
|
||||
|
||||
conf
|
||||
23
dialogflow-fun-java/.project
Normal file
23
dialogflow-fun-java/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dialogflow-fun</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.apt.aptEnabled=false
|
||||
9
dialogflow-fun-java/.settings/org.eclipse.jdt.core.prefs
Normal file
9
dialogflow-fun-java/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=11
|
||||
4
dialogflow-fun-java/.settings/org.eclipse.m2e.core.prefs
Normal file
4
dialogflow-fun-java/.settings/org.eclipse.m2e.core.prefs
Normal file
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -1,12 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>fr.lengrand</groupId>
|
||||
<artifactId>dialogflow-fun</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<groupId>fr.lengrand</groupId>
|
||||
<artifactId>dialogflow-fun</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<java.version>11</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>1.30.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud</groupId>
|
||||
<artifactId>google-cloud-dialogflow</artifactId>
|
||||
<version>0.114.0-alpha</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
95
dialogflow-fun-java/src/main/java/CreateAgent.java
Normal file
95
dialogflow-fun-java/src/main/java/CreateAgent.java
Normal file
@@ -0,0 +1,95 @@
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.cloud.dialogflow.v2beta1.EntityType;
|
||||
import com.google.cloud.dialogflow.v2beta1.EntityTypeName;
|
||||
import com.google.cloud.dialogflow.v2beta1.EntityTypesClient;
|
||||
import com.google.cloud.dialogflow.v2beta1.ProjectAgentName;
|
||||
import com.google.cloud.dialogflow.v2beta1.Agent;
|
||||
import com.google.cloud.dialogflow.v2beta1.AgentsClient;
|
||||
import com.google.cloud.dialogflow.v2beta1.ProjectName;
|
||||
import com.google.cloud.dialogflow.v2beta1.EntityType.Entity;
|
||||
|
||||
public class CreateAgent {
|
||||
|
||||
private static final String GOOGLE_AUTH_ENV_NAME = "GOOGLE_APPLICATION_CREDENTIALS";
|
||||
private static final String PROJECT_NAME = "dialogflow-fun";
|
||||
private static final String AGENT_NAME = "dialogflow-fun-agent";
|
||||
private static final String AGENT_ID = "ac522b80-e75b-40cd-9493-269fbb4ef634";
|
||||
private static final String ENTITY_TYPE_ID = "Developer";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if (!googleAuthOk()) {
|
||||
System.out.println("Error with Google Authentication. Exiting...");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
getAgentInfo();
|
||||
getEntitiesInfo();
|
||||
|
||||
System.out.println("Done");
|
||||
}
|
||||
|
||||
public static void getEntitiesInfo() {
|
||||
|
||||
// ENTITY TYPES
|
||||
// https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/dialogflow/v2/package-summary.html
|
||||
// * **System** - entities that are defined by the Dialogflow API for common
|
||||
// data types such as date, time, currency, and so on. A system entity is
|
||||
// represented by the `EntityType` type.
|
||||
// * **Developer** - entities that are defined by you that represent actionable
|
||||
// data that is meaningful to your application. For example, you could define a
|
||||
// `pizza.sauce` entity for red or white pizza sauce, a `pizza.cheese` entity
|
||||
// for the different types of cheese on a pizza, a `pizza.topping` entity for
|
||||
// different toppings, and so on. A developer entity is represented by the
|
||||
// `EntityType` type.
|
||||
// * **User** - entities that are built for an individual user such as
|
||||
// favorites, preferences, playlists, and so on. A user entity is represented by
|
||||
// the [SessionEntityType][google.cloud.dialogflow.v2.SessionEntityType] type.
|
||||
|
||||
System.out.println("==========");
|
||||
System.out.println("Getting Entities info");
|
||||
|
||||
try {
|
||||
EntityTypesClient entityTypesClient = EntityTypesClient.create();
|
||||
ProjectAgentName parent = ProjectAgentName.of(PROJECT_NAME);
|
||||
for (EntityType entityType : entityTypesClient.listEntityTypes(parent).iterateAll()) {
|
||||
System.out.println(entityType.getDisplayName());
|
||||
List<Entity> entities = entityType.getEntitiesList();
|
||||
entities.forEach(CreateAgent::printEntity);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("==========");
|
||||
|
||||
}
|
||||
|
||||
public static void printEntity(Entity entity) {
|
||||
System.out.println(entity.getValue());
|
||||
}
|
||||
|
||||
public static void getAgentInfo() {
|
||||
System.out.println("==========");
|
||||
System.out.println("Getting Agent info");
|
||||
|
||||
try {
|
||||
AgentsClient agentsClient = AgentsClient.create();
|
||||
Agent myAgent = agentsClient.getAgent(ProjectName.of("dialogflow-fun"));
|
||||
System.out.println(myAgent.getDisplayName());
|
||||
System.out.println(myAgent.getDescription());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("==========");
|
||||
}
|
||||
|
||||
public static boolean googleAuthOk() {
|
||||
return System.getenv().get(GOOGLE_AUTH_ENV_NAME) != null;
|
||||
}
|
||||
}
|
||||
5
dialogflow-fun-java/target/maven-archiver/pom.properties
Normal file
5
dialogflow-fun-java/target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Sun Oct 13 17:08:23 CEST 2019
|
||||
groupId=fr.lengrand
|
||||
artifactId=dialogflow-fun
|
||||
version=1.0-SNAPSHOT
|
||||
@@ -0,0 +1,2 @@
|
||||
CreateAgent.class
|
||||
DialogFlow.class
|
||||
@@ -0,0 +1,2 @@
|
||||
/Users/jlengrand/IdeaProjects/dialogflow-fun/dialogflow-fun-java/src/main/java/DialogFlow.java
|
||||
/Users/jlengrand/IdeaProjects/dialogflow-fun/dialogflow-fun-java/src/main/java/CreateAgent.java
|
||||
Reference in New Issue
Block a user