diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml
index a454a61e8..1b645c012 100644
--- a/.github/.OwlBot.lock.yaml
+++ b/.github/.OwlBot.lock.yaml
@@ -13,5 +13,5 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest
- digest: sha256:6d4e3a15c62cfdcb823d60e16da7521e7c6fc00eba07c8ff12e4de9924a57d28
-# created: 2022-06-29T23:17:33.110417661Z
+ digest: sha256:f8374176dc59291f05dd3fec927a9da2cda687a9ef4de32e77f699a2be12ab45
+# created: 2022-07-07T14:26:11.880812641Z
diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml
index 1d2eb1f85..8c7907fe5 100644
--- a/.github/sync-repo-settings.yaml
+++ b/.github/sync-repo-settings.yaml
@@ -16,6 +16,8 @@ branchProtectionRules:
- 'Kokoro - Test: Integration'
- cla/google
- OwlBot Post Processor
+ - 'Kokoro - Test: Java GraalVM Native Image'
+ - 'Kokoro - Test: Java 17 GraalVM Native Image'
- pattern: java7
isAdminEnforced: true
requiredApprovingReviewCount: 1
@@ -37,4 +39,4 @@ permissionRules:
- team: yoshi-java-admins
permission: admin
- team: yoshi-java
- permission: push
\ No newline at end of file
+ permission: push
diff --git a/.kokoro/nightly/samples.cfg b/.kokoro/nightly/samples.cfg
index 9761fd864..51f17afa0 100644
--- a/.kokoro/nightly/samples.cfg
+++ b/.kokoro/nightly/samples.cfg
@@ -3,7 +3,7 @@
# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
- value: "gcr.io/cloud-devrel-kokoro-resources/java8"
+ value: "gcr.io/cloud-devrel-kokoro-resources/java11"
}
env_vars: {
diff --git a/.kokoro/presubmit/samples.cfg b/.kokoro/presubmit/samples.cfg
index 01e096004..ba8d71941 100644
--- a/.kokoro/presubmit/samples.cfg
+++ b/.kokoro/presubmit/samples.cfg
@@ -3,7 +3,7 @@
# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
- value: "gcr.io/cloud-devrel-kokoro-resources/java8"
+ value: "gcr.io/cloud-devrel-kokoro-resources/java11"
}
env_vars: {
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7c9fe395e..0e9999f77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog
+## [0.14.1](https://github.com/googleapis/java-dialogflow-cx/compare/v0.14.0...v0.14.1) (2022-07-12)
+
+
+### Documentation
+
+* add DetectIntent samples ([#500](https://github.com/googleapis/java-dialogflow-cx/issues/500)) ([2c5f9c2](https://github.com/googleapis/java-dialogflow-cx/commit/2c5f9c25a88ebb041b5ba11e2fab6b7b467afb19))
+
## [0.14.0](https://github.com/googleapis/java-dialogflow-cx/compare/v0.13.1...v0.14.0) (2022-07-01)
diff --git a/README.md b/README.md
index 0d458a92d..24a1bcb7f 100644
--- a/README.md
+++ b/README.md
@@ -22,20 +22,20 @@ If you are using Maven, add this to your pom.xml file:
com.google.cloud
google-cloud-dialogflow-cx
- 0.13.1
+ 0.14.0
```
-If you are using Gradle without BOM, add this to your dependencies
+If you are using Gradle without BOM, add this to your dependencies:
```Groovy
-implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.13.1'
+implementation 'com.google.cloud:google-cloud-dialogflow-cx:0.14.0'
```
-If you are using SBT, add this to your dependencies
+If you are using SBT, add this to your dependencies:
```Scala
-libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.13.1"
+libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.14.0"
```
## Authentication
@@ -86,7 +86,14 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-dialogflow-cx
| Create Simple Page | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/CreateSimplePage.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/CreateSimplePage.java) |
| Delete Page | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DeletePage.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DeletePage.java) |
| Detect Intent | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntent.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntent.java) |
+| Detect Intent Audio Input | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java) |
+| Detect Intent Disable Webhook | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java) |
+| Detect Intent Event Input | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java) |
+| Detect Intent Intent Input | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java) |
+| Detect Intent Sentiment Analysis | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java) |
| Detect Intent Stream | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java) |
+| Detect Intent Streaming Partial Response | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java) |
+| Detect Intent Synthesize Text To Speech Output | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java) |
| Export Agent | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/ExportAgent.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/ExportAgent.java) |
| List Pages | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/ListPages.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/ListPages.java) |
| List Test Case Results | [source code](https://github.com/googleapis/java-dialogflow-cx/blob/main/samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dialogflow-cx&page=editor&open_in_editor=samples/snippets/src/main/java/dialogflow/cx/ListTestCaseResults.java) |
diff --git a/google-cloud-dialogflow-cx-bom/pom.xml b/google-cloud-dialogflow-cx-bom/pom.xml
index ac74ac82a..968beaa39 100644
--- a/google-cloud-dialogflow-cx-bom/pom.xml
+++ b/google-cloud-dialogflow-cx-bom/pom.xml
@@ -3,12 +3,12 @@
4.0.0
com.google.cloud
google-cloud-dialogflow-cx-bom
- 0.14.0
+ 0.14.1
pom
com.google.cloud
google-cloud-shared-config
- 1.5.0
+ 1.5.1
Google Dialogflow CX BOM
@@ -56,27 +56,27 @@
com.google.cloud
google-cloud-dialogflow-cx
- 0.14.0
+ 0.14.1
com.google.api.grpc
grpc-google-cloud-dialogflow-cx-v3beta1
- 0.14.0
+ 0.14.1
com.google.api.grpc
grpc-google-cloud-dialogflow-cx-v3
- 0.14.0
+ 0.14.1
com.google.api.grpc
proto-google-cloud-dialogflow-cx-v3beta1
- 0.14.0
+ 0.14.1
com.google.api.grpc
proto-google-cloud-dialogflow-cx-v3
- 0.14.0
+ 0.14.1
diff --git a/google-cloud-dialogflow-cx/pom.xml b/google-cloud-dialogflow-cx/pom.xml
index 0c6623a2f..639e565d8 100644
--- a/google-cloud-dialogflow-cx/pom.xml
+++ b/google-cloud-dialogflow-cx/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.google.cloud
google-cloud-dialogflow-cx
- 0.14.0
+ 0.14.1
jar
Google Dialogflow CX
https://github.com/googleapis/java-dialogflow-cx
@@ -11,7 +11,7 @@
com.google.cloud
google-cloud-dialogflow-cx-parent
- 0.14.0
+ 0.14.1
google-cloud-dialogflow-cx
diff --git a/grpc-google-cloud-dialogflow-cx-v3/pom.xml b/grpc-google-cloud-dialogflow-cx-v3/pom.xml
index 8f70d3390..8adb3894f 100644
--- a/grpc-google-cloud-dialogflow-cx-v3/pom.xml
+++ b/grpc-google-cloud-dialogflow-cx-v3/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-dialogflow-cx-v3
- 0.14.0
+ 0.14.1
grpc-google-cloud-dialogflow-cx-v3
GRPC library for grpc-google-cloud-dialogflow-cx-v3
com.google.cloud
google-cloud-dialogflow-cx-parent
- 0.14.0
+ 0.14.1
diff --git a/grpc-google-cloud-dialogflow-cx-v3beta1/pom.xml b/grpc-google-cloud-dialogflow-cx-v3beta1/pom.xml
index 7fe2b6e74..5c07b783a 100644
--- a/grpc-google-cloud-dialogflow-cx-v3beta1/pom.xml
+++ b/grpc-google-cloud-dialogflow-cx-v3beta1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
grpc-google-cloud-dialogflow-cx-v3beta1
- 0.14.0
+ 0.14.1
grpc-google-cloud-dialogflow-cx-v3beta1
GRPC library for grpc-google-cloud-dialogflow-cx-v3beta1
com.google.cloud
google-cloud-dialogflow-cx-parent
- 0.14.0
+ 0.14.1
diff --git a/owlbot.py b/owlbot.py
index dca9d8672..1e8a3cd64 100644
--- a/owlbot.py
+++ b/owlbot.py
@@ -18,7 +18,24 @@
for library in s.get_staging_dirs():
# put any special-case replacements here
+
s.move(library)
s.remove_staging_dirs()
java.common_templates()
+
+s.replace(
+ '**/pom.xml',
+ r'1.8',
+ r'11'
+)
+s.replace(
+ '**/pom.xml',
+ r'1.8',
+ r'11'
+)
+s.replace(
+ '.kokoro/**/samples.cfg',
+ r'gcr.io/cloud-devrel-kokoro-resources/java8',
+ r'gcr.io/cloud-devrel-kokoro-resources/java11'
+)
diff --git a/pom.xml b/pom.xml
index 096ad4d1d..4f9e26308 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.google.cloud
google-cloud-dialogflow-cx-parent
pom
- 0.14.0
+ 0.14.1
Google Dialogflow CX Parent
https://github.com/googleapis/java-dialogflow-cx
@@ -14,7 +14,7 @@
com.google.cloud
google-cloud-shared-config
- 1.5.0
+ 1.5.1
@@ -61,27 +61,27 @@
com.google.cloud
google-cloud-dialogflow-cx
- 0.14.0
+ 0.14.1
com.google.api.grpc
proto-google-cloud-dialogflow-cx-v3beta1
- 0.14.0
+ 0.14.1
com.google.api.grpc
proto-google-cloud-dialogflow-cx-v3
- 0.14.0
+ 0.14.1
com.google.api.grpc
grpc-google-cloud-dialogflow-cx-v3beta1
- 0.14.0
+ 0.14.1
com.google.api.grpc
grpc-google-cloud-dialogflow-cx-v3
- 0.14.0
+ 0.14.1
diff --git a/proto-google-cloud-dialogflow-cx-v3/pom.xml b/proto-google-cloud-dialogflow-cx-v3/pom.xml
index b5ee2af65..4f8fa6d2f 100644
--- a/proto-google-cloud-dialogflow-cx-v3/pom.xml
+++ b/proto-google-cloud-dialogflow-cx-v3/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
proto-google-cloud-dialogflow-cx-v3
- 0.14.0
+ 0.14.1
proto-google-cloud-dialogflow-cx-v3
PROTO library for proto-google-cloud-dialogflow-cx-v3
com.google.cloud
google-cloud-dialogflow-cx-parent
- 0.14.0
+ 0.14.1
diff --git a/proto-google-cloud-dialogflow-cx-v3beta1/pom.xml b/proto-google-cloud-dialogflow-cx-v3beta1/pom.xml
index 7d355c6de..7e71d2b27 100644
--- a/proto-google-cloud-dialogflow-cx-v3beta1/pom.xml
+++ b/proto-google-cloud-dialogflow-cx-v3beta1/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.google.api.grpc
proto-google-cloud-dialogflow-cx-v3beta1
- 0.14.0
+ 0.14.1
proto-google-cloud-dialogflow-cx-v3beta1
PROTO library for proto-google-cloud-dialogflow-cx-v3beta1
com.google.cloud
google-cloud-dialogflow-cx-parent
- 0.14.0
+ 0.14.1
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index cf5793864..8dc3142f3 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -18,8 +18,8 @@
- 1.8
- 1.8
+ 11
+ 11
UTF-8
diff --git a/samples/pom.xml b/samples/pom.xml
index 1ba73edc7..69ba2a92b 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -22,8 +22,8 @@
- 1.8
- 1.8
+ 11
+ 11
UTF-8
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index 8eea4a9af..e31dc4a75 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -18,8 +18,8 @@
- 1.8
- 1.8
+ 11
+ 11
UTF-8
@@ -28,7 +28,7 @@
com.google.cloud
google-cloud-dialogflow-cx
- 0.14.0
+ 0.14.1
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 5a32a4ec6..5c723ddd6 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -18,8 +18,8 @@
- 1.8
- 1.8
+ 11
+ 11
UTF-8
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java
new file mode 100644
index 000000000..e864f381a
--- /dev/null
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentAudioInput.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+// [START dialogflow_cx_v3_detect_intent_audio_input]
+
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.dialogflow.cx.v3.AudioEncoding;
+import com.google.cloud.dialogflow.cx.v3.AudioInput;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentRequest;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentResponse;
+import com.google.cloud.dialogflow.cx.v3.InputAudioConfig;
+import com.google.cloud.dialogflow.cx.v3.QueryInput;
+import com.google.cloud.dialogflow.cx.v3.QueryResult;
+import com.google.cloud.dialogflow.cx.v3.SessionName;
+import com.google.cloud.dialogflow.cx.v3.SessionsClient;
+import com.google.cloud.dialogflow.cx.v3.SessionsSettings;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+public class DetectIntentAudioInput {
+
+ // DialogFlow API Detect Intent sample with Audio input.
+ public static void main(String[] args) throws IOException, ApiException {
+ /** TODO (developer): replace these values with your own values */
+ String projectId = "my-project-id";
+ String locationId = "global";
+ String agentId = "my-agent-id";
+ String audioFileName = "resources/book_a_room.wav";
+ int sampleRateHertz = 16000;
+ /*
+ * A session ID is a string of at most 36 bytes in size.
+ * Your system is responsible for generating unique session IDs.
+ * They can be random numbers, hashed end-user identifiers,
+ * or any other values that are convenient for you to generate.
+ */
+ String sessionId = "my-UUID";
+ String languageCode = "en";
+
+ detectIntent(
+ projectId, locationId, agentId, audioFileName, sampleRateHertz, sessionId, languageCode);
+ }
+
+ public static void detectIntent(
+ String projectId,
+ String locationId,
+ String agentId,
+ String audioFileName,
+ int sampleRateHertz,
+ String sessionId,
+ String languageCode)
+ throws IOException, ApiException {
+
+ SessionsSettings.Builder sessionsSettingsBuilder = SessionsSettings.newBuilder();
+ if (locationId.equals("global")) {
+ sessionsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
+ } else {
+ sessionsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
+ }
+ SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
+
+ // Instantiates a client by setting the session name.
+ // Format:`projects//locations//agents//sessions/`
+ try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
+ SessionName session =
+ SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);
+
+ // TODO : Uncomment if you want to print session path
+ // System.out.println("Session Path: " + session.toString());
+ InputAudioConfig inputAudioConfig =
+ InputAudioConfig.newBuilder()
+ .setAudioEncoding(AudioEncoding.AUDIO_ENCODING_LINEAR_16)
+ .setSampleRateHertz(sampleRateHertz)
+ .build();
+
+ try (FileInputStream audioStream = new FileInputStream(audioFileName)) {
+ // Subsequent requests must **only** contain the audio data.
+ // Following messages: audio chunks. We just read the file in fixed-size chunks. In reality
+ // you would split the user input by time.
+ byte[] buffer = new byte[4096];
+ int bytes = audioStream.read(buffer);
+ AudioInput audioInput =
+ AudioInput.newBuilder()
+ .setAudio(ByteString.copyFrom(buffer, 0, bytes))
+ .setConfig(inputAudioConfig)
+ .build();
+ QueryInput queryInput =
+ QueryInput.newBuilder()
+ .setAudio(audioInput)
+ .setLanguageCode("en-US") // languageCode = "en-US"
+ .build();
+
+ DetectIntentRequest request =
+ DetectIntentRequest.newBuilder()
+ .setSession(session.toString())
+ .setQueryInput(queryInput)
+ .build();
+
+ // Performs the detect intent request.
+ DetectIntentResponse response = sessionsClient.detectIntent(request);
+
+ // Display the query result.
+ QueryResult queryResult = response.getQueryResult();
+
+ System.out.println("====================");
+ System.out.format(
+ "Detected Intent: %s (confidence: %f)\n",
+ queryResult.getTranscript(), queryResult.getIntentDetectionConfidence());
+ }
+ }
+ }
+}
+// [END dialogflow_cx_v3_detect_intent_audio_input]
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java
new file mode 100644
index 000000000..c0cf470fe
--- /dev/null
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentDisableWebhook.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+// [START dialogflow_cx_v3_detect_intent_disable_webhook]
+
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentRequest;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentResponse;
+import com.google.cloud.dialogflow.cx.v3.QueryInput;
+import com.google.cloud.dialogflow.cx.v3.QueryParameters;
+import com.google.cloud.dialogflow.cx.v3.QueryResult;
+import com.google.cloud.dialogflow.cx.v3.SessionName;
+import com.google.cloud.dialogflow.cx.v3.SessionsClient;
+import com.google.cloud.dialogflow.cx.v3.SessionsSettings;
+import com.google.cloud.dialogflow.cx.v3.TextInput;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class DetectIntentDisableWebhook {
+
+ public static void main(String[] args) throws IOException, ApiException {
+ String projectId = "my-project-id";
+ String locationId = "global";
+ String agentId = "my-agent-id";
+ String sessionId = "my-UUID";
+ List texts = new ArrayList<>(List.of("my-list", "of-texts"));
+ String languageCode = "en";
+
+ detectIntent(projectId, locationId, agentId, sessionId, texts, languageCode);
+ }
+
+ // DialogFlow API Detect Intent sample with webhook disabled.
+ public static Map detectIntent(
+ String projectId,
+ String locationId,
+ String agentId,
+ String sessionId,
+ List texts,
+ String languageCode)
+ throws IOException, ApiException {
+ SessionsSettings.Builder sessionsSettingsBuilder = SessionsSettings.newBuilder();
+ if (locationId.equals("global")) {
+ sessionsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
+ } else {
+ sessionsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
+ }
+ SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
+
+ Map queryResults = Maps.newHashMap();
+
+ // Instantiates a client by setting the session name.
+ // Format:`projects//locations//agents//sessions/`
+ try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
+ SessionName session =
+ SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);
+
+ // TODO : Uncomment if you want to print session path
+ // System.out.println("Session Path: " + session.toString());
+
+ // Detect intents for each text input.
+ for (String text : texts) {
+ // Set the text (hello) for the query.
+ TextInput.Builder textInput = TextInput.newBuilder().setText(text);
+
+ // Build the query with the TextInput and language code (en-US).
+ QueryInput queryInput =
+ QueryInput.newBuilder().setText(textInput).setLanguageCode(languageCode).build();
+
+ // Build the query parameters and setDisableWebhook to true.
+ QueryParameters queryParameters =
+ QueryParameters.newBuilder().setDisableWebhook(true).build();
+
+ // Build the DetectIntentRequest with the SessionName, QueryInput, and QueryParameters.
+ DetectIntentRequest request =
+ DetectIntentRequest.newBuilder()
+ .setSession(session.toString())
+ .setQueryInput(queryInput)
+ .setQueryParams(queryParameters)
+ .build();
+ System.out.println(request.toString());
+
+ // Performs the detect intent request.
+ DetectIntentResponse response = sessionsClient.detectIntent(request);
+
+ // Display the query result.
+ QueryResult queryResult = response.getQueryResult();
+
+ // TODO : Uncomment if you want to print queryResult
+ // System.out.println("====================");
+ // System.out.format("Query Text: '%s'\n", queryResult.getText());
+ // System.out.format(
+ // "Detected Intent: %s (confidence: %f)\n",
+ // queryResult.getIntent().getDisplayName(),
+ // queryResult.getIntentDetectionConfidence());
+
+ queryResults.put(text, queryResult);
+ }
+ }
+ return queryResults;
+ }
+}
+// [END dialogflow_cx_v3_detect_intent_disable_webhook]
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java
new file mode 100644
index 000000000..5f92199e9
--- /dev/null
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentEventInput.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+// [START dialogflow_cx_v3_detect_intent_event_input]
+
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentRequest;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentResponse;
+import com.google.cloud.dialogflow.cx.v3.EventInput;
+import com.google.cloud.dialogflow.cx.v3.QueryInput;
+import com.google.cloud.dialogflow.cx.v3.QueryResult;
+import com.google.cloud.dialogflow.cx.v3.SessionName;
+import com.google.cloud.dialogflow.cx.v3.SessionsClient;
+import com.google.cloud.dialogflow.cx.v3.SessionsSettings;
+import java.io.IOException;
+
+public class DetectIntentEventInput {
+
+ // DialogFlow API Detect Intent sample with Event input.
+ public static void main(String[] args) throws IOException, ApiException {
+ String projectId = "my-project-id";
+ String locationId = "global";
+ String agentId = "my-agent-id";
+ String sessionId = "my-UUID";
+ String event = "my-event-id";
+ String languageCode = "en";
+
+ detectIntent(projectId, locationId, agentId, sessionId, event, languageCode);
+ }
+
+ public static void detectIntent(
+ String projectId,
+ String locationId,
+ String agentId,
+ String sessionId,
+ String event,
+ String languageCode)
+ throws IOException, ApiException {
+
+ SessionsSettings.Builder sessionsSettingsBuilder = SessionsSettings.newBuilder();
+ if (locationId.equals("global")) {
+ sessionsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
+ } else {
+ sessionsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
+ }
+ SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
+
+ // Instantiates a client by setting the session name.
+ // Format:`projects//locations//agents//sessions/`
+ try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
+ SessionName session =
+ SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);
+
+ // TODO : Uncomment if you want to print session path
+ // System.out.println("Session Path: " + session.toString());
+
+ EventInput.Builder eventInput = EventInput.newBuilder().setEvent(event);
+
+ // Build the query with the EventInput and language code (en-US).
+ QueryInput queryInput =
+ QueryInput.newBuilder().setEvent(eventInput).setLanguageCode(languageCode).build();
+
+ // Build the DetectIntentRequest with the SessionName and QueryInput.
+ DetectIntentRequest request =
+ DetectIntentRequest.newBuilder()
+ .setSession(session.toString())
+ .setQueryInput(queryInput)
+ .build();
+
+ // Performs the detect intent request.
+ DetectIntentResponse response = sessionsClient.detectIntent(request);
+
+ // Display the query result.
+ QueryResult queryResult = response.getQueryResult();
+
+ // TODO : Uncomment if you want to print queryResult
+ System.out.println("====================");
+ System.out.format("Triggering Event: %s \n", queryResult.getTriggerEvent());
+ }
+ }
+}
+
+// [END dialogflow_cx_v3_detect_intent_event_input]
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java
new file mode 100644
index 000000000..45af3c567
--- /dev/null
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentIntentInput.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+// [START dialogflow_cx_v3_detect_intent_intent_input]
+
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentRequest;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentResponse;
+import com.google.cloud.dialogflow.cx.v3.IntentInput;
+import com.google.cloud.dialogflow.cx.v3.QueryInput;
+import com.google.cloud.dialogflow.cx.v3.QueryResult;
+import com.google.cloud.dialogflow.cx.v3.SessionName;
+import com.google.cloud.dialogflow.cx.v3.SessionsClient;
+import com.google.cloud.dialogflow.cx.v3.SessionsSettings;
+import java.io.IOException;
+
+public class DetectIntentIntentInput {
+
+ // DialogFlow API Detect Intent sample with Intent input.
+ public static void main(String[] args) throws IOException, ApiException {
+ String projectId = "my-project-id";
+ String locationId = "global";
+ String agentId = "my-agent-id";
+ String sessionId = "my-UUID";
+ String intent = "my-intent-id";
+ String languageCode = "en";
+
+ detectIntent(projectId, locationId, agentId, sessionId, intent, languageCode);
+ }
+
+ public static void detectIntent(
+ String projectId,
+ String locationId,
+ String agentId,
+ String sessionId,
+ String intent,
+ String languageCode)
+ throws IOException, ApiException {
+
+ SessionsSettings.Builder sessionsSettingsBuilder = SessionsSettings.newBuilder();
+ if (locationId.equals("global")) {
+ sessionsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
+ } else {
+ sessionsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
+ }
+ SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
+
+ // Instantiates a client by setting the session name.
+ // Format:`projects//locations//agents//sessions/`
+ try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
+ SessionName session =
+ SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);
+
+ // TODO : Uncomment if you want to print session path
+ // System.out.println("Session Path: " + session.toString());
+
+ IntentInput.Builder intentInput = IntentInput.newBuilder().setIntent(intent);
+
+ // Build the query with the IntentInput and language code (en-US).
+ QueryInput queryInput =
+ QueryInput.newBuilder().setIntent(intentInput).setLanguageCode(languageCode).build();
+
+ // Build the DetectIntentRequest with the SessionName and QueryInput.
+ DetectIntentRequest request =
+ DetectIntentRequest.newBuilder()
+ .setSession(session.toString())
+ .setQueryInput(queryInput)
+ .build();
+
+ // Performs the detect intent request.
+ DetectIntentResponse response = sessionsClient.detectIntent(request);
+
+ // Display the query result.
+ QueryResult queryResult = response.getQueryResult();
+
+ // TODO : Uncomment if you want to print queryResult
+ System.out.println("====================");
+ System.out.format(
+ "Detected Intent: %s (confidence: %f)\n",
+ queryResult.getIntent().getDisplayName(), queryResult.getIntentDetectionConfidence());
+ }
+ }
+}
+
+// [END dialogflow_cx_v3_detect_intent_intent_input]
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java
new file mode 100644
index 000000000..318242c4f
--- /dev/null
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSentimentAnalysis.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+// [START dialogflow_cx_v3_detect_intent_sentiment_analysis]
+
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentRequest;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentResponse;
+import com.google.cloud.dialogflow.cx.v3.QueryInput;
+import com.google.cloud.dialogflow.cx.v3.QueryParameters;
+import com.google.cloud.dialogflow.cx.v3.QueryResult;
+import com.google.cloud.dialogflow.cx.v3.SessionName;
+import com.google.cloud.dialogflow.cx.v3.SessionsClient;
+import com.google.cloud.dialogflow.cx.v3.SessionsSettings;
+import com.google.cloud.dialogflow.cx.v3.TextInput;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class DetectIntentSentimentAnalysis {
+
+ public static void main(String[] args) throws IOException, ApiException {
+ String projectId = "my-project-id";
+ String locationId = "global";
+ String agentId = "my-agent-id";
+ String sessionId = "my-UUID";
+ List texts = new ArrayList<>(List.of("my-list", "of-texts"));
+ String languageCode = "en";
+
+ detectIntent(projectId, locationId, agentId, sessionId, texts, languageCode);
+ }
+
+ // DialogFlow API Detect Intent sample with sentiment analysis.
+ public static Map detectIntent(
+ String projectId,
+ String locationId,
+ String agentId,
+ String sessionId,
+ List texts,
+ String languageCode)
+ throws IOException, ApiException {
+ SessionsSettings.Builder sessionsSettingsBuilder = SessionsSettings.newBuilder();
+ if (locationId.equals("global")) {
+ sessionsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
+ } else {
+ sessionsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
+ }
+ SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
+
+ Map queryResults = Maps.newHashMap();
+
+ // Instantiates a client by setting the session name.
+ // Format:`projects//locations//agents//sessions/`
+ try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
+ SessionName session =
+ SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);
+
+ // TODO : Uncomment if you want to print session path
+ // System.out.println("Session Path: " + session.toString());
+
+ // Detect intents for each text input.
+ for (String text : texts) {
+ // Set the text (hello) for the query.
+ TextInput.Builder textInput = TextInput.newBuilder().setText(text);
+
+ // Build the query with the TextInput and language code (en-US).
+ QueryInput queryInput =
+ QueryInput.newBuilder().setText(textInput).setLanguageCode(languageCode).build();
+
+ // Build the query parameters to analyze the sentiment of the query.
+ QueryParameters queryParameters =
+ QueryParameters.newBuilder().setAnalyzeQueryTextSentiment(true).build();
+
+ // Build the DetectIntentRequest with the SessionName, QueryInput, and QueryParameters.
+ DetectIntentRequest request =
+ DetectIntentRequest.newBuilder()
+ .setSession(session.toString())
+ .setQueryInput(queryInput)
+ .setQueryParams(queryParameters)
+ .build();
+
+ // Performs the detect intent request.
+ DetectIntentResponse response = sessionsClient.detectIntent(request);
+
+ // Display the query result.
+ QueryResult queryResult = response.getQueryResult();
+
+ // TODO : Uncomment if you want to print queryResult
+ // System.out.println("====================");
+ // SentimentAnalysisResult sentimentAnalysisResult =
+ // queryResult.getSentimentAnalysisResult();
+ // Float score = sentimentAnalysisResult.getScore();
+
+ queryResults.put(text, queryResult);
+ }
+ }
+ return queryResults;
+ }
+}
+// [END dialogflow_cx_v3_detect_intent_sentiment_analysis]
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java
index b09609aea..96b1799a5 100644
--- a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStream.java
@@ -53,11 +53,10 @@ public static void detectIntentStream(
}
SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
- // Instantiates a client
+ // Instantiates a client by setting the session name.
+ // Format: `projects//locations//agents//sessions/`
+ // Using the same `sessionId` between requests allows continuation of the conversation.
try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
- // Set the session name using the projectID (my-project-id), locationID (global), agentID
- // (UUID), and sessionId (UUID).
- // Using the same `sessionId` between requests allows continuation of the conversation.
SessionName session = SessionName.of(projectId, locationId, agentId, sessionId);
// Instructs the speech recognizer how to process the audio content.
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java
new file mode 100644
index 000000000..81cb534e2
--- /dev/null
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentStreamingPartialResponse.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+// [START dialogflow_cx_v3_detect_intent_streaming_partial_response]
+
+import com.google.api.gax.rpc.ApiException;
+import com.google.api.gax.rpc.BidiStream;
+import com.google.cloud.dialogflow.cx.v3.AudioEncoding;
+import com.google.cloud.dialogflow.cx.v3.AudioInput;
+import com.google.cloud.dialogflow.cx.v3.InputAudioConfig;
+import com.google.cloud.dialogflow.cx.v3.OutputAudioConfig;
+import com.google.cloud.dialogflow.cx.v3.OutputAudioEncoding;
+import com.google.cloud.dialogflow.cx.v3.QueryInput;
+import com.google.cloud.dialogflow.cx.v3.SessionName;
+import com.google.cloud.dialogflow.cx.v3.SessionsClient;
+import com.google.cloud.dialogflow.cx.v3.SessionsSettings;
+import com.google.cloud.dialogflow.cx.v3.SsmlVoiceGender;
+import com.google.cloud.dialogflow.cx.v3.StreamingDetectIntentRequest;
+import com.google.cloud.dialogflow.cx.v3.StreamingDetectIntentResponse;
+import com.google.cloud.dialogflow.cx.v3.SynthesizeSpeechConfig;
+import com.google.cloud.dialogflow.cx.v3.VoiceSelectionParams;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+public class DetectIntentStreamingPartialResponse {
+
+ // DialogFlow API Detect Intent sample with audio files
+ // that processes as an audio stream.
+ public static void detectIntentStreamingPartialResponse(
+ String projectId, String locationId, String agentId, String sessionId, String audioFilePath)
+ throws ApiException, IOException {
+ SessionsSettings.Builder sessionsSettingsBuilder = SessionsSettings.newBuilder();
+ if (locationId.equals("global")) {
+ sessionsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
+ } else {
+ sessionsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
+ }
+ SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
+
+ // Instantiates a client by setting the session name.
+ // Format:`projects//locations//agents//sessions/`
+ // Using the same `sessionId` between requests allows continuation of the conversation.
+ try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
+ SessionName session = SessionName.of(projectId, locationId, agentId, sessionId);
+
+ // Instructs the speech recognizer how to process the audio content.
+ // Note: hard coding audioEncoding and sampleRateHertz for simplicity.
+ // Audio encoding of the audio content sent in the query request.
+ InputAudioConfig inputAudioConfig =
+ InputAudioConfig.newBuilder()
+ .setAudioEncoding(AudioEncoding.AUDIO_ENCODING_LINEAR_16)
+ .setSampleRateHertz(16000) // sampleRateHertz = 16000
+ .build();
+
+ // Build the AudioInput with the InputAudioConfig.
+ AudioInput audioInput = AudioInput.newBuilder().setConfig(inputAudioConfig).build();
+
+ // Build the query with the InputAudioConfig.
+ QueryInput queryInput =
+ QueryInput.newBuilder()
+ .setAudio(audioInput)
+ .setLanguageCode("en-US") // languageCode = "en-US"
+ .build();
+
+ // Create the Bidirectional stream
+ BidiStream bidiStream =
+ sessionsClient.streamingDetectIntentCallable().call();
+
+ // Specify sssml name and gender
+ VoiceSelectionParams voiceSelection =
+ // Voices that are available https://cloud.google.com/text-to-speech/docs/voices
+ VoiceSelectionParams.newBuilder()
+ .setName("en-GB-Standard-A")
+ .setSsmlGender(SsmlVoiceGender.SSML_VOICE_GENDER_FEMALE)
+ .build();
+
+ SynthesizeSpeechConfig speechConfig =
+ SynthesizeSpeechConfig.newBuilder().setVoice(voiceSelection).build();
+
+ // Setup audio config
+ OutputAudioConfig audioConfig =
+ // Output encoding explanation
+ // https://cloud.google.com/dialogflow/cx/docs/reference/rpc/google.cloud.dialogflow.cx.v3#outputaudioencoding
+ OutputAudioConfig.newBuilder()
+ .setAudioEncoding(OutputAudioEncoding.OUTPUT_AUDIO_ENCODING_UNSPECIFIED)
+ .setAudioEncodingValue(1)
+ .setSynthesizeSpeechConfig(speechConfig)
+ .build();
+
+ StreamingDetectIntentRequest streamingDetectIntentRequest =
+ StreamingDetectIntentRequest.newBuilder()
+ .setSession(session.toString())
+ .setQueryInput(queryInput)
+ .setEnablePartialResponse(true)
+ .setOutputAudioConfig(audioConfig)
+ .build();
+ System.out.println(streamingDetectIntentRequest.toString());
+
+ // The first request must **only** contain the audio configuration:
+ bidiStream.send(streamingDetectIntentRequest);
+
+ try (FileInputStream audioStream = new FileInputStream(audioFilePath)) {
+ // Subsequent requests must **only** contain the audio data.
+ // Following messages: audio chunks. We just read the file in fixed-size chunks. In reality
+ // you would split the user input by time.
+ byte[] buffer = new byte[4096];
+ int bytes;
+ while ((bytes = audioStream.read(buffer)) != -1) {
+ AudioInput subAudioInput =
+ AudioInput.newBuilder().setAudio(ByteString.copyFrom(buffer, 0, bytes)).build();
+ QueryInput subQueryInput =
+ QueryInput.newBuilder()
+ .setAudio(subAudioInput)
+ .setLanguageCode("en-US") // languageCode = "en-US"
+ .build();
+ bidiStream.send(
+ StreamingDetectIntentRequest.newBuilder().setQueryInput(subQueryInput).build());
+ }
+ }
+
+ // Tell the service you are done sending data.
+ bidiStream.closeSend();
+
+ // TODO: Uncomment to print detectIntentResponse.
+
+ // for (StreamingDetectIntentResponse response : bidiStream) {
+ // QueryResult queryResult = response.getDetectIntentResponse().getQueryResult();
+ // System.out.println("====================");
+ // System.out.format("Query Text: '%s'\n", queryResult.getTranscript());
+ // System.out.format(
+ // "Detected Intent: %s (confidence: %f)\n",
+ // queryResult.getIntent()
+ // .getDisplayName(), queryResult.getIntentDetectionConfidence());
+ // }
+ }
+ }
+}
+// [END dialogflow_cx_v3_detect_intent_streaming_partial_response]
diff --git a/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java
new file mode 100644
index 000000000..d26437eef
--- /dev/null
+++ b/samples/snippets/src/main/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutput.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+// [START dialogflow_cx_v3_detect_intent_synthesize_tts_output]
+
+import com.google.api.gax.rpc.ApiException;
+import com.google.cloud.dialogflow.cx.v3.AudioEncoding;
+import com.google.cloud.dialogflow.cx.v3.AudioInput;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentRequest;
+import com.google.cloud.dialogflow.cx.v3.DetectIntentResponse;
+import com.google.cloud.dialogflow.cx.v3.InputAudioConfig;
+import com.google.cloud.dialogflow.cx.v3.OutputAudioConfig;
+import com.google.cloud.dialogflow.cx.v3.OutputAudioEncoding;
+import com.google.cloud.dialogflow.cx.v3.QueryInput;
+import com.google.cloud.dialogflow.cx.v3.SessionName;
+import com.google.cloud.dialogflow.cx.v3.SessionsClient;
+import com.google.cloud.dialogflow.cx.v3.SessionsSettings;
+import com.google.cloud.dialogflow.cx.v3.SynthesizeSpeechConfig;
+import com.google.protobuf.ByteString;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+public class DetectIntentSynthesizeTextToSpeechOutput {
+
+ // DialogFlow API Detect Intent sample with synthesize TTS output.
+ public static void main(String[] args) throws IOException, ApiException {
+ String projectId = "my-project-id";
+ String locationId = "my-location-id";
+ String agentId = "my-agent-id";
+ String audioFileName = "my-audio-file-name";
+ int sampleRateHertz = 16000;
+ String sessionId = "my-session-id";
+ String languageCode = "my-language-code";
+
+ detectIntent(
+ projectId, locationId, agentId, audioFileName, sampleRateHertz, sessionId, languageCode);
+ }
+
+ public static void detectIntent(
+ String projectId,
+ String locationId,
+ String agentId,
+ String audioFileName,
+ int sampleRateHertz,
+ String sessionId,
+ String languageCode)
+ throws IOException, ApiException {
+
+ SessionsSettings.Builder sessionsSettingsBuilder = SessionsSettings.newBuilder();
+ if (locationId.equals("global")) {
+ sessionsSettingsBuilder.setEndpoint("dialogflow.googleapis.com:443");
+ } else {
+ sessionsSettingsBuilder.setEndpoint(locationId + "-dialogflow.googleapis.com:443");
+ }
+ SessionsSettings sessionsSettings = sessionsSettingsBuilder.build();
+
+ // Instantiates a client by setting the session name.
+ // Format:`projects//locations//agents//sessions/`
+ try (SessionsClient sessionsClient = SessionsClient.create(sessionsSettings)) {
+ SessionName session =
+ SessionName.ofProjectLocationAgentSessionName(projectId, locationId, agentId, sessionId);
+
+ // TODO : Uncomment if you want to print session path
+ // System.out.println("Session Path: " + session.toString());
+ InputAudioConfig inputAudioConfig =
+ InputAudioConfig.newBuilder()
+ .setAudioEncoding(AudioEncoding.AUDIO_ENCODING_LINEAR_16)
+ .setSampleRateHertz(sampleRateHertz)
+ .build();
+
+ try (FileInputStream audioStream = new FileInputStream(audioFileName)) {
+ // Subsequent requests must **only** contain the audio data.
+ // Following messages: audio chunks. We just read the file in fixed-size chunks. In reality
+ // you would split the user input by time.
+ byte[] buffer = new byte[4096];
+ int bytes = audioStream.read(buffer);
+ AudioInput audioInput =
+ AudioInput.newBuilder()
+ .setAudio(ByteString.copyFrom(buffer, 0, bytes))
+ .setConfig(inputAudioConfig)
+ .build();
+ QueryInput queryInput =
+ QueryInput.newBuilder()
+ .setAudio(audioInput)
+ .setLanguageCode("en-US") // languageCode = "en-US"
+ .build();
+
+ SynthesizeSpeechConfig speechConfig =
+ SynthesizeSpeechConfig.newBuilder().setSpeakingRate(1.25).setPitch(10.0).build();
+
+ OutputAudioConfig outputAudioConfig =
+ OutputAudioConfig.newBuilder()
+ .setAudioEncoding(OutputAudioEncoding.OUTPUT_AUDIO_ENCODING_LINEAR_16)
+ .setSynthesizeSpeechConfig(speechConfig)
+ .build();
+
+ DetectIntentRequest request =
+ DetectIntentRequest.newBuilder()
+ .setSession(session.toString())
+ .setQueryInput(queryInput)
+ .setOutputAudioConfig(outputAudioConfig)
+ .build();
+
+ // Performs the detect intent request.
+ DetectIntentResponse response = sessionsClient.detectIntent(request);
+
+ // Display the output audio config retrieved from the response.
+ OutputAudioConfig audioConfigFromResponse = response.getOutputAudioConfig();
+
+ System.out.println("====================");
+ System.out.format("Output Audio Config: %s \n", audioConfigFromResponse.toString());
+ }
+ }
+ }
+}
+// [END dialogflow_cx_v3_detect_intent_synthesize_tts_output]
diff --git a/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java b/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java
index b479c0eb8..69723e127 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/CreateAgentIT.java
@@ -43,7 +43,7 @@ public void setUp() throws IOException {
}
@After
- public void tearDown() throws IOException {
+ public void tearDown() throws IOException, InterruptedException {
System.setOut(originalOut);
String apiEndpoint = "global-dialogflow.googleapis.com:443";
@@ -51,6 +51,9 @@ public void tearDown() throws IOException {
AgentsClient client = AgentsClient.create(agentsSettings);
client.deleteAgent(CreateAgentIT.agentPath);
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
diff --git a/samples/snippets/src/test/java/dialogflow/cx/CreateFlowIT.java b/samples/snippets/src/test/java/dialogflow/cx/CreateFlowIT.java
index 1c9e02135..7bbe9de68 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/CreateFlowIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/CreateFlowIT.java
@@ -68,6 +68,9 @@ public static void tearDown() throws Exception {
try (FlowsClient flowsClient = FlowsClient.create(flowsSettings)) {
flowsClient.deleteFlow(newFlowNameRegional);
}
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/CreateIntentIT.java b/samples/snippets/src/test/java/dialogflow/cx/CreateIntentIT.java
index 9cd42c025..6f317122f 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/CreateIntentIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/CreateIntentIT.java
@@ -70,6 +70,9 @@ public static void tearDown() throws Exception {
intentsClient.deleteIntent(newIntentNameRegional);
}
}
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
@@ -93,7 +96,6 @@ public void testCreateIntentRegional() throws Exception {
CreateIntent.createIntent(
DISPLAY_NAME, PROJECT_ID, LOCATION_REGIONAL, AGENT_ID_REGIONAL, TRAINING_PHRASES_PARTS);
newIntentNameRegional = result.getName();
- System.out.println("intent name new:" + newIntentNameRegional);
assertEquals(result.getTrainingPhrasesCount(), TRAINING_PHRASES_PARTS.size());
for (TrainingPhrase trainingPhrase : result.getTrainingPhrasesList()) {
diff --git a/samples/snippets/src/test/java/dialogflow/cx/CreatePageIT.java b/samples/snippets/src/test/java/dialogflow/cx/CreatePageIT.java
index 649d5a6c8..b392be98c 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/CreatePageIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/CreatePageIT.java
@@ -57,6 +57,9 @@ public static void tearDown() throws Exception {
try (PagesClient pagesClient = PagesClient.create()) {
pagesClient.deletePage(newPageNameGlobal);
}
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
// Delete the newly created Page in the regional location.
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentAudioInputTest.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentAudioInputTest.java
new file mode 100644
index 000000000..ffe361914
--- /dev/null
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentAudioInputTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Unit test for {@link DetectIntentIntentAudioInput}. */
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectIntentAudioInputTest {
+
+ private static String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static String LOCATION = "global";
+ private static String AGENT_ID =
+ System.getenv()
+ .getOrDefault("DIALOGFLOW_CX_AGENT_ID_GLOBAL", "b8d0e85d-0741-4e6d-a66a-3671184b7b93");
+ private static String AUDIO_FILE_NAME = "resources/book_a_room.wav";
+ private static int SAMPLE_RATE_HERTZ = 16000;
+ private static String SESSION_ID = UUID.randomUUID().toString();
+ private static String LANGUAGE_CODE = "en";
+
+ private ByteArrayOutputStream stdOut;
+
+ @Before
+ public void setUp() throws IOException {
+
+ stdOut = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(stdOut));
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ stdOut = null;
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectIntentAudioInput() throws Exception {
+
+ DetectIntentAudioInput.detectIntent(
+ PROJECT_ID,
+ LOCATION,
+ AGENT_ID,
+ AUDIO_FILE_NAME,
+ SAMPLE_RATE_HERTZ,
+ SESSION_ID,
+ LANGUAGE_CODE);
+ System.out.println(stdOut.toString());
+ assertThat(stdOut.toString()).contains("Detected Intent:");
+ }
+}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentDisableWebhookTest.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentDisableWebhookTest.java
new file mode 100644
index 000000000..3564ed1cc
--- /dev/null
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentDisableWebhookTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.cloud.dialogflow.cx.v3.QueryResult;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Unit test for {@link DetectIntentDisableWebhook}. */
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectIntentDisableWebhookTest {
+
+ private static String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static String LOCATION = "global";
+ private static String AGENT_ID =
+ System.getenv()
+ .getOrDefault("DIALOGFLOW_CX_AGENT_ID_GLOBAL", "b8d0e85d-0741-4e6d-a66a-3671184b7b93");
+ private static String SESSION_ID = UUID.randomUUID().toString();
+ private static String LANGUAGE_CODE = "en-US";
+ private static List TEXTS = Arrays.asList("hello", "unhappy");
+
+ private ByteArrayOutputStream stdOut;
+
+ @Before
+ public void setUp() throws IOException {
+
+ stdOut = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(stdOut));
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ stdOut = null;
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectIntentDisableWebhook() throws Exception {
+ Map queryResults =
+ DetectIntentDisableWebhook.detectIntent(
+ PROJECT_ID, LOCATION, AGENT_ID, SESSION_ID, TEXTS, LANGUAGE_CODE);
+
+ for (int i = 0; i < TEXTS.size(); i++) {
+ String text = TEXTS.get(i);
+ float score = queryResults.get(text).getSentimentAnalysisResult().getScore();
+ System.out.println(stdOut.toString());
+ assertThat(stdOut.toString()).contains("disable_webhook");
+ }
+ }
+}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentEventInputTest.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentEventInputTest.java
new file mode 100644
index 000000000..f63625194
--- /dev/null
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentEventInputTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Unit test for {@link DetectIntentEventInput}. */
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectIntentEventInputTest {
+
+ private static String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static String LOCATION = "global";
+ private static String AGENT_ID =
+ System.getenv()
+ .getOrDefault("DIALOGFLOW_CX_AGENT_ID_GLOBAL", "b8d0e85d-0741-4e6d-a66a-3671184b7b93");
+ private static String EVENT = "sys.no-match-default";
+ private static String SESSION_ID = UUID.randomUUID().toString();
+ private static String LANGUAGE_CODE = "en-US";
+
+ private ByteArrayOutputStream stdOut;
+
+ @Before
+ public void setUp() throws IOException {
+
+ stdOut = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(stdOut));
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ stdOut = null;
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectIntentEventInput() throws Exception {
+ String triggeringEvent = "sys.no-match-default";
+
+ DetectIntentEventInput.detectIntent(
+ PROJECT_ID, LOCATION, AGENT_ID, SESSION_ID, EVENT, LANGUAGE_CODE);
+ System.out.println(stdOut.toString());
+ assertThat(stdOut.toString()).contains(triggeringEvent);
+ }
+}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentIT.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentIT.java
index bf0e300a7..66d356a9b 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentIT.java
@@ -23,11 +23,12 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Integration (system) tests for {@link DetectIntent}. */
+/** Integration (system) tests for {@link DetectIntentText}. */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class DetectIntentIT {
@@ -45,6 +46,12 @@ public class DetectIntentIT {
private static String LANGUAGE_CODE = "en-US";
private static List TEXTS = Arrays.asList("hello", "book a meeting room");
+ @After
+ public void tearDown() throws InterruptedException {
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
+ }
+
@Test
public void testDetectIntentGlobal() throws Exception {
Map queryResults =
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentIntentInputTest.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentIntentInputTest.java
new file mode 100644
index 000000000..51dc3a560
--- /dev/null
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentIntentInputTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Unit test for {@link DetectIntentIntentInput}. */
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectIntentIntentInputTest {
+
+ private static String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static String LOCATION = "global";
+ private static String AGENT_ID =
+ System.getenv()
+ .getOrDefault("DIALOGFLOW_CX_AGENT_ID_GLOBAL", "b8d0e85d-0741-4e6d-a66a-3671184b7b93");
+ private static String INTENT_ID = "00000000-0000-0000-0000-000000000000";
+ private static String SESSION_ID = UUID.randomUUID().toString();
+ private static String LANGUAGE_CODE = "en-US";
+ private static String INTENT =
+ "projects/"
+ + PROJECT_ID
+ + "/locations/"
+ + LOCATION
+ + "/agents/"
+ + AGENT_ID
+ + "/intents/"
+ + INTENT_ID;
+
+ private ByteArrayOutputStream stdOut;
+
+ @Before
+ public void setUp() throws IOException {
+
+ stdOut = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(stdOut));
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ stdOut = null;
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectIntentIntentInput() throws Exception {
+ String intentName = "Default Welcome Intent";
+
+ DetectIntentIntentInput.detectIntent(
+ PROJECT_ID, LOCATION, AGENT_ID, SESSION_ID, INTENT, LANGUAGE_CODE);
+ System.out.println(stdOut.toString());
+ assertThat(stdOut.toString()).contains(intentName);
+ }
+}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentSentimentAnalysisTest.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentSentimentAnalysisTest.java
new file mode 100644
index 000000000..2194a9e70
--- /dev/null
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentSentimentAnalysisTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+import static org.junit.Assert.assertTrue;
+
+import com.google.cloud.dialogflow.cx.v3.QueryResult;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.junit.Test;
+
+/** Unit test for {@link DetectIntentSentimentAnalysis}. */
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectIntentSentimentAnalysisTest {
+
+ private static String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static String LOCATION = "global";
+ private static String AGENT_ID =
+ System.getenv()
+ .getOrDefault("DIALOGFLOW_CX_AGENT_ID_GLOBAL", "b8d0e85d-0741-4e6d-a66a-3671184b7b93");
+ private static String SESSION_ID = UUID.randomUUID().toString();
+ private static String LANGUAGE_CODE = "en-US";
+ private static List TEXTS = Arrays.asList("hello", "unhappy");
+
+ @Test
+ public void testDetectIntentSentimentAnalysis() throws Exception {
+ int min = -1;
+ int max = 1;
+
+ Map queryResults =
+ DetectIntentSentimentAnalysis.detectIntent(
+ PROJECT_ID, LOCATION, AGENT_ID, SESSION_ID, TEXTS, LANGUAGE_CODE);
+
+ for (int i = 0; i < TEXTS.size(); i++) {
+ String text = TEXTS.get(i);
+ float score = queryResults.get(text).getSentimentAnalysisResult().getScore();
+ assertTrue(min <= score && score <= max);
+ }
+ }
+}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentStreamIT.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentStreamIT.java
index 4ef71b0ed..b941420f0 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentStreamIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentStreamIT.java
@@ -55,9 +55,12 @@ public void setUp() {
}
@After
- public void tearDown() {
+ public void tearDown() throws InterruptedException {
System.setOut(original);
bout.reset();
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentStreamingPartialResponseTest.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentStreamingPartialResponseTest.java
new file mode 100644
index 000000000..7f6f24a2e
--- /dev/null
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentStreamingPartialResponseTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Integration (system) tests for {@link DetectIntentStream}. */
+@RunWith(JUnit4.class)
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectIntentStreamingPartialResponseTest {
+
+ private static String AUDIO_FILE_PATH = "resources/book_a_room.wav";
+ private static String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static String LOCATION = "global";
+ private static String AGENT_ID =
+ System.getenv()
+ .getOrDefault("DIALOGFLOW_CX_AGENT_ID_GLOBAL", "b8d0e85d-0741-4e6d-a66a-3671184b7b93");
+ private static String SESSION_ID = UUID.randomUUID().toString();
+ private ByteArrayOutputStream bout;
+ private PrintStream original;
+
+ @Before
+ public void setUp() {
+ original = System.out;
+ bout = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(bout));
+ }
+
+ @After
+ public void tearDown() {
+ System.setOut(original);
+ bout.reset();
+ }
+
+ @Test
+ public void testDetectIntentStreamingPartialResponse() throws IOException {
+ DetectIntentStreamingPartialResponse.detectIntentStreamingPartialResponse(
+ PROJECT_ID, LOCATION, AGENT_ID, SESSION_ID, AUDIO_FILE_PATH);
+
+ String output = bout.toString();
+
+ assertThat(output).contains("enable_partial_response");
+ }
+}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutputTest.java b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutputTest.java
new file mode 100644
index 000000000..20d84e37a
--- /dev/null
+++ b/samples/snippets/src/test/java/dialogflow/cx/DetectIntentSynthesizeTextToSpeechOutputTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dialogflow.cx;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Unit test for {@link DetectIntentSynthesizeTtSOutput}. */
+@SuppressWarnings("checkstyle:abbreviationaswordinname")
+public class DetectIntentSynthesizeTextToSpeechOutputTest {
+
+ private static String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
+ private static String LOCATION = "global";
+ private static String AGENT_ID =
+ System.getenv()
+ .getOrDefault("DIALOGFLOW_CX_AGENT_ID_GLOBAL", "b8d0e85d-0741-4e6d-a66a-3671184b7b93");
+ private static String AUDIO_FILE_NAME = "resources/book_a_room.wav";
+ private static int SAMPLE_RATE_HERTZ = 16000;
+ private static String SESSION_ID = UUID.randomUUID().toString();
+ private static String LANGUAGE_CODE = "en";
+
+ private ByteArrayOutputStream stdOut;
+
+ @Before
+ public void setUp() throws IOException {
+
+ stdOut = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(stdOut));
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ stdOut = null;
+ System.setOut(null);
+ }
+
+ @Test
+ public void testDetectIntentSynthesizeTextToSpeechOutput() throws Exception {
+
+ DetectIntentSynthesizeTextToSpeechOutput.detectIntent(
+ PROJECT_ID,
+ LOCATION,
+ AGENT_ID,
+ AUDIO_FILE_NAME,
+ SAMPLE_RATE_HERTZ,
+ SESSION_ID,
+ LANGUAGE_CODE);
+ System.out.println(stdOut.toString());
+ assertThat(stdOut.toString()).contains("speaking_rate");
+ }
+}
diff --git a/samples/snippets/src/test/java/dialogflow/cx/ExportAgentIT.java b/samples/snippets/src/test/java/dialogflow/cx/ExportAgentIT.java
index 018ad2760..e499fe726 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/ExportAgentIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/ExportAgentIT.java
@@ -71,7 +71,7 @@ public void setUp() throws IOException {
}
@After
- public void tearDown() throws IOException {
+ public void tearDown() throws IOException, InterruptedException {
stdOut = null;
System.setOut(null);
String apiEndpoint = "global-dialogflow.googleapis.com:443";
@@ -81,6 +81,9 @@ public void tearDown() throws IOException {
client.deleteAgent(ExportAgentIT.agentPath);
client.close();
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
diff --git a/samples/snippets/src/test/java/dialogflow/cx/ListTestCaseResultsIT.java b/samples/snippets/src/test/java/dialogflow/cx/ListTestCaseResultsIT.java
index 57a7fd32c..2214356f1 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/ListTestCaseResultsIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/ListTestCaseResultsIT.java
@@ -43,8 +43,11 @@ public void setUp() throws IOException {
}
@After
- public void tearDown() throws IOException {
+ public void tearDown() throws IOException, InterruptedException {
System.setOut(originalOut);
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
diff --git a/samples/snippets/src/test/java/dialogflow/cx/ListTrainingPhrasesTest.java b/samples/snippets/src/test/java/dialogflow/cx/ListTrainingPhrasesTest.java
index e0f528560..347b39804 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/ListTrainingPhrasesTest.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/ListTrainingPhrasesTest.java
@@ -40,9 +40,12 @@ public void setUp() throws IOException {
}
@After
- public void tearDown() throws IOException {
+ public void tearDown() throws IOException, InterruptedException {
stdOut = null;
System.setOut(null);
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
diff --git a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java
index d0e8fac93..ab1b2ca60 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/PageManagementIT.java
@@ -65,7 +65,7 @@ public static void setUp() throws IOException {
}
@AfterClass
- public static void tearDown() throws IOException {
+ public static void tearDown() throws IOException, InterruptedException {
String apiEndpoint = "global-dialogflow.googleapis.com:443";
String parentPath = "projects/" + PROJECT_ID + "/locations/global";
@@ -73,6 +73,9 @@ public static void tearDown() throws IOException {
AgentsClient client = AgentsClient.create(agentsSettings);
client.deleteAgent(parent);
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
diff --git a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java
index bb210fa2d..0443ec40c 100644
--- a/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java
+++ b/samples/snippets/src/test/java/dialogflow/cx/UpdateIntentTest.java
@@ -74,7 +74,7 @@ public void setUp() throws IOException {
}
@After
- public void tearDown() throws IOException {
+ public void tearDown() throws IOException, InterruptedException {
stdOut = null;
System.setOut(null);
String apiEndpoint = "global-dialogflow.googleapis.com:443";
@@ -84,6 +84,9 @@ public void tearDown() throws IOException {
AgentsClient client = AgentsClient.create(agentsSettings);
client.deleteAgent(parent);
+
+ // Small delay to prevent reaching quota limit of requests per minute
+ Thread.sleep(250);
}
@Test
diff --git a/versions.txt b/versions.txt
index bf53befe0..83ea41e1d 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,8 +1,8 @@
# Format:
# module:released-version:current-version
-google-cloud-dialogflow-cx:0.14.0:0.14.0
-grpc-google-cloud-dialogflow-cx-v3beta1:0.14.0:0.14.0
-grpc-google-cloud-dialogflow-cx-v3:0.14.0:0.14.0
-proto-google-cloud-dialogflow-cx-v3beta1:0.14.0:0.14.0
-proto-google-cloud-dialogflow-cx-v3:0.14.0:0.14.0
+google-cloud-dialogflow-cx:0.14.1:0.14.1
+grpc-google-cloud-dialogflow-cx-v3beta1:0.14.1:0.14.1
+grpc-google-cloud-dialogflow-cx-v3:0.14.1:0.14.1
+proto-google-cloud-dialogflow-cx-v3beta1:0.14.1:0.14.1
+proto-google-cloud-dialogflow-cx-v3:0.14.1:0.14.1