• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.dialogflow.cx.v3beta1.samples;
18 
19 // [START dialogflow_v3beta1_generated_Sessions_StreamingDetectIntent_async]
20 import com.google.api.gax.rpc.BidiStream;
21 import com.google.cloud.dialogflow.cx.v3beta1.OutputAudioConfig;
22 import com.google.cloud.dialogflow.cx.v3beta1.QueryInput;
23 import com.google.cloud.dialogflow.cx.v3beta1.QueryParameters;
24 import com.google.cloud.dialogflow.cx.v3beta1.SessionName;
25 import com.google.cloud.dialogflow.cx.v3beta1.SessionsClient;
26 import com.google.cloud.dialogflow.cx.v3beta1.StreamingDetectIntentRequest;
27 import com.google.cloud.dialogflow.cx.v3beta1.StreamingDetectIntentResponse;
28 
29 public class AsyncStreamingDetectIntent {
30 
main(String[] args)31   public static void main(String[] args) throws Exception {
32     asyncStreamingDetectIntent();
33   }
34 
asyncStreamingDetectIntent()35   public static void asyncStreamingDetectIntent() throws Exception {
36     // This snippet has been automatically generated and should be regarded as a code template only.
37     // It will require modifications to work:
38     // - It may require correct/in-range values for request initialization.
39     // - It may require specifying regional endpoints when creating the service client as shown in
40     // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
41     try (SessionsClient sessionsClient = SessionsClient.create()) {
42       BidiStream<StreamingDetectIntentRequest, StreamingDetectIntentResponse> bidiStream =
43           sessionsClient.streamingDetectIntentCallable().call();
44       StreamingDetectIntentRequest request =
45           StreamingDetectIntentRequest.newBuilder()
46               .setSession(
47                   SessionName.ofProjectLocationAgentSessionName(
48                           "[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]")
49                       .toString())
50               .setQueryParams(QueryParameters.newBuilder().build())
51               .setQueryInput(QueryInput.newBuilder().build())
52               .setOutputAudioConfig(OutputAudioConfig.newBuilder().build())
53               .setEnablePartialResponse(true)
54               .setEnableDebuggingInfo(true)
55               .build();
56       bidiStream.send(request);
57       for (StreamingDetectIntentResponse response : bidiStream) {
58         // Do something when a response is received.
59       }
60     }
61   }
62 }
63 // [END dialogflow_v3beta1_generated_Sessions_StreamingDetectIntent_async]
64