Dialogflow V2 API - Class Google::Cloud::Dialogflow::V2::Conversations::Client (v0.30.0)

Reference documentation and code samples for the Dialogflow V2 API class Google::Cloud::Dialogflow::V2::Conversations::Client.

Client for the Conversations service.

Service for managing Conversations.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the Conversations Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all Conversations clients
::Google::Cloud::Dialogflow::V2::Conversations::Client.configure do |config|
  config.timeout = 10.0
end

#complete_conversation

def complete_conversation(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
def complete_conversation(name: nil) -> ::Google::Cloud::Dialogflow::V2::Conversation

Completes the specified conversation. Finished conversations are purged from the database after 30 days.

Overloads
def complete_conversation(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
Pass arguments to complete_conversation via a request object, either of type Google::Cloud::Dialogflow::V2::CompleteConversationRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::CompleteConversationRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def complete_conversation(name: nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
Pass arguments to complete_conversation via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. Resource identifier of the conversation to close. Format: projects/<Project ID>/locations/<Location ID>/conversations/<Conversation ID>.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::CompleteConversationRequest.new

# Call the complete_conversation method.
result = client.complete_conversation request

# The returned object is of type Google::Cloud::Dialogflow::V2::Conversation.
p result

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the Conversations Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#create_conversation

def create_conversation(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
def create_conversation(parent: nil, conversation: nil, conversation_id: nil) -> ::Google::Cloud::Dialogflow::V2::Conversation

Creates a new conversation. Conversations are auto-completed after 24 hours.

Conversation Lifecycle: There are two stages during a conversation: Automated Agent Stage and Assist Stage.

For Automated Agent Stage, there will be a dialogflow agent responding to user queries.

For Assist Stage, there's no dialogflow agent responding to user queries. But we will provide suggestions which are generated from conversation.

If Conversation.conversation_profile is configured for a dialogflow agent, conversation will start from Automated Agent Stage, otherwise, it will start from Assist Stage. And during Automated Agent Stage, once an Intent with Intent.live_agent_handoff is triggered, conversation will transfer to Assist Stage.

Overloads
def create_conversation(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
Pass arguments to create_conversation via a request object, either of type Google::Cloud::Dialogflow::V2::CreateConversationRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::CreateConversationRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def create_conversation(parent: nil, conversation: nil, conversation_id: nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
Pass arguments to create_conversation via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. Resource identifier of the project creating the conversation. Format: projects/<Project ID>/locations/<Location ID>.
  • conversation (::Google::Cloud::Dialogflow::V2::Conversation, ::Hash) — Required. The conversation to create.
  • conversation_id (::String) —

    Optional. Identifier of the conversation. Generally it's auto generated by Google. Only set it if you cannot wait for the response to return a auto-generated one to you.

    The conversation ID must be compliant with the regression fomula [a-zA-Z][a-zA-Z0-9_-]* with the characters length in range of [3,64]. If the field is provided, the caller is resposible for

    1. the uniqueness of the ID, otherwise the request will be rejected.
    2. the consistency for whether to use custom ID or not under a project to better ensure uniqueness.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::CreateConversationRequest.new

# Call the create_conversation method.
result = client.create_conversation request

# The returned object is of type Google::Cloud::Dialogflow::V2::Conversation.
p result

#generate_stateless_summary

def generate_stateless_summary(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryResponse
def generate_stateless_summary(stateless_conversation: nil, conversation_profile: nil, latest_message: nil, max_context_size: nil) -> ::Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryResponse

Generates and returns a summary for a conversation that does not have a resource created for it.

Overloads
def generate_stateless_summary(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryResponse
Pass arguments to generate_stateless_summary via a request object, either of type GenerateStatelessSummaryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def generate_stateless_summary(stateless_conversation: nil, conversation_profile: nil, latest_message: nil, max_context_size: nil) -> ::Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryResponse
Pass arguments to generate_stateless_summary via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • stateless_conversation (::Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryRequest::MinimalConversation, ::Hash) — Required. The conversation to suggest a summary for.
  • conversation_profile (::Google::Cloud::Dialogflow::V2::ConversationProfile, ::Hash) — Required. A ConversationProfile containing information required for Summary generation. Required fields: {language_code, security_settings} Optional fields: {agent_assistant_config}
  • latest_message (::String) — The name of the latest conversation message used as context for generating a Summary. If empty, the latest message of the conversation will be used. The format is specific to the user and the names of the messages provided.
  • max_context_size (::Integer) — Max number of messages prior to and including [latest_message] to use as context when compiling the suggestion. By default 500 and at most 1000.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryRequest.new

# Call the generate_stateless_summary method.
result = client.generate_stateless_summary request

# The returned object is of type Google::Cloud::Dialogflow::V2::GenerateStatelessSummaryResponse.
p result

#get_conversation

def get_conversation(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
def get_conversation(name: nil) -> ::Google::Cloud::Dialogflow::V2::Conversation

Retrieves the specific conversation.

Overloads
def get_conversation(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
Pass arguments to get_conversation via a request object, either of type GetConversationRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::GetConversationRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_conversation(name: nil) -> ::Google::Cloud::Dialogflow::V2::Conversation
Pass arguments to get_conversation via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The name of the conversation. Format: projects/<Project ID>/locations/<Location ID>/conversations/<Conversation ID>.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::GetConversationRequest.new

# Call the get_conversation method.
result = client.get_conversation request

# The returned object is of type Google::Cloud::Dialogflow::V2::Conversation.
p result

#initialize

def initialize() { |config| ... } -> Client

Create a new Conversations client object.

Yields
  • (config) — Configure the Conversations client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Dialogflow::V2::Conversations::Client.new do |config|
  config.timeout = 10.0
end

#list_conversations

def list_conversations(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Conversation>
def list_conversations(parent: nil, page_size: nil, page_token: nil, filter: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Conversation>

Returns the list of all conversations in the specified project.

Overloads
def list_conversations(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Conversation>
Pass arguments to list_conversations via a request object, either of type ListConversationsRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::ListConversationsRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_conversations(parent: nil, page_size: nil, page_token: nil, filter: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Conversation>
Pass arguments to list_conversations via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The project from which to list all conversation. Format: projects/<Project ID>/locations/<Location ID>.
  • page_size (::Integer) — Optional. The maximum number of items to return in a single page. By default 100 and at most 1000.
  • page_token (::String) — Optional. The next_page_token value returned from a previous list request.
  • filter (::String) — A filter expression that filters conversations listed in the response. In general, the expression must specify the field name, a comparison operator, and the value to use for filtering:

    • The value must be a string, a number, or a boolean.
    • The comparison operator must be either `=`,`!=`, `>`, or `<>
    • To filter on multiple expressions, separate the expressions with `AND` or `OR` (omitting both implies `AND`).
    • For clarity, expressions can be enclosed in parentheses.

    Only lifecycle_state can be filtered on in this way. For example, the following expression only returns COMPLETED conversations:

    lifecycle_state = "COMPLETED"

    For more information about filtering, see API Filtering.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::ListConversationsRequest.new

# Call the list_conversations method.
result = client.list_conversations request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Dialogflow::V2::Conversation.
  p item
end

#list_messages

def list_messages(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Message>
def list_messages(parent: nil, filter: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Message>

Lists messages that belong to a given conversation. messages are ordered by create_time in descending order. To fetch updates without duplication, send request with filter create_time_epoch_microseconds > [first item's create_time of previous request] and empty page_token.

Overloads
def list_messages(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Message>
Pass arguments to list_messages via a request object, either of type ListMessagesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::ListMessagesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_messages(parent: nil, filter: nil, page_size: nil, page_token: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Dialogflow::V2::Message>
Pass arguments to list_messages via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The name of the conversation to list messages for. Format: projects/<Project ID>/locations/<Location ID>/conversations/<Conversation ID>
  • filter (::String) — Optional. Filter on message fields. Currently predicates on create_time and create_time_epoch_microseconds are supported. create_time only support milliseconds accuracy. E.g., create_time_epoch_microseconds > 1551790877964485 or create_time > 2017-01-15T01:30:15.01Z.

    For more information about filtering, see API Filtering.

  • page_size (::Integer) — Optional. The maximum number of items to return in a single page. By default 100 and at most 1000.
  • page_token (::String) — Optional. The next_page_token value returned from a previous list request.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::ListMessagesRequest.new

# Call the list_messages method.
result = client.list_messages request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Dialogflow::V2::Message.
  p item
end

#location_client

def location_client() -> Google::Cloud::Location::Locations::Client

Get the associated client for mix-in of the Locations.

Returns
  • (Google::Cloud::Location::Locations::Client)

#search_knowledge

def search_knowledge(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::SearchKnowledgeResponse
def search_knowledge(parent: nil, query: nil, conversation_profile: nil, session_id: nil, conversation: nil, latest_message: nil) -> ::Google::Cloud::Dialogflow::V2::SearchKnowledgeResponse

Get answers for the given query based on knowledge documents.

Overloads
def search_knowledge(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::SearchKnowledgeResponse
Pass arguments to search_knowledge via a request object, either of type SearchKnowledgeRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::SearchKnowledgeRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def search_knowledge(parent: nil, query: nil, conversation_profile: nil, session_id: nil, conversation: nil, latest_message: nil) -> ::Google::Cloud::Dialogflow::V2::SearchKnowledgeResponse
Pass arguments to search_knowledge via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — The parent resource contains the conversation profile Format: 'projects/
  • query (::Google::Cloud::Dialogflow::V2::TextInput, ::Hash) — Required. The natural language text query for knowledge search.
  • conversation_profile (::String) — Required. The conversation profile used to configure the search. Format: projects/<Project ID>/locations/<Location ID>/conversationProfiles/<Conversation Profile ID>.
  • session_id (::String) — The ID of the search session. The session_id can be combined with Dialogflow V3 Agent ID retrieved from conversation profile or on its own to identify a search session. The search history of the same session will impact the search result. It's up to the API caller to choose an appropriate Session ID. It can be a random number or some type of session identifiers (preferably hashed). The length must not exceed 36 characters.
  • conversation (::String) — The conversation (between human agent and end user) where the search request is triggered. Format: projects/<Project ID>/locations/<Location ID>/conversations/<Conversation ID>.
  • latest_message (::String) — The name of the latest conversation message when the request is triggered. Format: projects/<Project ID>/locations/<Location ID>/conversations/<Conversation ID>/messages/<Message ID>.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::SearchKnowledgeRequest.new

# Call the search_knowledge method.
result = client.search_knowledge request

# The returned object is of type Google::Cloud::Dialogflow::V2::SearchKnowledgeResponse.
p result

#suggest_conversation_summary

def suggest_conversation_summary(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::SuggestConversationSummaryResponse
def suggest_conversation_summary(conversation: nil, latest_message: nil, context_size: nil, assist_query_params: nil) -> ::Google::Cloud::Dialogflow::V2::SuggestConversationSummaryResponse

Suggests summary for a conversation based on specific historical messages. The range of the messages to be used for summary can be specified in the request.

Overloads
def suggest_conversation_summary(request, options = nil) -> ::Google::Cloud::Dialogflow::V2::SuggestConversationSummaryResponse
Pass arguments to suggest_conversation_summary via a request object, either of type SuggestConversationSummaryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Dialogflow::V2::SuggestConversationSummaryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def suggest_conversation_summary(conversation: nil, latest_message: nil, context_size: nil, assist_query_params: nil) -> ::Google::Cloud::Dialogflow::V2::SuggestConversationSummaryResponse
Pass arguments to suggest_conversation_summary via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • conversation (::String) — Required. The conversation to fetch suggestion for. Format: projects/<Project ID>/locations/<Location ID>/conversations/<Conversation ID>.
  • latest_message (::String) — The name of the latest conversation message used as context for compiling suggestion. If empty, the latest message of the conversation will be used.

    Format: projects/<Project ID>/locations/<Location ID>/conversations/<Conversation ID>/messages/<Message ID>.

  • context_size (::Integer) — Max number of messages prior to and including [latest_message] to use as context when compiling the suggestion. By default 500 and at most 1000.
  • assist_query_params (::Google::Cloud::Dialogflow::V2::AssistQueryParameters, ::Hash) — Parameters for a human assist query. Only used for POC/demo purpose.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/dialogflow/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Dialogflow::V2::Conversations::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Dialogflow::V2::SuggestConversationSummaryRequest.new

# Call the suggest_conversation_summary method.
result = client.suggest_conversation_summary request

# The returned object is of type Google::Cloud::Dialogflow::V2::SuggestConversationSummaryResponse.
p result