google-cloud-dialogflow 0.15.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) 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 +397 -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 +368 -506
  9. data/lib/google/cloud/dialogflow/version.rb +1 -1
  10. metadata +88 -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 -121
  14. data/lib/google/cloud/dialogflow/v2/agent_services_pb.rb +0 -111
  15. data/lib/google/cloud/dialogflow/v2/agents_client.rb +0 -810
  16. data/lib/google/cloud/dialogflow/v2/agents_client_config.json +0 -71
  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 -75
  20. data/lib/google/cloud/dialogflow/v2/contexts_client.rb +0 -522
  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 -247
  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 -498
  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/cloud/dialogflow/v2/validation_result.rb +0 -71
  31. data/lib/google/cloud/dialogflow/v2/doc/google/longrunning/operations.rb +0 -51
  32. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/any.rb +0 -131
  33. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/duration.rb +0 -91
  34. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/field_mask.rb +0 -222
  35. data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/struct.rb +0 -74
  36. data/lib/google/cloud/dialogflow/v2/doc/google/rpc/status.rb +0 -39
  37. data/lib/google/cloud/dialogflow/v2/doc/google/type/latlng.rb +0 -31
  38. data/lib/google/cloud/dialogflow/v2/entity_type_pb.rb +0 -125
  39. data/lib/google/cloud/dialogflow/v2/entity_type_services_pb.rb +0 -105
  40. data/lib/google/cloud/dialogflow/v2/entity_types_client.rb +0 -997
  41. data/lib/google/cloud/dialogflow/v2/entity_types_client_config.json +0 -76
  42. data/lib/google/cloud/dialogflow/v2/intent_pb.rb +0 -367
  43. data/lib/google/cloud/dialogflow/v2/intent_services_pb.rb +0 -93
  44. data/lib/google/cloud/dialogflow/v2/intents_client.rb +0 -763
  45. data/lib/google/cloud/dialogflow/v2/intents_client_config.json +0 -61
  46. data/lib/google/cloud/dialogflow/v2/session_entity_type_pb.rb +0 -65
  47. data/lib/google/cloud/dialogflow/v2/session_entity_type_services_pb.rb +0 -93
  48. data/lib/google/cloud/dialogflow/v2/session_entity_types_client.rb +0 -507
  49. data/lib/google/cloud/dialogflow/v2/session_entity_types_client_config.json +0 -51
  50. data/lib/google/cloud/dialogflow/v2/session_pb.rb +0 -141
  51. data/lib/google/cloud/dialogflow/v2/session_services_pb.rb +0 -56
  52. data/lib/google/cloud/dialogflow/v2/sessions_client.rb +0 -340
  53. data/lib/google/cloud/dialogflow/v2/sessions_client_config.json +0 -36
  54. data/lib/google/cloud/dialogflow/v2/validation_result_pb.rb +0 -36
  55. 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,141 +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/field_mask_pb'
17
- require 'google/protobuf/struct_pb'
18
- require 'google/rpc/status_pb'
19
- require 'google/type/latlng_pb'
20
- Google::Protobuf::DescriptorPool.generated_pool.build do
21
- add_message "google.cloud.dialogflow.v2.DetectIntentRequest" do
22
- optional :session, :string, 1
23
- optional :query_params, :message, 2, "google.cloud.dialogflow.v2.QueryParameters"
24
- optional :query_input, :message, 3, "google.cloud.dialogflow.v2.QueryInput"
25
- optional :output_audio_config, :message, 4, "google.cloud.dialogflow.v2.OutputAudioConfig"
26
- optional :output_audio_config_mask, :message, 7, "google.protobuf.FieldMask"
27
- optional :input_audio, :bytes, 5
28
- end
29
- add_message "google.cloud.dialogflow.v2.DetectIntentResponse" do
30
- optional :response_id, :string, 1
31
- optional :query_result, :message, 2, "google.cloud.dialogflow.v2.QueryResult"
32
- optional :webhook_status, :message, 3, "google.rpc.Status"
33
- optional :output_audio, :bytes, 4
34
- optional :output_audio_config, :message, 6, "google.cloud.dialogflow.v2.OutputAudioConfig"
35
- end
36
- add_message "google.cloud.dialogflow.v2.QueryParameters" do
37
- optional :time_zone, :string, 1
38
- optional :geo_location, :message, 2, "google.type.LatLng"
39
- repeated :contexts, :message, 3, "google.cloud.dialogflow.v2.Context"
40
- optional :reset_contexts, :bool, 4
41
- repeated :session_entity_types, :message, 5, "google.cloud.dialogflow.v2.SessionEntityType"
42
- optional :payload, :message, 6, "google.protobuf.Struct"
43
- optional :sentiment_analysis_request_config, :message, 10, "google.cloud.dialogflow.v2.SentimentAnalysisRequestConfig"
44
- end
45
- add_message "google.cloud.dialogflow.v2.QueryInput" do
46
- oneof :input do
47
- optional :audio_config, :message, 1, "google.cloud.dialogflow.v2.InputAudioConfig"
48
- optional :text, :message, 2, "google.cloud.dialogflow.v2.TextInput"
49
- optional :event, :message, 3, "google.cloud.dialogflow.v2.EventInput"
50
- end
51
- end
52
- add_message "google.cloud.dialogflow.v2.QueryResult" do
53
- optional :query_text, :string, 1
54
- optional :language_code, :string, 15
55
- optional :speech_recognition_confidence, :float, 2
56
- optional :action, :string, 3
57
- optional :parameters, :message, 4, "google.protobuf.Struct"
58
- optional :all_required_params_present, :bool, 5
59
- optional :fulfillment_text, :string, 6
60
- repeated :fulfillment_messages, :message, 7, "google.cloud.dialogflow.v2.Intent.Message"
61
- optional :webhook_source, :string, 8
62
- optional :webhook_payload, :message, 9, "google.protobuf.Struct"
63
- repeated :output_contexts, :message, 10, "google.cloud.dialogflow.v2.Context"
64
- optional :intent, :message, 11, "google.cloud.dialogflow.v2.Intent"
65
- optional :intent_detection_confidence, :float, 12
66
- optional :diagnostic_info, :message, 14, "google.protobuf.Struct"
67
- optional :sentiment_analysis_result, :message, 17, "google.cloud.dialogflow.v2.SentimentAnalysisResult"
68
- end
69
- add_message "google.cloud.dialogflow.v2.StreamingDetectIntentRequest" do
70
- optional :session, :string, 1
71
- optional :query_params, :message, 2, "google.cloud.dialogflow.v2.QueryParameters"
72
- optional :query_input, :message, 3, "google.cloud.dialogflow.v2.QueryInput"
73
- optional :single_utterance, :bool, 4
74
- optional :output_audio_config, :message, 5, "google.cloud.dialogflow.v2.OutputAudioConfig"
75
- optional :output_audio_config_mask, :message, 7, "google.protobuf.FieldMask"
76
- optional :input_audio, :bytes, 6
77
- end
78
- add_message "google.cloud.dialogflow.v2.StreamingDetectIntentResponse" do
79
- optional :response_id, :string, 1
80
- optional :recognition_result, :message, 2, "google.cloud.dialogflow.v2.StreamingRecognitionResult"
81
- optional :query_result, :message, 3, "google.cloud.dialogflow.v2.QueryResult"
82
- optional :webhook_status, :message, 4, "google.rpc.Status"
83
- optional :output_audio, :bytes, 5
84
- optional :output_audio_config, :message, 6, "google.cloud.dialogflow.v2.OutputAudioConfig"
85
- end
86
- add_message "google.cloud.dialogflow.v2.StreamingRecognitionResult" do
87
- optional :message_type, :enum, 1, "google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType"
88
- optional :transcript, :string, 2
89
- optional :is_final, :bool, 3
90
- optional :confidence, :float, 4
91
- repeated :speech_word_info, :message, 7, "google.cloud.dialogflow.v2.SpeechWordInfo"
92
- optional :speech_end_offset, :message, 8, "google.protobuf.Duration"
93
- end
94
- add_enum "google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType" do
95
- value :MESSAGE_TYPE_UNSPECIFIED, 0
96
- value :TRANSCRIPT, 1
97
- value :END_OF_SINGLE_UTTERANCE, 2
98
- end
99
- add_message "google.cloud.dialogflow.v2.TextInput" do
100
- optional :text, :string, 1
101
- optional :language_code, :string, 2
102
- end
103
- add_message "google.cloud.dialogflow.v2.EventInput" do
104
- optional :name, :string, 1
105
- optional :parameters, :message, 2, "google.protobuf.Struct"
106
- optional :language_code, :string, 3
107
- end
108
- add_message "google.cloud.dialogflow.v2.SentimentAnalysisRequestConfig" do
109
- optional :analyze_query_text_sentiment, :bool, 1
110
- end
111
- add_message "google.cloud.dialogflow.v2.SentimentAnalysisResult" do
112
- optional :query_text_sentiment, :message, 1, "google.cloud.dialogflow.v2.Sentiment"
113
- end
114
- add_message "google.cloud.dialogflow.v2.Sentiment" do
115
- optional :score, :float, 1
116
- optional :magnitude, :float, 2
117
- end
118
- end
119
-
120
- module Google
121
- module Cloud
122
- module Dialogflow
123
- module V2
124
- DetectIntentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.DetectIntentRequest").msgclass
125
- DetectIntentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.DetectIntentResponse").msgclass
126
- QueryParameters = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryParameters").msgclass
127
- QueryInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryInput").msgclass
128
- QueryResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryResult").msgclass
129
- StreamingDetectIntentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingDetectIntentRequest").msgclass
130
- StreamingDetectIntentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingDetectIntentResponse").msgclass
131
- StreamingRecognitionResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingRecognitionResult").msgclass
132
- StreamingRecognitionResult::MessageType = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType").enummodule
133
- TextInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.TextInput").msgclass
134
- EventInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.EventInput").msgclass
135
- SentimentAnalysisRequestConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.SentimentAnalysisRequestConfig").msgclass
136
- SentimentAnalysisResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.SentimentAnalysisResult").msgclass
137
- Sentiment = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.Sentiment").msgclass
138
- end
139
- end
140
- end
141
- end
@@ -1,56 +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 2020 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
- require 'grpc'
21
- require 'google/cloud/dialogflow/v2/session_pb'
22
-
23
- module Google
24
- module Cloud
25
- module Dialogflow
26
- module V2
27
- module Sessions
28
- # A session represents an interaction with a user. You retrieve user input
29
- # and pass it to the [DetectIntent][google.cloud.dialogflow.v2.Sessions.DetectIntent] (or
30
- # [StreamingDetectIntent][google.cloud.dialogflow.v2.Sessions.StreamingDetectIntent]) method to determine
31
- # user intent and respond.
32
- class Service
33
-
34
- include GRPC::GenericService
35
-
36
- self.marshal_class_method = :encode
37
- self.unmarshal_class_method = :decode
38
- self.service_name = 'google.cloud.dialogflow.v2.Sessions'
39
-
40
- # Processes a natural language query and returns structured, actionable data
41
- # as a result. This method is not idempotent, because it may cause contexts
42
- # and session entity types to be updated, which in turn might affect
43
- # results of future queries.
44
- rpc :DetectIntent, DetectIntentRequest, DetectIntentResponse
45
- # Processes a natural language query in audio format in a streaming fashion
46
- # and returns structured, actionable data as a result. This method is only
47
- # available via the gRPC API (not REST).
48
- rpc :StreamingDetectIntent, stream(StreamingDetectIntentRequest), stream(StreamingDetectIntentResponse)
49
- end
50
-
51
- Stub = Service.rpc_stub_class
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,340 +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
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
161
- headers[:"x-goog-user-project"] = credentials.quota_project_id
162
- end
163
- headers.merge!(metadata) unless metadata.nil?
164
- client_config_file = Pathname.new(__dir__).join(
165
- "sessions_client_config.json"
166
- )
167
- defaults = client_config_file.open do |f|
168
- Google::Gax.construct_settings(
169
- "google.cloud.dialogflow.v2.Sessions",
170
- JSON.parse(f.read),
171
- client_config,
172
- Google::Gax::Grpc::STATUS_CODE_NAMES,
173
- timeout,
174
- errors: Google::Gax::Grpc::API_ERRORS,
175
- metadata: headers
176
- )
177
- end
178
-
179
- # Allow overriding the service path/port in subclasses.
180
- service_path = service_address || self.class::SERVICE_ADDRESS
181
- port = service_port || self.class::DEFAULT_SERVICE_PORT
182
- interceptors = self.class::GRPC_INTERCEPTORS
183
- @sessions_stub = Google::Gax::Grpc.create_stub(
184
- service_path,
185
- port,
186
- chan_creds: chan_creds,
187
- channel: channel,
188
- updater_proc: updater_proc,
189
- scopes: scopes,
190
- interceptors: interceptors,
191
- &Google::Cloud::Dialogflow::V2::Sessions::Stub.method(:new)
192
- )
193
-
194
- @detect_intent = Google::Gax.create_api_call(
195
- @sessions_stub.method(:detect_intent),
196
- defaults["detect_intent"],
197
- exception_transformer: exception_transformer,
198
- params_extractor: proc do |request|
199
- {'session' => request.session}
200
- end
201
- )
202
- @streaming_detect_intent = Google::Gax.create_api_call(
203
- @sessions_stub.method(:streaming_detect_intent),
204
- defaults["streaming_detect_intent"],
205
- exception_transformer: exception_transformer
206
- )
207
- end
208
-
209
- # Service calls
210
-
211
- # Processes a natural language query and returns structured, actionable data
212
- # as a result. This method is not idempotent, because it may cause contexts
213
- # and session entity types to be updated, which in turn might affect
214
- # results of future queries.
215
- #
216
- # @param session [String]
217
- # Required. The name of the session this query is sent to. Format:
218
- # `projects/<Project ID>/agent/sessions/<Session ID>`. It's up to the API
219
- # caller to choose an appropriate session ID. It can be a random number or
220
- # some type of user identifier (preferably hashed). The length of the session
221
- # ID must not exceed 36 bytes.
222
- # @param query_input [Google::Cloud::Dialogflow::V2::QueryInput | Hash]
223
- # Required. The input specification. It can be set to:
224
- #
225
- # 1. an audio config
226
- # which instructs the speech recognizer how to process the speech audio,
227
- #
228
- # 2. a conversational query in the form of text, or
229
- #
230
- # 3. an event that specifies which intent to trigger.
231
- # A hash of the same form as `Google::Cloud::Dialogflow::V2::QueryInput`
232
- # can also be provided.
233
- # @param query_params [Google::Cloud::Dialogflow::V2::QueryParameters | Hash]
234
- # The parameters of this query.
235
- # A hash of the same form as `Google::Cloud::Dialogflow::V2::QueryParameters`
236
- # can also be provided.
237
- # @param output_audio_config [Google::Cloud::Dialogflow::V2::OutputAudioConfig | Hash]
238
- # Instructs the speech synthesizer how to generate the output
239
- # audio. If this field is not set and agent-level speech synthesizer is not
240
- # configured, no output audio is generated.
241
- # A hash of the same form as `Google::Cloud::Dialogflow::V2::OutputAudioConfig`
242
- # can also be provided.
243
- # @param output_audio_config_mask [Google::Protobuf::FieldMask | Hash]
244
- # Mask for {Google::Cloud::Dialogflow::V2::DetectIntentRequest#output_audio_config output_audio_config} indicating which settings in this
245
- # request-level config should override speech synthesizer settings defined at
246
- # agent-level.
247
- #
248
- # If unspecified or empty, {Google::Cloud::Dialogflow::V2::DetectIntentRequest#output_audio_config output_audio_config} replaces the agent-level
249
- # config in its entirety.
250
- # A hash of the same form as `Google::Protobuf::FieldMask`
251
- # can also be provided.
252
- # @param input_audio [String]
253
- # The natural language speech audio to be processed. This field
254
- # should be populated iff `query_input` is set to an input audio config.
255
- # A single request can contain up to 1 minute of speech audio data.
256
- # @param options [Google::Gax::CallOptions]
257
- # Overrides the default settings for this call, e.g, timeout,
258
- # retries, etc.
259
- # @yield [result, operation] Access the result along with the RPC operation
260
- # @yieldparam result [Google::Cloud::Dialogflow::V2::DetectIntentResponse]
261
- # @yieldparam operation [GRPC::ActiveCall::Operation]
262
- # @return [Google::Cloud::Dialogflow::V2::DetectIntentResponse]
263
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
264
- # @example
265
- # require "google/cloud/dialogflow"
266
- #
267
- # sessions_client = Google::Cloud::Dialogflow::Sessions.new(version: :v2)
268
- # formatted_session = Google::Cloud::Dialogflow::V2::SessionsClient.session_path("[PROJECT]", "[SESSION]")
269
- #
270
- # # TODO: Initialize `query_input`:
271
- # query_input = {}
272
- # response = sessions_client.detect_intent(formatted_session, query_input)
273
-
274
- def detect_intent \
275
- session,
276
- query_input,
277
- query_params: nil,
278
- output_audio_config: nil,
279
- output_audio_config_mask: nil,
280
- input_audio: nil,
281
- options: nil,
282
- &block
283
- req = {
284
- session: session,
285
- query_input: query_input,
286
- query_params: query_params,
287
- output_audio_config: output_audio_config,
288
- output_audio_config_mask: output_audio_config_mask,
289
- input_audio: input_audio
290
- }.delete_if { |_, v| v.nil? }
291
- req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::DetectIntentRequest)
292
- @detect_intent.call(req, options, &block)
293
- end
294
-
295
- # Processes a natural language query in audio format in a streaming fashion
296
- # and returns structured, actionable data as a result. This method is only
297
- # available via the gRPC API (not REST).
298
- #
299
- # @param reqs [Enumerable<Google::Cloud::Dialogflow::V2::StreamingDetectIntentRequest>]
300
- # The input requests.
301
- # @param options [Google::Gax::CallOptions]
302
- # Overrides the default settings for this call, e.g, timeout,
303
- # retries, etc.
304
- # @return [Enumerable<Google::Cloud::Dialogflow::V2::StreamingDetectIntentResponse>]
305
- # An enumerable of Google::Cloud::Dialogflow::V2::StreamingDetectIntentResponse instances.
306
- #
307
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
308
- #
309
- # @note
310
- # EXPERIMENTAL:
311
- # Streaming requests are still undergoing review.
312
- # This method interface might change in the future.
313
- #
314
- # @example
315
- # require "google/cloud/dialogflow"
316
- #
317
- # sessions_client = Google::Cloud::Dialogflow::Sessions.new(version: :v2)
318
- #
319
- # # TODO: Initialize `session`:
320
- # session = ''
321
- #
322
- # # TODO: Initialize `query_input`:
323
- # query_input = {}
324
- # request = { session: session, query_input: query_input }
325
- # requests = [request]
326
- # sessions_client.streaming_detect_intent(requests).each do |element|
327
- # # Process element.
328
- # end
329
-
330
- def streaming_detect_intent reqs, options: nil
331
- request_protos = reqs.lazy.map do |req|
332
- Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::StreamingDetectIntentRequest)
333
- end
334
- @streaming_detect_intent.call(request_protos, options)
335
- end
336
- end
337
- end
338
- end
339
- end
340
- end