lib/google/cloud/dialogflow/v2/contexts_client.rb in google-cloud-dialogflow-0.2.3 vs lib/google/cloud/dialogflow/v2/contexts_client.rb in google-cloud-dialogflow-0.3.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright 2018 Google LLC
+# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -42,15 +42,16 @@
# You can include contexts as input parameters of a
# {Google::Cloud::Dialogflow::V2::Sessions::DetectIntent DetectIntent} (or
# {Google::Cloud::Dialogflow::V2::Sessions::StreamingDetectIntent StreamingDetectIntent}) request,
# or as output contexts included in the returned intent.
# Contexts expire when an intent is matched, after the number of `DetectIntent`
- # requests specified by the `lifespan_count` parameter, or after 10 minutes
+ # requests specified by the `lifespan_count` parameter, or after 20 minutes
# if no intents are matched for a `DetectIntent` request.
#
# For more information about contexts, see the
- # [Dialogflow documentation](https://dialogflow.com/docs/contexts).
+ # [Dialogflow
+ # documentation](https://cloud.google.com/dialogflow-enterprise/docs/contexts-overview).
#
# @!attribute [r] contexts_stub
# @return [Google::Cloud::Dialogflow::V2::Contexts::Stub]
class ContextsClient
# @private
@@ -77,37 +78,27 @@
private_constant :PAGE_DESCRIPTORS
# The scopes needed to make gRPC calls to all of the methods defined in
# this service.
ALL_SCOPES = [
- "https://www.googleapis.com/auth/cloud-platform"
+ "https://www.googleapis.com/auth/cloud-platform",
+ "https://www.googleapis.com/auth/dialogflow"
].freeze
- SESSION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
- "projects/{project}/agent/sessions/{session}"
- )
-
- private_constant :SESSION_PATH_TEMPLATE
-
CONTEXT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
"projects/{project}/agent/sessions/{session}/contexts/{context}"
)
private_constant :CONTEXT_PATH_TEMPLATE
- # Returns a fully-qualified session resource name string.
- # @param project [String]
- # @param session [String]
- # @return [String]
- def self.session_path project, session
- SESSION_PATH_TEMPLATE.render(
- :"project" => project,
- :"session" => session
- )
- end
+ SESSION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
+ "projects/{project}/agent/sessions/{session}"
+ )
+ private_constant :SESSION_PATH_TEMPLATE
+
# Returns a fully-qualified context resource name string.
# @param project [String]
# @param session [String]
# @param context [String]
# @return [String]
@@ -117,10 +108,21 @@
:"session" => session,
:"context" => context
)
end
+ # Returns a fully-qualified session resource name string.
+ # @param project [String]
+ # @param session [String]
+ # @return [String]
+ def self.session_path project, session
+ SESSION_PATH_TEMPLATE.render(
+ :"project" => project,
+ :"session" => session
+ )
+ end
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
# Provides the means for authenticating requests made by the client. This parameter can
# be many types.
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
# authenticating requests made by this client.
@@ -223,36 +225,54 @@
)
@list_contexts = Google::Gax.create_api_call(
@contexts_stub.method(:list_contexts),
defaults["list_contexts"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@get_context = Google::Gax.create_api_call(
@contexts_stub.method(:get_context),
defaults["get_context"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@create_context = Google::Gax.create_api_call(
@contexts_stub.method(:create_context),
defaults["create_context"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
@update_context = Google::Gax.create_api_call(
@contexts_stub.method(:update_context),
defaults["update_context"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'context.name' => request.context.name}
+ end
)
@delete_context = Google::Gax.create_api_call(
@contexts_stub.method(:delete_context),
defaults["delete_context"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'name' => request.name}
+ end
)
@delete_all_contexts = Google::Gax.create_api_call(
@contexts_stub.method(:delete_all_contexts),
defaults["delete_all_contexts"],
- exception_transformer: exception_transformer
+ exception_transformer: exception_transformer,
+ params_extractor: proc do |request|
+ {'parent' => request.parent}
+ end
)
end
# Service calls
@@ -341,9 +361,11 @@
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::GetContextRequest)
@get_context.call(req, options, &block)
end
# Creates a context.
+ #
+ # If the specified context already exists, overrides the context.
#
# @param parent [String]
# Required. The session to create a context for.
# Format: `projects/<Project ID>/agent/sessions/<Session ID>`.
# @param context [Google::Cloud::Dialogflow::V2::Context | Hash]