google-cloud-dialogflow 0.13.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/AUTHENTICATION.md +51 -59
  4. data/LICENSE.md +203 -0
  5. data/MIGRATING.md +445 -0
  6. data/README.md +35 -25
  7. data/lib/{google/cloud/dialogflow/v2/doc/google/protobuf/empty.rb → google-cloud-dialogflow.rb} +4 -14
  8. data/lib/google/cloud/dialogflow.rb +374 -506
  9. data/lib/google/cloud/dialogflow/version.rb +1 -1
  10. metadata +62 -83
  11. data/LICENSE +0 -201
  12. data/lib/google/cloud/dialogflow/v2.rb +0 -598
  13. data/lib/google/cloud/dialogflow/v2/agent_pb.rb +0 -115
  14. data/lib/google/cloud/dialogflow/v2/agent_services_pb.rb +0 -109
  15. data/lib/google/cloud/dialogflow/v2/agents_client.rb +0 -760
  16. data/lib/google/cloud/dialogflow/v2/agents_client_config.json +0 -66
  17. data/lib/google/cloud/dialogflow/v2/audio_config_pb.rb +0 -96
  18. data/lib/google/cloud/dialogflow/v2/context_pb.rb +0 -63
  19. data/lib/google/cloud/dialogflow/v2/context_services_pb.rb +0 -76
  20. data/lib/google/cloud/dialogflow/v2/contexts_client.rb +0 -519
  21. data/lib/google/cloud/dialogflow/v2/contexts_client_config.json +0 -56
  22. data/lib/google/cloud/dialogflow/v2/credentials.rb +0 -42
  23. data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/agent.rb +0 -233
  24. data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/audio_config.rb +0 -341
  25. data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/context.rb +0 -116
  26. data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/entity_type.rb +0 -305
  27. data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/intent.rb +0 -937
  28. data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/session.rb +0 -482
  29. data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/session_entity_type.rb +0 -130
  30. data/lib/google/cloud/dialogflow/v2/doc/google/longrunning/operations.rb +0 -51
  31. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/any.rb +0 -131
  32. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/duration.rb +0 -91
  33. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/field_mask.rb +0 -222
  34. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/struct.rb +0 -74
  35. data/lib/google/cloud/dialogflow/v2/doc/google/rpc/status.rb +0 -39
  36. data/lib/google/cloud/dialogflow/v2/doc/google/type/latlng.rb +0 -31
  37. data/lib/google/cloud/dialogflow/v2/entity_type_pb.rb +0 -125
  38. data/lib/google/cloud/dialogflow/v2/entity_type_services_pb.rb +0 -106
  39. data/lib/google/cloud/dialogflow/v2/entity_types_client.rb +0 -994
  40. data/lib/google/cloud/dialogflow/v2/entity_types_client_config.json +0 -76
  41. data/lib/google/cloud/dialogflow/v2/intent_pb.rb +0 -367
  42. data/lib/google/cloud/dialogflow/v2/intent_services_pb.rb +0 -94
  43. data/lib/google/cloud/dialogflow/v2/intents_client.rb +0 -760
  44. data/lib/google/cloud/dialogflow/v2/intents_client_config.json +0 -61
  45. data/lib/google/cloud/dialogflow/v2/session_entity_type_pb.rb +0 -65
  46. data/lib/google/cloud/dialogflow/v2/session_entity_type_services_pb.rb +0 -94
  47. data/lib/google/cloud/dialogflow/v2/session_entity_types_client.rb +0 -504
  48. data/lib/google/cloud/dialogflow/v2/session_entity_types_client_config.json +0 -51
  49. data/lib/google/cloud/dialogflow/v2/session_pb.rb +0 -138
  50. data/lib/google/cloud/dialogflow/v2/session_services_pb.rb +0 -57
  51. data/lib/google/cloud/dialogflow/v2/sessions_client.rb +0 -326
  52. data/lib/google/cloud/dialogflow/v2/sessions_client_config.json +0 -36
  53. data/lib/google/cloud/dialogflow/v2/webhook_pb.rb +0 -46
@@ -1,51 +0,0 @@
1
- {
2
- "interfaces": {
3
- "google.cloud.dialogflow.v2.SessionEntityTypes": {
4
- "retry_codes": {
5
- "idempotent": [
6
- "DEADLINE_EXCEEDED",
7
- "UNAVAILABLE"
8
- ],
9
- "non_idempotent": []
10
- },
11
- "retry_params": {
12
- "default": {
13
- "initial_retry_delay_millis": 100,
14
- "retry_delay_multiplier": 1.3,
15
- "max_retry_delay_millis": 60000,
16
- "initial_rpc_timeout_millis": 20000,
17
- "rpc_timeout_multiplier": 1.0,
18
- "max_rpc_timeout_millis": 20000,
19
- "total_timeout_millis": 600000
20
- }
21
- },
22
- "methods": {
23
- "ListSessionEntityTypes": {
24
- "timeout_millis": 60000,
25
- "retry_codes_name": "idempotent",
26
- "retry_params_name": "default"
27
- },
28
- "GetSessionEntityType": {
29
- "timeout_millis": 60000,
30
- "retry_codes_name": "idempotent",
31
- "retry_params_name": "default"
32
- },
33
- "CreateSessionEntityType": {
34
- "timeout_millis": 60000,
35
- "retry_codes_name": "non_idempotent",
36
- "retry_params_name": "default"
37
- },
38
- "UpdateSessionEntityType": {
39
- "timeout_millis": 60000,
40
- "retry_codes_name": "non_idempotent",
41
- "retry_params_name": "default"
42
- },
43
- "DeleteSessionEntityType": {
44
- "timeout_millis": 60000,
45
- "retry_codes_name": "idempotent",
46
- "retry_params_name": "default"
47
- }
48
- }
49
- }
50
- }
51
- }
@@ -1,138 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # source: google/cloud/dialogflow/v2/session.proto
3
-
4
-
5
- require 'google/protobuf'
6
-
7
- require 'google/api/annotations_pb'
8
- require 'google/api/client_pb'
9
- require 'google/api/field_behavior_pb'
10
- require 'google/api/resource_pb'
11
- require 'google/cloud/dialogflow/v2/audio_config_pb'
12
- require 'google/cloud/dialogflow/v2/context_pb'
13
- require 'google/cloud/dialogflow/v2/intent_pb'
14
- require 'google/cloud/dialogflow/v2/session_entity_type_pb'
15
- require 'google/protobuf/duration_pb'
16
- require 'google/protobuf/struct_pb'
17
- require 'google/rpc/status_pb'
18
- require 'google/type/latlng_pb'
19
- Google::Protobuf::DescriptorPool.generated_pool.build do
20
- add_message "google.cloud.dialogflow.v2.DetectIntentRequest" do
21
- optional :session, :string, 1
22
- optional :query_params, :message, 2, "google.cloud.dialogflow.v2.QueryParameters"
23
- optional :query_input, :message, 3, "google.cloud.dialogflow.v2.QueryInput"
24
- optional :output_audio_config, :message, 4, "google.cloud.dialogflow.v2.OutputAudioConfig"
25
- optional :input_audio, :bytes, 5
26
- end
27
- add_message "google.cloud.dialogflow.v2.DetectIntentResponse" do
28
- optional :response_id, :string, 1
29
- optional :query_result, :message, 2, "google.cloud.dialogflow.v2.QueryResult"
30
- optional :webhook_status, :message, 3, "google.rpc.Status"
31
- optional :output_audio, :bytes, 4
32
- optional :output_audio_config, :message, 6, "google.cloud.dialogflow.v2.OutputAudioConfig"
33
- end
34
- add_message "google.cloud.dialogflow.v2.QueryParameters" do
35
- optional :time_zone, :string, 1
36
- optional :geo_location, :message, 2, "google.type.LatLng"
37
- repeated :contexts, :message, 3, "google.cloud.dialogflow.v2.Context"
38
- optional :reset_contexts, :bool, 4
39
- repeated :session_entity_types, :message, 5, "google.cloud.dialogflow.v2.SessionEntityType"
40
- optional :payload, :message, 6, "google.protobuf.Struct"
41
- optional :sentiment_analysis_request_config, :message, 10, "google.cloud.dialogflow.v2.SentimentAnalysisRequestConfig"
42
- end
43
- add_message "google.cloud.dialogflow.v2.QueryInput" do
44
- oneof :input do
45
- optional :audio_config, :message, 1, "google.cloud.dialogflow.v2.InputAudioConfig"
46
- optional :text, :message, 2, "google.cloud.dialogflow.v2.TextInput"
47
- optional :event, :message, 3, "google.cloud.dialogflow.v2.EventInput"
48
- end
49
- end
50
- add_message "google.cloud.dialogflow.v2.QueryResult" do
51
- optional :query_text, :string, 1
52
- optional :language_code, :string, 15
53
- optional :speech_recognition_confidence, :float, 2
54
- optional :action, :string, 3
55
- optional :parameters, :message, 4, "google.protobuf.Struct"
56
- optional :all_required_params_present, :bool, 5
57
- optional :fulfillment_text, :string, 6
58
- repeated :fulfillment_messages, :message, 7, "google.cloud.dialogflow.v2.Intent.Message"
59
- optional :webhook_source, :string, 8
60
- optional :webhook_payload, :message, 9, "google.protobuf.Struct"
61
- repeated :output_contexts, :message, 10, "google.cloud.dialogflow.v2.Context"
62
- optional :intent, :message, 11, "google.cloud.dialogflow.v2.Intent"
63
- optional :intent_detection_confidence, :float, 12
64
- optional :diagnostic_info, :message, 14, "google.protobuf.Struct"
65
- optional :sentiment_analysis_result, :message, 17, "google.cloud.dialogflow.v2.SentimentAnalysisResult"
66
- end
67
- add_message "google.cloud.dialogflow.v2.StreamingDetectIntentRequest" do
68
- optional :session, :string, 1
69
- optional :query_params, :message, 2, "google.cloud.dialogflow.v2.QueryParameters"
70
- optional :query_input, :message, 3, "google.cloud.dialogflow.v2.QueryInput"
71
- optional :single_utterance, :bool, 4
72
- optional :output_audio_config, :message, 5, "google.cloud.dialogflow.v2.OutputAudioConfig"
73
- optional :input_audio, :bytes, 6
74
- end
75
- add_message "google.cloud.dialogflow.v2.StreamingDetectIntentResponse" do
76
- optional :response_id, :string, 1
77
- optional :recognition_result, :message, 2, "google.cloud.dialogflow.v2.StreamingRecognitionResult"
78
- optional :query_result, :message, 3, "google.cloud.dialogflow.v2.QueryResult"
79
- optional :webhook_status, :message, 4, "google.rpc.Status"
80
- optional :output_audio, :bytes, 5
81
- optional :output_audio_config, :message, 6, "google.cloud.dialogflow.v2.OutputAudioConfig"
82
- end
83
- add_message "google.cloud.dialogflow.v2.StreamingRecognitionResult" do
84
- optional :message_type, :enum, 1, "google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType"
85
- optional :transcript, :string, 2
86
- optional :is_final, :bool, 3
87
- optional :confidence, :float, 4
88
- repeated :speech_word_info, :message, 7, "google.cloud.dialogflow.v2.SpeechWordInfo"
89
- optional :speech_end_offset, :message, 8, "google.protobuf.Duration"
90
- end
91
- add_enum "google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType" do
92
- value :MESSAGE_TYPE_UNSPECIFIED, 0
93
- value :TRANSCRIPT, 1
94
- value :END_OF_SINGLE_UTTERANCE, 2
95
- end
96
- add_message "google.cloud.dialogflow.v2.TextInput" do
97
- optional :text, :string, 1
98
- optional :language_code, :string, 2
99
- end
100
- add_message "google.cloud.dialogflow.v2.EventInput" do
101
- optional :name, :string, 1
102
- optional :parameters, :message, 2, "google.protobuf.Struct"
103
- optional :language_code, :string, 3
104
- end
105
- add_message "google.cloud.dialogflow.v2.SentimentAnalysisRequestConfig" do
106
- optional :analyze_query_text_sentiment, :bool, 1
107
- end
108
- add_message "google.cloud.dialogflow.v2.SentimentAnalysisResult" do
109
- optional :query_text_sentiment, :message, 1, "google.cloud.dialogflow.v2.Sentiment"
110
- end
111
- add_message "google.cloud.dialogflow.v2.Sentiment" do
112
- optional :score, :float, 1
113
- optional :magnitude, :float, 2
114
- end
115
- end
116
-
117
- module Google
118
- module Cloud
119
- module Dialogflow
120
- module V2
121
- DetectIntentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.DetectIntentRequest").msgclass
122
- DetectIntentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.DetectIntentResponse").msgclass
123
- QueryParameters = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryParameters").msgclass
124
- QueryInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryInput").msgclass
125
- QueryResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryResult").msgclass
126
- StreamingDetectIntentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingDetectIntentRequest").msgclass
127
- StreamingDetectIntentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingDetectIntentResponse").msgclass
128
- StreamingRecognitionResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingRecognitionResult").msgclass
129
- StreamingRecognitionResult::MessageType = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType").enummodule
130
- TextInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.TextInput").msgclass
131
- EventInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.EventInput").msgclass
132
- SentimentAnalysisRequestConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.SentimentAnalysisRequestConfig").msgclass
133
- SentimentAnalysisResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.SentimentAnalysisResult").msgclass
134
- Sentiment = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.Sentiment").msgclass
135
- end
136
- end
137
- end
138
- end
@@ -1,57 +0,0 @@
1
- # Generated by the protocol buffer compiler. DO NOT EDIT!
2
- # Source: google/cloud/dialogflow/v2/session.proto for package 'google.cloud.dialogflow.v2'
3
- # Original file comments:
4
- # Copyright 2019 Google LLC.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
- #
19
-
20
-
21
- require 'grpc'
22
- require 'google/cloud/dialogflow/v2/session_pb'
23
-
24
- module Google
25
- module Cloud
26
- module Dialogflow
27
- module V2
28
- module Sessions
29
- # A session represents an interaction with a user. You retrieve user input
30
- # and pass it to the [DetectIntent][google.cloud.dialogflow.v2.Sessions.DetectIntent] (or
31
- # [StreamingDetectIntent][google.cloud.dialogflow.v2.Sessions.StreamingDetectIntent]) method to determine
32
- # user intent and respond.
33
- class Service
34
-
35
- include GRPC::GenericService
36
-
37
- self.marshal_class_method = :encode
38
- self.unmarshal_class_method = :decode
39
- self.service_name = 'google.cloud.dialogflow.v2.Sessions'
40
-
41
- # Processes a natural language query and returns structured, actionable data
42
- # as a result. This method is not idempotent, because it may cause contexts
43
- # and session entity types to be updated, which in turn might affect
44
- # results of future queries.
45
- rpc :DetectIntent, DetectIntentRequest, DetectIntentResponse
46
- # Processes a natural language query in audio format in a streaming fashion
47
- # and returns structured, actionable data as a result. This method is only
48
- # available via the gRPC API (not REST).
49
- rpc :StreamingDetectIntent, stream(StreamingDetectIntentRequest), stream(StreamingDetectIntentResponse)
50
- end
51
-
52
- Stub = Service.rpc_stub_class
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,326 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/cloud/dialogflow/v2/session.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
-
28
- require "google/cloud/dialogflow/v2/session_pb"
29
- require "google/cloud/dialogflow/v2/credentials"
30
- require "google/cloud/dialogflow/version"
31
-
32
- module Google
33
- module Cloud
34
- module Dialogflow
35
- module V2
36
- # A session represents an interaction with a user. You retrieve user input
37
- # and pass it to the {Google::Cloud::Dialogflow::V2::Sessions::DetectIntent DetectIntent} (or
38
- # {Google::Cloud::Dialogflow::V2::Sessions::StreamingDetectIntent StreamingDetectIntent}) method to determine
39
- # user intent and respond.
40
- #
41
- # @!attribute [r] sessions_stub
42
- # @return [Google::Cloud::Dialogflow::V2::Sessions::Stub]
43
- class SessionsClient
44
- # @private
45
- attr_reader :sessions_stub
46
-
47
- # The default address of the service.
48
- SERVICE_ADDRESS = "dialogflow.googleapis.com".freeze
49
-
50
- # The default port of the service.
51
- DEFAULT_SERVICE_PORT = 443
52
-
53
- # The default set of gRPC interceptors.
54
- GRPC_INTERCEPTORS = []
55
-
56
- DEFAULT_TIMEOUT = 30
57
-
58
- # The scopes needed to make gRPC calls to all of the methods defined in
59
- # this service.
60
- ALL_SCOPES = [
61
- "https://www.googleapis.com/auth/cloud-platform",
62
- "https://www.googleapis.com/auth/dialogflow"
63
- ].freeze
64
-
65
-
66
- SESSION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
67
- "projects/{project}/agent/sessions/{session}"
68
- )
69
-
70
- private_constant :SESSION_PATH_TEMPLATE
71
-
72
- # Returns a fully-qualified session resource name string.
73
- # @param project [String]
74
- # @param session [String]
75
- # @return [String]
76
- def self.session_path project, session
77
- SESSION_PATH_TEMPLATE.render(
78
- :"project" => project,
79
- :"session" => session
80
- )
81
- end
82
-
83
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
84
- # Provides the means for authenticating requests made by the client. This parameter can
85
- # be many types.
86
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
87
- # authenticating requests made by this client.
88
- # A `String` will be treated as the path to the keyfile to be used for the construction of
89
- # credentials for this client.
90
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
91
- # credentials for this client.
92
- # A `GRPC::Core::Channel` will be used to make calls through.
93
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
94
- # should already be composed with a `GRPC::Core::CallCredentials` object.
95
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
96
- # metadata for requests, generally, to give OAuth credentials.
97
- # @param scopes [Array<String>]
98
- # The OAuth scopes for this service. This parameter is ignored if
99
- # an updater_proc is supplied.
100
- # @param client_config [Hash]
101
- # A Hash for call options for each method. See
102
- # Google::Gax#construct_settings for the structure of
103
- # this data. Falls back to the default config if not specified
104
- # or the specified config is missing data points.
105
- # @param timeout [Numeric]
106
- # The default timeout, in seconds, for calls made through this client.
107
- # @param metadata [Hash]
108
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
109
- # @param service_address [String]
110
- # Override for the service hostname, or `nil` to leave as the default.
111
- # @param service_port [Integer]
112
- # Override for the service port, or `nil` to leave as the default.
113
- # @param exception_transformer [Proc]
114
- # An optional proc that intercepts any exceptions raised during an API call to inject
115
- # custom error handling.
116
- def initialize \
117
- credentials: nil,
118
- scopes: ALL_SCOPES,
119
- client_config: {},
120
- timeout: DEFAULT_TIMEOUT,
121
- metadata: nil,
122
- service_address: nil,
123
- service_port: nil,
124
- exception_transformer: nil,
125
- lib_name: nil,
126
- lib_version: ""
127
- # These require statements are intentionally placed here to initialize
128
- # the gRPC module only when it's required.
129
- # See https://github.com/googleapis/toolkit/issues/446
130
- require "google/gax/grpc"
131
- require "google/cloud/dialogflow/v2/session_services_pb"
132
-
133
- credentials ||= Google::Cloud::Dialogflow::V2::Credentials.default
134
-
135
- if credentials.is_a?(String) || credentials.is_a?(Hash)
136
- updater_proc = Google::Cloud::Dialogflow::V2::Credentials.new(credentials).updater_proc
137
- end
138
- if credentials.is_a?(GRPC::Core::Channel)
139
- channel = credentials
140
- end
141
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
142
- chan_creds = credentials
143
- end
144
- if credentials.is_a?(Proc)
145
- updater_proc = credentials
146
- end
147
- if credentials.is_a?(Google::Auth::Credentials)
148
- updater_proc = credentials.updater_proc
149
- end
150
-
151
- package_version = Google::Cloud::Dialogflow::VERSION
152
-
153
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
154
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
155
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
156
- google_api_client << " grpc/#{GRPC::VERSION}"
157
- google_api_client.freeze
158
-
159
- headers = { :"x-goog-api-client" => google_api_client }
160
- headers.merge!(metadata) unless metadata.nil?
161
- client_config_file = Pathname.new(__dir__).join(
162
- "sessions_client_config.json"
163
- )
164
- defaults = client_config_file.open do |f|
165
- Google::Gax.construct_settings(
166
- "google.cloud.dialogflow.v2.Sessions",
167
- JSON.parse(f.read),
168
- client_config,
169
- Google::Gax::Grpc::STATUS_CODE_NAMES,
170
- timeout,
171
- errors: Google::Gax::Grpc::API_ERRORS,
172
- metadata: headers
173
- )
174
- end
175
-
176
- # Allow overriding the service path/port in subclasses.
177
- service_path = service_address || self.class::SERVICE_ADDRESS
178
- port = service_port || self.class::DEFAULT_SERVICE_PORT
179
- interceptors = self.class::GRPC_INTERCEPTORS
180
- @sessions_stub = Google::Gax::Grpc.create_stub(
181
- service_path,
182
- port,
183
- chan_creds: chan_creds,
184
- channel: channel,
185
- updater_proc: updater_proc,
186
- scopes: scopes,
187
- interceptors: interceptors,
188
- &Google::Cloud::Dialogflow::V2::Sessions::Stub.method(:new)
189
- )
190
-
191
- @detect_intent = Google::Gax.create_api_call(
192
- @sessions_stub.method(:detect_intent),
193
- defaults["detect_intent"],
194
- exception_transformer: exception_transformer,
195
- params_extractor: proc do |request|
196
- {'session' => request.session}
197
- end
198
- )
199
- @streaming_detect_intent = Google::Gax.create_api_call(
200
- @sessions_stub.method(:streaming_detect_intent),
201
- defaults["streaming_detect_intent"],
202
- exception_transformer: exception_transformer
203
- )
204
- end
205
-
206
- # Service calls
207
-
208
- # Processes a natural language query and returns structured, actionable data
209
- # as a result. This method is not idempotent, because it may cause contexts
210
- # and session entity types to be updated, which in turn might affect
211
- # results of future queries.
212
- #
213
- # @param session [String]
214
- # Required. The name of the session this query is sent to. Format:
215
- # `projects/<Project ID>/agent/sessions/<Session ID>`. It's up to the API
216
- # caller to choose an appropriate session ID. It can be a random number or
217
- # some type of user identifier (preferably hashed). The length of the session
218
- # ID must not exceed 36 bytes.
219
- # @param query_input [Google::Cloud::Dialogflow::V2::QueryInput | Hash]
220
- # Required. The input specification. It can be set to:
221
- #
222
- # 1. an audio config
223
- # which instructs the speech recognizer how to process the speech audio,
224
- #
225
- # 2. a conversational query in the form of text, or
226
- #
227
- # 3. an event that specifies which intent to trigger.
228
- # A hash of the same form as `Google::Cloud::Dialogflow::V2::QueryInput`
229
- # can also be provided.
230
- # @param query_params [Google::Cloud::Dialogflow::V2::QueryParameters | Hash]
231
- # Optional. The parameters of this query.
232
- # A hash of the same form as `Google::Cloud::Dialogflow::V2::QueryParameters`
233
- # can also be provided.
234
- # @param output_audio_config [Google::Cloud::Dialogflow::V2::OutputAudioConfig | Hash]
235
- # Optional. Instructs the speech synthesizer how to generate the output
236
- # audio. If this field is not set and agent-level speech synthesizer is not
237
- # configured, no output audio is generated.
238
- # A hash of the same form as `Google::Cloud::Dialogflow::V2::OutputAudioConfig`
239
- # can also be provided.
240
- # @param input_audio [String]
241
- # Optional. The natural language speech audio to be processed. This field
242
- # should be populated iff `query_input` is set to an input audio config.
243
- # A single request can contain up to 1 minute of speech audio data.
244
- # @param options [Google::Gax::CallOptions]
245
- # Overrides the default settings for this call, e.g, timeout,
246
- # retries, etc.
247
- # @yield [result, operation] Access the result along with the RPC operation
248
- # @yieldparam result [Google::Cloud::Dialogflow::V2::DetectIntentResponse]
249
- # @yieldparam operation [GRPC::ActiveCall::Operation]
250
- # @return [Google::Cloud::Dialogflow::V2::DetectIntentResponse]
251
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
252
- # @example
253
- # require "google/cloud/dialogflow"
254
- #
255
- # sessions_client = Google::Cloud::Dialogflow::Sessions.new(version: :v2)
256
- # formatted_session = Google::Cloud::Dialogflow::V2::SessionsClient.session_path("[PROJECT]", "[SESSION]")
257
- #
258
- # # TODO: Initialize `query_input`:
259
- # query_input = {}
260
- # response = sessions_client.detect_intent(formatted_session, query_input)
261
-
262
- def detect_intent \
263
- session,
264
- query_input,
265
- query_params: nil,
266
- output_audio_config: nil,
267
- input_audio: nil,
268
- options: nil,
269
- &block
270
- req = {
271
- session: session,
272
- query_input: query_input,
273
- query_params: query_params,
274
- output_audio_config: output_audio_config,
275
- input_audio: input_audio
276
- }.delete_if { |_, v| v.nil? }
277
- req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::DetectIntentRequest)
278
- @detect_intent.call(req, options, &block)
279
- end
280
-
281
- # Processes a natural language query in audio format in a streaming fashion
282
- # and returns structured, actionable data as a result. This method is only
283
- # available via the gRPC API (not REST).
284
- #
285
- # @param reqs [Enumerable<Google::Cloud::Dialogflow::V2::StreamingDetectIntentRequest>]
286
- # The input requests.
287
- # @param options [Google::Gax::CallOptions]
288
- # Overrides the default settings for this call, e.g, timeout,
289
- # retries, etc.
290
- # @return [Enumerable<Google::Cloud::Dialogflow::V2::StreamingDetectIntentResponse>]
291
- # An enumerable of Google::Cloud::Dialogflow::V2::StreamingDetectIntentResponse instances.
292
- #
293
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
294
- #
295
- # @note
296
- # EXPERIMENTAL:
297
- # Streaming requests are still undergoing review.
298
- # This method interface might change in the future.
299
- #
300
- # @example
301
- # require "google/cloud/dialogflow"
302
- #
303
- # sessions_client = Google::Cloud::Dialogflow::Sessions.new(version: :v2)
304
- #
305
- # # TODO: Initialize `session`:
306
- # session = ''
307
- #
308
- # # TODO: Initialize `query_input`:
309
- # query_input = {}
310
- # request = { session: session, query_input: query_input }
311
- # requests = [request]
312
- # sessions_client.streaming_detect_intent(requests).each do |element|
313
- # # Process element.
314
- # end
315
-
316
- def streaming_detect_intent reqs, options: nil
317
- request_protos = reqs.lazy.map do |req|
318
- Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::StreamingDetectIntentRequest)
319
- end
320
- @streaming_detect_intent.call(request_protos, options)
321
- end
322
- end
323
- end
324
- end
325
- end
326
- end