Skip to content

Commit eb8f5d5

Browse files
authored
Dialogflow to gcp (GoogleCloudPlatform#1181)
* Clean copy of Dialogflow samples, need to update pom.xml to work with java-docs-samples repo * Update files to match GCP Repo's style guides * Update argument parsing * Update Inc. to LLC * Update pom.xml * Add missing region tags for sample tracker
1 parent dce320a commit eb8f5d5

35 files changed

+5016
-0
lines changed

dialogflow/cloud-client/README.md

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# Dialogflow API Java examples
2+
3+
These samples demonstrate the use of the [Dialogflow API][dialogflow].
4+
5+
These samples show how to detect intents with text, audio, and streaming audio.
6+
7+
These samples show how to manage contexts, entities, entity types, and intents
8+
9+
[dialogflow]: https://dialogflow.com/docs/getting-started/basics
10+
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
11+
12+
## Java Version
13+
14+
This sample requires you to have
15+
[Java8](https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html).
16+
17+
### Download Maven
18+
19+
To get started, [download][maven-download] and [install][maven-install] it.
20+
21+
[maven]: https://maven.apache.org
22+
[maven-download]: https://maven.apache.org/download.cgi
23+
[maven-install]: https://maven.apache.org/install.html
24+
25+
### Setup
26+
27+
* Create a project with the [Google Cloud Console][cloud-console], and enable
28+
the [Dialogflow API][dialogflow-api].
29+
* [Set up][auth] authentication. For
30+
example, from the Cloud Console, create a service account,
31+
download its json credentials file, then set the appropriate environment
32+
variable:
33+
34+
```bash
35+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
36+
```
37+
* To run tests, set GOOGLE_CLOUD_PROJECT to your PROJECT_ID:
38+
```
39+
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
40+
```
41+
```
42+
mvn clean verify
43+
```
44+
* Set PROJECT_ID in pom.xml to your Google Cloud Project Id.
45+
* Set SESSION_ID in pom.xml to a session name of your choice. (Defaults to SESSION_ID)
46+
* Set CONTEXT_ID in pom.xml to a context name of your choice. (Defaults to CONTEXT_ID)
47+
48+
[cloud-console]: https://console.cloud.google.com
49+
[dialogflow-api]: https://console.cloud.google.com/apis/library/dialogflow.googleapis.com
50+
[auth]: https://cloud.google.com/docs/authentication/getting-started
51+
52+
## Run the sample
53+
54+
To build the sample, we use Maven.
55+
56+
```bash
57+
mvn clean package
58+
```
59+
60+
### Set up the Agent
61+
Import the sample agent (RoomReservation.zip) from the resources directory to your
62+
[Dialogflow Project][dialogflow-import] using the following guide:
63+
[Versioning with Import/Export][import-export-versioning]
64+
65+
[dialogflow-import]: https://console.dialogflow.com/api-client/#/editAgent/
66+
[import-export-versioning]: https://dialogflow.com/docs/best-practices/import-export-for-versions
67+
68+
## Samples
69+
70+
### Detect Intent Texts
71+
DialogFlow API Detect Intent sample with text inputs.
72+
73+
```
74+
mvn exec:java -DDetectIntentText
75+
```
76+
77+
### Detect Intent Audio
78+
DialogFlow API Detect Intent sample with audio files. Returns the result of detect intent with an
79+
audio file as input.
80+
81+
Note: Execute the following commands in order to yield reasonable outputs.
82+
```
83+
mvn exec:java -DDetectIntentAudioBookARoom
84+
```
85+
```
86+
mvn exec:java -DDetectIntentAudioMountainView
87+
```
88+
```
89+
mvn exec:java -DDetectIntentAudioToday
90+
```
91+
```
92+
mvn exec:java -DDetectIntentAudio230PM
93+
```
94+
```
95+
mvn exec:java -DDetectIntentAudioHalfAnHour
96+
```
97+
```
98+
mvn exec:java -DDetectIntentAudioTwoPeople
99+
```
100+
101+
### Detect Intent Stream
102+
DialogFlow API Detect Intent sample with audio files processes as an audio stream.
103+
104+
```
105+
mvn exec:java -DDetectIntentStreamBookARoom
106+
```
107+
```
108+
mvn exec:java -DDetectIntentStreamMountainView
109+
```
110+
111+
### Detect Intent With Model Selection
112+
DialogFlow API Detect Intent sample with model selection
113+
```
114+
mvn exec:java -DDetectIntentWithModelSelection -Dexec.args='--projectId PROJECT_ID --audioFilePath resources/book_a_room.wav --sessionId SESSION_ID'
115+
```
116+
117+
### Detect Intent With Sentiment Analysis
118+
DialogFlow API Detect Intent sample with sentiment analysis
119+
```
120+
mvn exec:java -DDetectIntentWithSentimentAnalysis -Dexec.args="--projectId PROJECT_ID -sessionId SESSION_ID 'hello'"
121+
```
122+
123+
### Detect Intent With Text-to-Speech
124+
DialogFlow API Detect Intent sample with Text-to-Speech
125+
```
126+
mvn exec:java -DetectIntentTTSResponse
127+
```
128+
129+
### Detect Intent Knowledge
130+
DialogFlow API Detect Intent sample with querying knowledge connector.
131+
```
132+
mvn exec:java -DDetectIntentKnowledge -Dexec.args="--projectId PROJECT_ID --knowledgeBaseId KNOWLEDGE_BASE_ID -sessionId SESSION_ID 'Where can I find pricing information?'"
133+
```
134+
135+
### Context Management
136+
DialogFlow API Context sample.
137+
138+
Lists contexts
139+
```
140+
mvn exec:java -DContextManagementList
141+
```
142+
Create an entity type
143+
```
144+
mvn exec:java -DContextManagementCreate
145+
```
146+
Delete entity type
147+
```
148+
mvn exec:java -DContextManagementDelete
149+
```
150+
151+
### Entity Management
152+
DialogFlow API Entity sample.
153+
154+
List entities
155+
```
156+
mvn exec:java -DEntityManagementList
157+
```
158+
Create an entity
159+
```
160+
mvn exec:java -DEntityManagementCreate
161+
```
162+
Delete entity
163+
```
164+
mvn exec:java -DEntityManagementDelete
165+
```
166+
167+
### Entity Type Management
168+
DialogFlow API EntityType sample.
169+
170+
List entity types
171+
```
172+
mvn exec:java -DEntityTypeManagementList
173+
```
174+
Create an entity type
175+
```
176+
mvn exec:java -DEntityTypeManagementCreate
177+
```
178+
Delete entity type
179+
```
180+
mvn exec:java -DEntityTypeManagementDelete
181+
```
182+
183+
### Intent Management
184+
DialogFlow API Intent sample.
185+
186+
List intents
187+
```
188+
mvn exec:java -DIntentManagementList
189+
```
190+
Create an intent
191+
```
192+
mvn exec:java -DIntentManagementCreate
193+
```
194+
Delete intent
195+
```
196+
mvn exec:java -DIntentManagementDelete
197+
```
198+
199+
### Session Entity Type Management
200+
DialogFlow API SessionEntityType sample.
201+
202+
List session entity types
203+
```
204+
mvn exec:java -DSessionEntityTypeManagementList
205+
```
206+
Create session entity type
207+
```
208+
mvn exec:java -DSessionEntityTypeManagementCreate
209+
```
210+
Delete session entity type
211+
```
212+
mvn exec:java -DSessionEntityTypeManagementDelete
213+
```
214+
215+
### Knowledge Base Management
216+
DialogFlow API KnowledgeBaseManagement sample
217+
218+
List knowledge base
219+
```
220+
mvn exec:java -DKnowledgeBaseManagement -Dexec.args='list --projectId PROJECT_ID'
221+
```
222+
Create knowledge base
223+
```
224+
mvn exec:java -DKnowledgeBaseManagement -Dexec.args='create DISPLAY_NAME --projectId PROJECT_ID'
225+
```
226+
Delete knowledge base
227+
```
228+
mvn exec:java -DKnowledgeBaseManagement -Dexec.args='delete KNOWLEDGE_BASE_ID --projectId PROJECT_ID'
229+
```
230+
231+
### Document Management
232+
DialogFlow API DocumentManagement sample
233+
234+
List documents
235+
```
236+
mvn exec:java -DDocumentManagement -Dexec.args='list --projectId PROJECT_ID --knowledgeBaseId KNOWLEDGE_BASE_ID'
237+
```
238+
Create doucment
239+
```
240+
mvn exec:java -DDocumentManagement -Dexec.args='create KNOWLEDGE_BASE_ID --projectId PROJECT_ID
241+
--displayName DISPLAY_NAME
242+
--mimeType text/html
243+
--knowledgeType FAQ'
244+
--contentUri https://cloud.google.com/storage/docs/faq'
245+
```
246+
Delete doucment
247+
```
248+
mvn exec:java -DDocumentManagement -Dexec.args='delete KNOWLEDGE_BASE_ID --projectId PROJECT_ID --documentId DOCUMENT_ID
249+
```

0 commit comments

Comments
 (0)