@Generated(value="by gapic-generator") @BetaApi public class SessionsClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (SessionsClient sessionsClient = SessionsClient.create()) {
SessionName session = SessionName.of("[PROJECT]", "[SESSION]");
QueryInput queryInput = QueryInput.newBuilder().build();
DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput);
}
Note: close() needs to be called on the sessionsClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SessionsSettings to create(). For example:
To customize credentials:
SessionsSettings sessionsSettings =
SessionsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SessionsClient sessionsClient =
SessionsClient.create(sessionsSettings);
To customize the endpoint:
SessionsSettings sessionsSettings =
SessionsSettings.newBuilder().setEndpoint(myEndpoint).build();
SessionsClient sessionsClient =
SessionsClient.create(sessionsSettings);
Modifier | Constructor and Description |
---|---|
protected |
SessionsClient(SessionsSettings settings)
Constructs an instance of SessionsClient, using the given settings.
|
protected |
SessionsClient(SessionsStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static SessionsClient |
create()
Constructs an instance of SessionsClient with default settings.
|
static SessionsClient |
create(SessionsSettings settings)
Constructs an instance of SessionsClient, using the given settings.
|
static SessionsClient |
create(SessionsStub stub)
Constructs an instance of SessionsClient, using the given stub for making calls.
|
com.google.cloud.dialogflow.v2.DetectIntentResponse |
detectIntent(com.google.cloud.dialogflow.v2.DetectIntentRequest request)
Processes a natural language query and returns structured, actionable data as a result.
|
com.google.cloud.dialogflow.v2.DetectIntentResponse |
detectIntent(com.google.cloud.dialogflow.v2.SessionName session,
com.google.cloud.dialogflow.v2.QueryInput queryInput)
Processes a natural language query and returns structured, actionable data as a result.
|
com.google.cloud.dialogflow.v2.DetectIntentResponse |
detectIntent(String session,
com.google.cloud.dialogflow.v2.QueryInput queryInput)
Processes a natural language query and returns structured, actionable data as a result.
|
UnaryCallable<com.google.cloud.dialogflow.v2.DetectIntentRequest,com.google.cloud.dialogflow.v2.DetectIntentResponse> |
detectIntentCallable()
Processes a natural language query and returns structured, actionable data as a result.
|
SessionsSettings |
getSettings() |
SessionsStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
void |
shutdownNow() |
BidiStreamingCallable<com.google.cloud.dialogflow.v2.StreamingDetectIntentRequest,com.google.cloud.dialogflow.v2.StreamingDetectIntentResponse> |
streamingDetectIntentCallable()
Processes a natural language query in audio format in a streaming fashion and returns
structured, actionable data as a result.
|
protected SessionsClient(SessionsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected SessionsClient(SessionsStub stub)
public static final SessionsClient create() throws IOException
IOException
public static final SessionsClient create(SessionsSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final SessionsClient create(SessionsStub stub)
public final SessionsSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public SessionsStub getStub()
public final com.google.cloud.dialogflow.v2.DetectIntentResponse detectIntent(com.google.cloud.dialogflow.v2.SessionName session, com.google.cloud.dialogflow.v2.QueryInput queryInput)
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
SessionName session = SessionName.of("[PROJECT]", "[SESSION]");
QueryInput queryInput = QueryInput.newBuilder().build();
DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput);
}
session
- Required. The name of the session this query is sent to. Format:
`projects/<Project ID>/agent/sessions/<Session ID>`. It's up to the API caller
to choose an appropriate session ID. It can be a random number or some type of user
identifier (preferably hashed). The length of the session ID must not exceed 36 bytes.queryInput
- Required. The input specification. It can be set to:
1. an audio config which instructs the speech recognizer how to process the speech audio,
2. a conversational query in the form of text, or
3. an event that specifies which intent to trigger.
ApiException
- if the remote call failspublic final com.google.cloud.dialogflow.v2.DetectIntentResponse detectIntent(String session, com.google.cloud.dialogflow.v2.QueryInput queryInput)
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
SessionName session = SessionName.of("[PROJECT]", "[SESSION]");
QueryInput queryInput = QueryInput.newBuilder().build();
DetectIntentResponse response = sessionsClient.detectIntent(session.toString(), queryInput);
}
session
- Required. The name of the session this query is sent to. Format:
`projects/<Project ID>/agent/sessions/<Session ID>`. It's up to the API caller
to choose an appropriate session ID. It can be a random number or some type of user
identifier (preferably hashed). The length of the session ID must not exceed 36 bytes.queryInput
- Required. The input specification. It can be set to:
1. an audio config which instructs the speech recognizer how to process the speech audio,
2. a conversational query in the form of text, or
3. an event that specifies which intent to trigger.
ApiException
- if the remote call failspublic final com.google.cloud.dialogflow.v2.DetectIntentResponse detectIntent(com.google.cloud.dialogflow.v2.DetectIntentRequest request)
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
SessionName session = SessionName.of("[PROJECT]", "[SESSION]");
QueryInput queryInput = QueryInput.newBuilder().build();
DetectIntentRequest request = DetectIntentRequest.newBuilder()
.setSession(session.toString())
.setQueryInput(queryInput)
.build();
DetectIntentResponse response = sessionsClient.detectIntent(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.dialogflow.v2.DetectIntentRequest,com.google.cloud.dialogflow.v2.DetectIntentResponse> detectIntentCallable()
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
SessionName session = SessionName.of("[PROJECT]", "[SESSION]");
QueryInput queryInput = QueryInput.newBuilder().build();
DetectIntentRequest request = DetectIntentRequest.newBuilder()
.setSession(session.toString())
.setQueryInput(queryInput)
.build();
ApiFuture<DetectIntentResponse> future = sessionsClient.detectIntentCallable().futureCall(request);
// Do something
DetectIntentResponse response = future.get();
}
public final BidiStreamingCallable<com.google.cloud.dialogflow.v2.StreamingDetectIntentRequest,com.google.cloud.dialogflow.v2.StreamingDetectIntentResponse> streamingDetectIntentCallable()
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
BidiStream<StreamingDetectIntentRequest, StreamingDetectIntentResponse> bidiStream =
sessionsClient.streamingDetectIntentCallable().call();
String session = "";
QueryInput queryInput = QueryInput.newBuilder().build();
StreamingDetectIntentRequest request = StreamingDetectIntentRequest.newBuilder()
.setSession(session)
.setQueryInput(queryInput)
.build();
bidiStream.send(request);
for (StreamingDetectIntentResponse response : bidiStream) {
// Do something when receive a response
}
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.