Dialogflow v3 API - Class SessionsClient (2.21.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
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 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
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.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
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.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
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.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
Name Description
request FulfillIntentRequest

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
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
Name Description
request FulfillIntentRequest

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
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
Name Description
request FulfillIntentRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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
Name Description
request MatchIntentRequest

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
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
Name Description
request MatchIntentRequest

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
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
Name Description
request MatchIntentRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
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);

ServerStreamingDetectIntent(DetectIntentRequest, CallSettings)

public virtual SessionsClient.ServerStreamingDetectIntentStream ServerStreamingDetectIntent(DetectIntentRequest request, CallSettings callSettings = null)

Processes a natural language query and returns structured, actionable data as a result through server-side streaming. Server-side streaming allows Dialogflow to send partial responses earlier in a single request.

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
SessionsClientServerStreamingDetectIntentStream

The server stream.

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, returning a streaming response
using SessionsClient.ServerStreamingDetectIntentStream response = sessionsClient.ServerStreamingDetectIntent(request);

// Read streaming responses from server until complete
// Note that C# 8 code can use await foreach
AsyncResponseStream<DetectIntentResponse> responseStream = response.GetResponseStream();
while (await responseStream.MoveNextAsync())
{
    DetectIntentResponse responseItem = responseStream.Current;
    // Do something with streamed response
}
// The response stream has completed

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

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

SubmitAnswerFeedback(SubmitAnswerFeedbackRequest, CallSettings)

public virtual AnswerFeedback SubmitAnswerFeedback(SubmitAnswerFeedbackRequest request, CallSettings callSettings = null)

Updates the feedback received from the user for a single turn of the bot response.

Parameters
Name Description
request SubmitAnswerFeedbackRequest

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
AnswerFeedback

The RPC response.

Example
// Create client
SessionsClient sessionsClient = SessionsClient.Create();
// Initialize request argument(s)
SubmitAnswerFeedbackRequest request = new SubmitAnswerFeedbackRequest
{
    SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    ResponseId = "",
    AnswerFeedback = new AnswerFeedback(),
    UpdateMask = new FieldMask(),
};
// Make the request
AnswerFeedback response = sessionsClient.SubmitAnswerFeedback(request);

SubmitAnswerFeedbackAsync(SubmitAnswerFeedbackRequest, CallSettings)

public virtual Task<AnswerFeedback> SubmitAnswerFeedbackAsync(SubmitAnswerFeedbackRequest request, CallSettings callSettings = null)

Updates the feedback received from the user for a single turn of the bot response.

Parameters
Name Description
request SubmitAnswerFeedbackRequest

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
TaskAnswerFeedback

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
SubmitAnswerFeedbackRequest request = new SubmitAnswerFeedbackRequest
{
    SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    ResponseId = "",
    AnswerFeedback = new AnswerFeedback(),
    UpdateMask = new FieldMask(),
};
// Make the request
AnswerFeedback response = await sessionsClient.SubmitAnswerFeedbackAsync(request);

SubmitAnswerFeedbackAsync(SubmitAnswerFeedbackRequest, CancellationToken)

public virtual Task<AnswerFeedback> SubmitAnswerFeedbackAsync(SubmitAnswerFeedbackRequest request, CancellationToken cancellationToken)

Updates the feedback received from the user for a single turn of the bot response.

Parameters
Name Description
request SubmitAnswerFeedbackRequest

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

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskAnswerFeedback

A Task containing the RPC response.

Example
// Create client
SessionsClient sessionsClient = await SessionsClient.CreateAsync();
// Initialize request argument(s)
SubmitAnswerFeedbackRequest request = new SubmitAnswerFeedbackRequest
{
    SessionAsSessionName = SessionName.FromProjectLocationAgentSession("[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]"),
    ResponseId = "",
    AnswerFeedback = new AnswerFeedback(),
    UpdateMask = new FieldMask(),
};
// Make the request
AnswerFeedback response = await sessionsClient.SubmitAnswerFeedbackAsync(request);