Google Cloud Dialogflow v2 API - Class SessionsClient (4.18.0)

public abstract class SessionsClient

Reference documentation and code samples for the Google Cloud Dialogflow v2 API class SessionsClient.

Sessions client wrapper, for convenient use.

Inheritance

object > SessionsClient

Derived Types

Namespace

Google.Cloud.Dialogflow.V2

Assembly

Google.Cloud.Dialogflow.V2.dll

Remarks

A service used for session interactions.

For more information, see the API interactions guide.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the Sessions service, which is a host of "dialogflow.googleapis.com" and a port of 443.

Property Value
Type Description
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default Sessions scopes.

Property Value
Type Description
IReadOnlyListstring
Remarks

GrpcClient

public virtual Sessions.SessionsClient GrpcClient { get; }

The underlying gRPC Sessions client

Property Value
Type Description
SessionsSessionsClient

LocationsClient

public virtual LocationsClient LocationsClient { get; }

The LocationsClient associated with this client.

Property Value
Type Description
LocationsClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
Type Description
ServiceMetadata

Methods

Create()

public static SessionsClient Create()

Synchronously creates a SessionsClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use SessionsClientBuilder.

Returns
Type Description
SessionsClient

The created SessionsClient.

CreateAsync(CancellationToken)

public static Task<SessionsClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a SessionsClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use SessionsClientBuilder.

Parameter
Name Description
cancellationToken CancellationToken

The CancellationToken to use while creating the client.

Returns
Type Description
TaskSessionsClient

The task representing the created SessionsClient.

DetectIntent(DetectIntentRequest, CallSettings)

public virtual DetectIntentResponse DetectIntent(DetectIntentRequest request, CallSettings callSettings = null)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
request DetectIntentRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
DetectIntentResponse

The RPC response.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize request argument(s)
DetectIntentRequest request = new DetectIntentRequest
{
    SessionAsSessionName = SessionName.FromProjectSession("[PROJECT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    OutputAudioConfig = new OutputAudioConfig(),
    InputAudio = ByteString.Empty,
    OutputAudioConfigMask = new FieldMask(),
};
// Make the request
DetectIntentResponse response = sessionsClient.DetectIntent(request);

DetectIntent(SessionName, QueryInput, CallSettings)

public virtual DetectIntentResponse DetectIntent(SessionName session, QueryInput queryInput, CallSettings callSettings = null)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
session SessionName

Required. The name of the session this query is sent to. Format: projects/<Project ID>/agent/sessions/<Session ID>, or projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>. If Environment ID is not specified, we assume default 'draft' environment (Environment ID might be referred to as environment name at some places). If User ID is not specified, we are using "-". It's up to the API caller to choose an appropriate Session ID and User Id. They can be a random number or some type of user and session identifiers (preferably hashed). The length of the Session ID and User ID must not exceed 36 characters.

For more information, see the API interactions guide.

Note: Always use agent versions for production traffic. See Versions and environments.

queryInput 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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
DetectIntentResponse

The RPC response.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize request argument(s)
SessionName session = SessionName.FromProjectSession("[PROJECT]", "[SESSION]");
QueryInput queryInput = new QueryInput();
// Make the request
DetectIntentResponse response = sessionsClient.DetectIntent(session, queryInput);

DetectIntent(string, QueryInput, CallSettings)

public virtual DetectIntentResponse DetectIntent(string session, QueryInput queryInput, CallSettings callSettings = null)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
session string

Required. The name of the session this query is sent to. Format: projects/<Project ID>/agent/sessions/<Session ID>, or projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>. If Environment ID is not specified, we assume default 'draft' environment (Environment ID might be referred to as environment name at some places). If User ID is not specified, we are using "-". It's up to the API caller to choose an appropriate Session ID and User Id. They can be a random number or some type of user and session identifiers (preferably hashed). The length of the Session ID and User ID must not exceed 36 characters.

For more information, see the API interactions guide.

Note: Always use agent versions for production traffic. See Versions and environments.

queryInput 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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
DetectIntentResponse

The RPC response.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize request argument(s)
string session = "projects/[PROJECT]/agent/sessions/[SESSION]";
QueryInput queryInput = new QueryInput();
// Make the request
DetectIntentResponse response = sessionsClient.DetectIntent(session, queryInput);

DetectIntentAsync(DetectIntentRequest, CallSettings)

public virtual Task<DetectIntentResponse> DetectIntentAsync(DetectIntentRequest request, CallSettings callSettings = null)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
request DetectIntentRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskDetectIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
DetectIntentRequest request = new DetectIntentRequest
{
    SessionAsSessionName = SessionName.FromProjectSession("[PROJECT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    OutputAudioConfig = new OutputAudioConfig(),
    InputAudio = ByteString.Empty,
    OutputAudioConfigMask = new FieldMask(),
};
// Make the request
DetectIntentResponse response = await sessionsClient.DetectIntentAsync(request);

DetectIntentAsync(DetectIntentRequest, CancellationToken)

public virtual Task<DetectIntentResponse> DetectIntentAsync(DetectIntentRequest request, CancellationToken cancellationToken)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
request DetectIntentRequest

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskDetectIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
DetectIntentRequest request = new DetectIntentRequest
{
    SessionAsSessionName = SessionName.FromProjectSession("[PROJECT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    OutputAudioConfig = new OutputAudioConfig(),
    InputAudio = ByteString.Empty,
    OutputAudioConfigMask = new FieldMask(),
};
// Make the request
DetectIntentResponse response = await sessionsClient.DetectIntentAsync(request);

DetectIntentAsync(SessionName, QueryInput, CallSettings)

public virtual Task<DetectIntentResponse> DetectIntentAsync(SessionName session, QueryInput queryInput, CallSettings callSettings = null)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
session SessionName

Required. The name of the session this query is sent to. Format: projects/<Project ID>/agent/sessions/<Session ID>, or projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>. If Environment ID is not specified, we assume default 'draft' environment (Environment ID might be referred to as environment name at some places). If User ID is not specified, we are using "-". It's up to the API caller to choose an appropriate Session ID and User Id. They can be a random number or some type of user and session identifiers (preferably hashed). The length of the Session ID and User ID must not exceed 36 characters.

For more information, see the API interactions guide.

Note: Always use agent versions for production traffic. See Versions and environments.

queryInput 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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskDetectIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
SessionName session = SessionName.FromProjectSession("[PROJECT]", "[SESSION]");
QueryInput queryInput = new QueryInput();
// Make the request
DetectIntentResponse response = await sessionsClient.DetectIntentAsync(session, queryInput);

DetectIntentAsync(SessionName, QueryInput, CancellationToken)

public virtual Task<DetectIntentResponse> DetectIntentAsync(SessionName session, QueryInput queryInput, CancellationToken cancellationToken)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
session SessionName

Required. The name of the session this query is sent to. Format: projects/<Project ID>/agent/sessions/<Session ID>, or projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>. If Environment ID is not specified, we assume default 'draft' environment (Environment ID might be referred to as environment name at some places). If User ID is not specified, we are using "-". It's up to the API caller to choose an appropriate Session ID and User Id. They can be a random number or some type of user and session identifiers (preferably hashed). The length of the Session ID and User ID must not exceed 36 characters.

For more information, see the API interactions guide.

Note: Always use agent versions for production traffic. See Versions and environments.

queryInput 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.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskDetectIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
SessionName session = SessionName.FromProjectSession("[PROJECT]", "[SESSION]");
QueryInput queryInput = new QueryInput();
// Make the request
DetectIntentResponse response = await sessionsClient.DetectIntentAsync(session, queryInput);

DetectIntentAsync(string, QueryInput, CallSettings)

public virtual Task<DetectIntentResponse> DetectIntentAsync(string session, QueryInput queryInput, CallSettings callSettings = null)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
session string

Required. The name of the session this query is sent to. Format: projects/<Project ID>/agent/sessions/<Session ID>, or projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>. If Environment ID is not specified, we assume default 'draft' environment (Environment ID might be referred to as environment name at some places). If User ID is not specified, we are using "-". It's up to the API caller to choose an appropriate Session ID and User Id. They can be a random number or some type of user and session identifiers (preferably hashed). The length of the Session ID and User ID must not exceed 36 characters.

For more information, see the API interactions guide.

Note: Always use agent versions for production traffic. See Versions and environments.

queryInput 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.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskDetectIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
string session = "projects/[PROJECT]/agent/sessions/[SESSION]";
QueryInput queryInput = new QueryInput();
// Make the request
DetectIntentResponse response = await sessionsClient.DetectIntentAsync(session, queryInput);

DetectIntentAsync(string, QueryInput, CancellationToken)

public virtual Task<DetectIntentResponse> DetectIntentAsync(string session, QueryInput queryInput, CancellationToken cancellationToken)

Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause contexts and session entity types to be updated, which in turn might affect results of future queries.

If you might use Agent Assist or other CCAI products now or in the future, consider using [AnalyzeContent][google.cloud.dialogflow.v2.Participants.AnalyzeContent] instead of DetectIntent. AnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
session string

Required. The name of the session this query is sent to. Format: projects/<Project ID>/agent/sessions/<Session ID>, or projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>. If Environment ID is not specified, we assume default 'draft' environment (Environment ID might be referred to as environment name at some places). If User ID is not specified, we are using "-". It's up to the API caller to choose an appropriate Session ID and User Id. They can be a random number or some type of user and session identifiers (preferably hashed). The length of the Session ID and User ID must not exceed 36 characters.

For more information, see the API interactions guide.

Note: Always use agent versions for production traffic. See Versions and environments.

queryInput 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.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskDetectIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
string session = "projects/[PROJECT]/agent/sessions/[SESSION]";
QueryInput queryInput = new QueryInput();
// Make the request
DetectIntentResponse response = await sessionsClient.DetectIntentAsync(session, queryInput);

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
Type Description
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.

StreamingDetectIntent(CallSettings, BidirectionalStreamingSettings)

public virtual SessionsClient.StreamingDetectIntentStream StreamingDetectIntent(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Processes a natural language query in audio format in a streaming fashion and returns structured, actionable data as a result. This method is only available via the gRPC API (not REST).

If you might use Agent Assist or other CCAI products now or in the future, consider using [StreamingAnalyzeContent][google.cloud.dialogflow.v2.Participants.StreamingAnalyzeContent] instead of StreamingDetectIntent. StreamingAnalyzeContent has additional functionality for Agent Assist and other CCAI products.

Note: Always use agent versions for production traffic. See Versions and environments.

Parameters
Name Description
callSettings CallSettings

If not null, applies overrides to this RPC call.

streamingSettings BidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
Type Description
SessionsClientStreamingDetectIntentStream

The client-server stream.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize streaming call, retrieving the stream object
using SessionsClient.StreamingDetectIntentStream response = sessionsClient.StreamingDetectIntent();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<StreamingDetectIntentResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        StreamingDetectIntentResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    StreamingDetectIntentRequest request = new StreamingDetectIntentRequest
    {
        SessionAsSessionName = SessionName.FromProjectSession("[PROJECT]", "[SESSION]"),
        QueryParams = new QueryParameters(),
        QueryInput = new QueryInput(),
        OutputAudioConfig = new OutputAudioConfig(),
        InputAudio = ByteString.Empty,
        OutputAudioConfigMask = new FieldMask(),
        EnableDebuggingInfo = false,
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;