Dialogflow v3 API - Class SessionsClient (2.7.0)

public abstract class SessionsClient

Reference documentation and code samples for the Dialogflow v3 API class SessionsClient.

Sessions client wrapper, for convenient use.

Inheritance

object > SessionsClient

Derived Types

Namespace

Google.Cloud.Dialogflow.Cx.V3

Assembly

Google.Cloud.Dialogflow.Cx.V3.dll

Remarks

A session represents an interaction with a user. You retrieve user input and pass it to the [DetectIntent][google.cloud.dialogflow.cx.v3.Sessions.DetectIntent] method to determine user intent and respond.

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
TypeDescription
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default Sessions scopes.

Property Value
TypeDescription
IReadOnlyListstring
Remarks

GrpcClient

public virtual Sessions.SessionsClient GrpcClient { get; }

The underlying gRPC Sessions client

Property Value
TypeDescription
SessionsSessionsClient

LocationsClient

public virtual LocationsClient LocationsClient { get; }

The LocationsClient associated with this client.

Property Value
TypeDescription
LocationsClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
TypeDescription
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
TypeDescription
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
NameDescription
cancellationTokenCancellationToken

The CancellationToken to use while creating the client.

Returns
TypeDescription
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 session entity types to be updated, which in turn might affect results of future queries.

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

Parameters
NameDescription
requestDetectIntentRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
DetectIntentResponse

The RPC response.

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

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 session entity types to be updated, which in turn might affect results of future queries.

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

Parameters
NameDescription
requestDetectIntentRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
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.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    OutputAudioConfig = new OutputAudioConfig(),
};
// 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 session entity types to be updated, which in turn might affect results of future queries.

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

Parameters
NameDescription
requestDetectIntentRequest

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

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
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.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    OutputAudioConfig = new OutputAudioConfig(),
};
// Make the request
DetectIntentResponse response = await sessionsClient.DetectIntentAsync(request);

FulfillIntent(FulfillIntentRequest, CallSettings)

public virtual FulfillIntentResponse FulfillIntent(FulfillIntentRequest request, CallSettings callSettings = null)

Fulfills a matched intent returned by [MatchIntent][google.cloud.dialogflow.cx.v3.Sessions.MatchIntent]. Must be called after [MatchIntent][google.cloud.dialogflow.cx.v3.Sessions.MatchIntent], with input from [MatchIntentResponse][google.cloud.dialogflow.cx.v3.MatchIntentResponse]. Otherwise, the behavior is undefined.

Parameters
NameDescription
requestFulfillIntentRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
FulfillIntentResponse

The RPC response.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize request argument(s)
FulfillIntentRequest request = new FulfillIntentRequest
{
    MatchIntentRequest = new MatchIntentRequest(),
    Match = new Match(),
    OutputAudioConfig = new OutputAudioConfig(),
};
// Make the request
FulfillIntentResponse response = sessionsClient.FulfillIntent(request);

FulfillIntentAsync(FulfillIntentRequest, CallSettings)

public virtual Task<FulfillIntentResponse> FulfillIntentAsync(FulfillIntentRequest request, CallSettings callSettings = null)

Fulfills a matched intent returned by [MatchIntent][google.cloud.dialogflow.cx.v3.Sessions.MatchIntent]. Must be called after [MatchIntent][google.cloud.dialogflow.cx.v3.Sessions.MatchIntent], with input from [MatchIntentResponse][google.cloud.dialogflow.cx.v3.MatchIntentResponse]. Otherwise, the behavior is undefined.

Parameters
NameDescription
requestFulfillIntentRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskFulfillIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
FulfillIntentRequest request = new FulfillIntentRequest
{
    MatchIntentRequest = new MatchIntentRequest(),
    Match = new Match(),
    OutputAudioConfig = new OutputAudioConfig(),
};
// Make the request
FulfillIntentResponse response = await sessionsClient.FulfillIntentAsync(request);

FulfillIntentAsync(FulfillIntentRequest, CancellationToken)

public virtual Task<FulfillIntentResponse> FulfillIntentAsync(FulfillIntentRequest request, CancellationToken cancellationToken)

Fulfills a matched intent returned by [MatchIntent][google.cloud.dialogflow.cx.v3.Sessions.MatchIntent]. Must be called after [MatchIntent][google.cloud.dialogflow.cx.v3.Sessions.MatchIntent], with input from [MatchIntentResponse][google.cloud.dialogflow.cx.v3.MatchIntentResponse]. Otherwise, the behavior is undefined.

Parameters
NameDescription
requestFulfillIntentRequest

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

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskFulfillIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
FulfillIntentRequest request = new FulfillIntentRequest
{
    MatchIntentRequest = new MatchIntentRequest(),
    Match = new Match(),
    OutputAudioConfig = new OutputAudioConfig(),
};
// Make the request
FulfillIntentResponse response = await sessionsClient.FulfillIntentAsync(request);

MatchIntent(MatchIntentRequest, CallSettings)

public virtual MatchIntentResponse MatchIntent(MatchIntentRequest request, CallSettings callSettings = null)

Returns preliminary intent match results, doesn't change the session status.

Parameters
NameDescription
requestMatchIntentRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
MatchIntentResponse

The RPC response.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize request argument(s)
MatchIntentRequest request = new MatchIntentRequest
{
    SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    PersistParameterChanges = false,
};
// Make the request
MatchIntentResponse response = sessionsClient.MatchIntent(request);

MatchIntentAsync(MatchIntentRequest, CallSettings)

public virtual Task<MatchIntentResponse> MatchIntentAsync(MatchIntentRequest request, CallSettings callSettings = null)

Returns preliminary intent match results, doesn't change the session status.

Parameters
NameDescription
requestMatchIntentRequest

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

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskMatchIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
MatchIntentRequest request = new MatchIntentRequest
{
    SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    PersistParameterChanges = false,
};
// Make the request
MatchIntentResponse response = await sessionsClient.MatchIntentAsync(request);

MatchIntentAsync(MatchIntentRequest, CancellationToken)

public virtual Task<MatchIntentResponse> MatchIntentAsync(MatchIntentRequest request, CancellationToken cancellationToken)

Returns preliminary intent match results, doesn't change the session status.

Parameters
NameDescription
requestMatchIntentRequest

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

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskMatchIntentResponse

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
MatchIntentRequest request = new MatchIntentRequest
{
    SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    QueryParams = new QueryParameters(),
    QueryInput = new QueryInput(),
    PersistParameterChanges = false,
};
// Make the request
MatchIntentResponse response = await sessionsClient.MatchIntentAsync(request);

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
TypeDescription
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).

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

Parameters
NameDescription
callSettingsCallSettings

If not null, applies overrides to this RPC call.

streamingSettingsBidirectionalStreamingSettings

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

Returns
TypeDescription
SessionsClientStreamingDetectIntentStream

The client-server stream.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize streaming call, retrieving the stream object
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.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
        QueryParams = new QueryParameters(),
        QueryInput = new QueryInput(),
        OutputAudioConfig = new OutputAudioConfig(),
        EnablePartialResponse = false,
        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;