Class: Google::Cloud::Dialogflow::V2::Contexts::Client
- Inherits:
-
Object
- Object
- Google::Cloud::Dialogflow::V2::Contexts::Client
- Includes:
- Paths
- Defined in:
- lib/google/cloud/dialogflow/v2/contexts/client.rb
Overview
Client for the Contexts service.
A context represents additional information included with user input or with an intent returned by the Dialogflow API. Contexts are helpful for differentiating user input which may be vague or have a different meaning depending on additional details from your application such as user setting and preferences, previous user input, where the user is in your application, geographic location, and so on.
You can include contexts as input parameters of a
DetectIntent (or
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 20 minutes
if no intents are matched for a DetectIntent request.
For more information about contexts, see the Dialogflow documentation.
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
-
.configure {|config| ... } ⇒ Client::Configuration
Configure the Contexts Client class.
Instance Method Summary collapse
-
#configure {|config| ... } ⇒ Client::Configuration
Configure the Contexts Client instance.
-
#create_context(request, options = nil) {|response, operation| ... } ⇒ Google::Cloud::Dialogflow::V2::Context
Creates a context.
-
#delete_all_contexts(request, options = nil) {|response, operation| ... } ⇒ Google::Protobuf::Empty
Deletes all active contexts in the specified session.
-
#delete_context(request, options = nil) {|response, operation| ... } ⇒ Google::Protobuf::Empty
Deletes the specified context.
-
#get_context(request, options = nil) {|response, operation| ... } ⇒ Google::Cloud::Dialogflow::V2::Context
Retrieves the specified context.
-
#initialize {|config| ... } ⇒ Client
constructor
Create a new Contexts client object.
-
#list_contexts(request, options = nil) {|response, operation| ... } ⇒ Gapic::PagedEnumerable<Google::Cloud::Dialogflow::V2::Context>
Returns the list of all contexts in the specified session.
-
#update_context(request, options = nil) {|response, operation| ... } ⇒ Google::Cloud::Dialogflow::V2::Context
Updates the specified context.
Methods included from Paths
Constructor Details
#initialize {|config| ... } ⇒ Client
Create a new Contexts client object.
Examples
To create a new Contexts client with the default configuration:
client = Google::Cloud::Dialogflow::V2::Contexts::Client.new
To create a new Contexts client with a custom configuration:
client = Google::Cloud::Dialogflow::V2::Contexts::Client.new do |config|
config.timeout = 10_000
end
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 174 def initialize # These require statements are intentionally placed here to initialize # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "gapic/grpc" require "google/cloud/dialogflow/v2/context_services_pb" # Create the configuration object @config = Configuration.new Client.configure # Yield the configuration if needed yield @config if block_given? # Create credentials credentials = @config.credentials credentials ||= Credentials.default scope: @config.scope if credentials.is_a?(String) || credentials.is_a?(Hash) credentials = Credentials.new credentials, scope: @config.scope end @quota_project_id = credentials.respond_to?(:quota_project_id) ? credentials.quota_project_id : nil @contexts_stub = Gapic::ServiceStub.new( Google::Cloud::Dialogflow::V2::Contexts::Stub, credentials: credentials, endpoint: @config.endpoint, channel_args: @config.channel_args, interceptors: @config.interceptors ) end |
Class Method Details
.configure {|config| ... } ⇒ Client::Configuration
Configure the Contexts Client class.
See Configuration for a description of the configuration fields.
Example
To modify the configuration for all Contexts clients:
Google::Cloud::Dialogflow::V2::Contexts::Client.configure do |config|
config.timeout = 10_000
end
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 81 def self.configure @configure ||= begin namespace = ["Google", "Cloud", "Dialogflow", "V2"] parent_config = while namespace.any? parent_name = namespace.join "::" parent_const = const_get parent_name break parent_const.configure if parent_const&.respond_to? :configure namespace.pop end default_config = Client::Configuration.new parent_config default_config.rpcs.list_contexts.timeout = 60.0 default_config.rpcs.list_contexts.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"] } default_config.rpcs.get_context.timeout = 60.0 default_config.rpcs.get_context.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"] } default_config.rpcs.create_context.timeout = 60.0 default_config.rpcs.update_context.timeout = 60.0 default_config.rpcs.delete_context.timeout = 60.0 default_config.rpcs.delete_context.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"] } default_config.rpcs.delete_all_contexts.timeout = 60.0 default_config.rpcs.delete_all_contexts.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: ["UNAVAILABLE", "DEADLINE_EXCEEDED"] } default_config end yield @configure if block_given? @configure end |
Instance Method Details
#configure {|config| ... } ⇒ Client::Configuration
Configure the Contexts 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 configure.
See Configuration for a description of the configuration fields.
149 150 151 152 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 149 def configure yield @config if block_given? @config end |
#create_context(request, options = nil) ⇒ Google::Cloud::Dialogflow::V2::Context #create_context(parent: nil, context: nil) ⇒ Google::Cloud::Dialogflow::V2::Context
Creates a context.
If the specified context already exists, overrides the context.
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 373 def create_context request, = nil raise ArgumentError, "request must be provided" if request.nil? request = Gapic::Protobuf.coerce request, to: Google::Cloud::Dialogflow::V2::CreateContextRequest # Converts hash and nil to an options object = Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.create_context..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Dialogflow::V2::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "parent" => request.parent } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.create_context.timeout, metadata: , retry_policy: @config.rpcs.create_context.retry_policy .apply_defaults metadata: @config., retry_policy: @config.retry_policy @contexts_stub.call_rpc :create_context, request, options: do |response, operation| yield response, operation if block_given? return response end rescue GRPC::BadStatus => e raise Google::Cloud::Error.from_error(e) end |
#delete_all_contexts(request, options = nil) ⇒ Google::Protobuf::Empty #delete_all_contexts(parent: nil) ⇒ Google::Protobuf::Empty
Deletes all active contexts in the specified session.
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 562 def delete_all_contexts request, = nil raise ArgumentError, "request must be provided" if request.nil? request = Gapic::Protobuf.coerce request, to: Google::Cloud::Dialogflow::V2::DeleteAllContextsRequest # Converts hash and nil to an options object = Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.delete_all_contexts..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Dialogflow::V2::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "parent" => request.parent } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.delete_all_contexts.timeout, metadata: , retry_policy: @config.rpcs.delete_all_contexts.retry_policy .apply_defaults metadata: @config., retry_policy: @config.retry_policy @contexts_stub.call_rpc :delete_all_contexts, request, options: do |response, operation| yield response, operation if block_given? return response end rescue GRPC::BadStatus => e raise Google::Cloud::Error.from_error(e) end |
#delete_context(request, options = nil) ⇒ Google::Protobuf::Empty #delete_context(name: nil) ⇒ Google::Protobuf::Empty
Deletes the specified context.
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 498 def delete_context request, = nil raise ArgumentError, "request must be provided" if request.nil? request = Gapic::Protobuf.coerce request, to: Google::Cloud::Dialogflow::V2::DeleteContextRequest # Converts hash and nil to an options object = Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.delete_context..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Dialogflow::V2::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "name" => request.name } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.delete_context.timeout, metadata: , retry_policy: @config.rpcs.delete_context.retry_policy .apply_defaults metadata: @config., retry_policy: @config.retry_policy @contexts_stub.call_rpc :delete_context, request, options: do |response, operation| yield response, operation if block_given? return response end rescue GRPC::BadStatus => e raise Google::Cloud::Error.from_error(e) end |
#get_context(request, options = nil) ⇒ Google::Cloud::Dialogflow::V2::Context #get_context(name: nil) ⇒ Google::Cloud::Dialogflow::V2::Context
Retrieves the specified context.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 303 def get_context request, = nil raise ArgumentError, "request must be provided" if request.nil? request = Gapic::Protobuf.coerce request, to: Google::Cloud::Dialogflow::V2::GetContextRequest # Converts hash and nil to an options object = Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.get_context..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Dialogflow::V2::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "name" => request.name } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.get_context.timeout, metadata: , retry_policy: @config.rpcs.get_context.retry_policy .apply_defaults metadata: @config., retry_policy: @config.retry_policy @contexts_stub.call_rpc :get_context, request, options: do |response, operation| yield response, operation if block_given? return response end rescue GRPC::BadStatus => e raise Google::Cloud::Error.from_error(e) end |
#list_contexts(request, options = nil) ⇒ Gapic::PagedEnumerable<Google::Cloud::Dialogflow::V2::Context> #list_contexts(parent: nil, page_size: nil, page_token: nil) ⇒ Gapic::PagedEnumerable<Google::Cloud::Dialogflow::V2::Context>
Returns the list of all contexts in the specified session.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 238 def list_contexts request, = nil raise ArgumentError, "request must be provided" if request.nil? request = Gapic::Protobuf.coerce request, to: Google::Cloud::Dialogflow::V2::ListContextsRequest # Converts hash and nil to an options object = Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.list_contexts..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Dialogflow::V2::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "parent" => request.parent } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.list_contexts.timeout, metadata: , retry_policy: @config.rpcs.list_contexts.retry_policy .apply_defaults metadata: @config., retry_policy: @config.retry_policy @contexts_stub.call_rpc :list_contexts, request, options: do |response, operation| response = Gapic::PagedEnumerable.new @contexts_stub, :list_contexts, request, response, operation, yield response, operation if block_given? return response end rescue GRPC::BadStatus => e raise Google::Cloud::Error.from_error(e) end |
#update_context(request, options = nil) ⇒ Google::Cloud::Dialogflow::V2::Context #update_context(context: nil, update_mask: nil) ⇒ Google::Cloud::Dialogflow::V2::Context
Updates the specified context.
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/google/cloud/dialogflow/v2/contexts/client.rb', line 434 def update_context request, = nil raise ArgumentError, "request must be provided" if request.nil? request = Gapic::Protobuf.coerce request, to: Google::Cloud::Dialogflow::V2::UpdateContextRequest # Converts hash and nil to an options object = Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.update_context..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Dialogflow::V2::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = { "context.name" => request.context.name } request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.update_context.timeout, metadata: , retry_policy: @config.rpcs.update_context.retry_policy .apply_defaults metadata: @config., retry_policy: @config.retry_policy @contexts_stub.call_rpc :update_context, request, options: do |response, operation| yield response, operation if block_given? return response end rescue GRPC::BadStatus => e raise Google::Cloud::Error.from_error(e) end |