google-cloud-dialogflow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +201 -0
- data/README.md +32 -0
- data/lib/google/cloud/dialogflow.rb +452 -0
- data/lib/google/cloud/dialogflow/credentials.rb +30 -0
- data/lib/google/cloud/dialogflow/v2.rb +454 -0
- data/lib/google/cloud/dialogflow/v2/agent_pb.rb +87 -0
- data/lib/google/cloud/dialogflow/v2/agent_services_pb.rb +104 -0
- data/lib/google/cloud/dialogflow/v2/agents_client.rb +639 -0
- data/lib/google/cloud/dialogflow/v2/agents_client_config.json +56 -0
- data/lib/google/cloud/dialogflow/v2/context_pb.rb +59 -0
- data/lib/google/cloud/dialogflow/v2/context_services_pb.rb +71 -0
- data/lib/google/cloud/dialogflow/v2/contexts_client.rb +445 -0
- data/lib/google/cloud/dialogflow/v2/contexts_client_config.json +56 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/agent.rb +223 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/context.rb +115 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/entity_type.rb +290 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/intent.rb +714 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/session.rb +451 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/cloud/dialogflow/v2/session_entity_type.rb +134 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/any.rb +124 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/field_mask.rb +223 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/protobuf/struct.rb +73 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/dialogflow/v2/doc/google/type/latlng.rb +64 -0
- data/lib/google/cloud/dialogflow/v2/doc/overview.rb +55 -0
- data/lib/google/cloud/dialogflow/v2/entity_type_pb.rb +120 -0
- data/lib/google/cloud/dialogflow/v2/entity_type_services_pb.rb +105 -0
- data/lib/google/cloud/dialogflow/v2/entity_types_client.rb +900 -0
- data/lib/google/cloud/dialogflow/v2/entity_types_client_config.json +76 -0
- data/lib/google/cloud/dialogflow/v2/intent_pb.rb +274 -0
- data/lib/google/cloud/dialogflow/v2/intent_services_pb.rb +91 -0
- data/lib/google/cloud/dialogflow/v2/intents_client.rb +684 -0
- data/lib/google/cloud/dialogflow/v2/intents_client_config.json +61 -0
- data/lib/google/cloud/dialogflow/v2/session_entity_type_pb.rb +61 -0
- data/lib/google/cloud/dialogflow/v2/session_entity_type_services_pb.rb +64 -0
- data/lib/google/cloud/dialogflow/v2/session_entity_types_client.rb +413 -0
- data/lib/google/cloud/dialogflow/v2/session_entity_types_client_config.json +51 -0
- data/lib/google/cloud/dialogflow/v2/session_pb.rb +127 -0
- data/lib/google/cloud/dialogflow/v2/session_services_pb.rb +55 -0
- data/lib/google/cloud/dialogflow/v2/sessions_client.rb +286 -0
- data/lib/google/cloud/dialogflow/v2/sessions_client_config.json +36 -0
- data/lib/google/cloud/dialogflow/v2/webhook_pb.rb +42 -0
- metadata +142 -0
@@ -0,0 +1,51 @@
|
|
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
|
+
}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: google/cloud/dialogflow/v2/session.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
require 'google/api/annotations_pb'
|
7
|
+
require 'google/cloud/dialogflow/v2/context_pb'
|
8
|
+
require 'google/cloud/dialogflow/v2/intent_pb'
|
9
|
+
require 'google/cloud/dialogflow/v2/session_entity_type_pb'
|
10
|
+
require 'google/protobuf/struct_pb'
|
11
|
+
require 'google/rpc/status_pb'
|
12
|
+
require 'google/type/latlng_pb'
|
13
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
14
|
+
add_message "google.cloud.dialogflow.v2.DetectIntentRequest" do
|
15
|
+
optional :session, :string, 1
|
16
|
+
optional :query_params, :message, 2, "google.cloud.dialogflow.v2.QueryParameters"
|
17
|
+
optional :query_input, :message, 3, "google.cloud.dialogflow.v2.QueryInput"
|
18
|
+
optional :input_audio, :bytes, 5
|
19
|
+
end
|
20
|
+
add_message "google.cloud.dialogflow.v2.DetectIntentResponse" do
|
21
|
+
optional :response_id, :string, 1
|
22
|
+
optional :query_result, :message, 2, "google.cloud.dialogflow.v2.QueryResult"
|
23
|
+
optional :webhook_status, :message, 3, "google.rpc.Status"
|
24
|
+
end
|
25
|
+
add_message "google.cloud.dialogflow.v2.QueryParameters" do
|
26
|
+
optional :time_zone, :string, 1
|
27
|
+
optional :geo_location, :message, 2, "google.type.LatLng"
|
28
|
+
repeated :contexts, :message, 3, "google.cloud.dialogflow.v2.Context"
|
29
|
+
optional :reset_contexts, :bool, 4
|
30
|
+
repeated :session_entity_types, :message, 5, "google.cloud.dialogflow.v2.SessionEntityType"
|
31
|
+
optional :payload, :message, 6, "google.protobuf.Struct"
|
32
|
+
end
|
33
|
+
add_message "google.cloud.dialogflow.v2.QueryInput" do
|
34
|
+
oneof :input do
|
35
|
+
optional :audio_config, :message, 1, "google.cloud.dialogflow.v2.InputAudioConfig"
|
36
|
+
optional :text, :message, 2, "google.cloud.dialogflow.v2.TextInput"
|
37
|
+
optional :event, :message, 3, "google.cloud.dialogflow.v2.EventInput"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
add_message "google.cloud.dialogflow.v2.QueryResult" do
|
41
|
+
optional :query_text, :string, 1
|
42
|
+
optional :language_code, :string, 15
|
43
|
+
optional :speech_recognition_confidence, :float, 2
|
44
|
+
optional :action, :string, 3
|
45
|
+
optional :parameters, :message, 4, "google.protobuf.Struct"
|
46
|
+
optional :all_required_params_present, :bool, 5
|
47
|
+
optional :fulfillment_text, :string, 6
|
48
|
+
repeated :fulfillment_messages, :message, 7, "google.cloud.dialogflow.v2.Intent.Message"
|
49
|
+
optional :webhook_source, :string, 8
|
50
|
+
optional :webhook_payload, :message, 9, "google.protobuf.Struct"
|
51
|
+
repeated :output_contexts, :message, 10, "google.cloud.dialogflow.v2.Context"
|
52
|
+
optional :intent, :message, 11, "google.cloud.dialogflow.v2.Intent"
|
53
|
+
optional :intent_detection_confidence, :float, 12
|
54
|
+
optional :diagnostic_info, :message, 14, "google.protobuf.Struct"
|
55
|
+
end
|
56
|
+
add_message "google.cloud.dialogflow.v2.StreamingDetectIntentRequest" do
|
57
|
+
optional :session, :string, 1
|
58
|
+
optional :query_params, :message, 2, "google.cloud.dialogflow.v2.QueryParameters"
|
59
|
+
optional :query_input, :message, 3, "google.cloud.dialogflow.v2.QueryInput"
|
60
|
+
optional :single_utterance, :bool, 4
|
61
|
+
optional :input_audio, :bytes, 6
|
62
|
+
end
|
63
|
+
add_message "google.cloud.dialogflow.v2.StreamingDetectIntentResponse" do
|
64
|
+
optional :response_id, :string, 1
|
65
|
+
optional :recognition_result, :message, 2, "google.cloud.dialogflow.v2.StreamingRecognitionResult"
|
66
|
+
optional :query_result, :message, 3, "google.cloud.dialogflow.v2.QueryResult"
|
67
|
+
optional :webhook_status, :message, 4, "google.rpc.Status"
|
68
|
+
end
|
69
|
+
add_message "google.cloud.dialogflow.v2.StreamingRecognitionResult" do
|
70
|
+
optional :message_type, :enum, 1, "google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType"
|
71
|
+
optional :transcript, :string, 2
|
72
|
+
optional :is_final, :bool, 3
|
73
|
+
optional :confidence, :float, 4
|
74
|
+
end
|
75
|
+
add_enum "google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType" do
|
76
|
+
value :MESSAGE_TYPE_UNSPECIFIED, 0
|
77
|
+
value :TRANSCRIPT, 1
|
78
|
+
value :END_OF_SINGLE_UTTERANCE, 2
|
79
|
+
end
|
80
|
+
add_message "google.cloud.dialogflow.v2.InputAudioConfig" do
|
81
|
+
optional :audio_encoding, :enum, 1, "google.cloud.dialogflow.v2.AudioEncoding"
|
82
|
+
optional :sample_rate_hertz, :int32, 2
|
83
|
+
optional :language_code, :string, 3
|
84
|
+
repeated :phrase_hints, :string, 4
|
85
|
+
end
|
86
|
+
add_message "google.cloud.dialogflow.v2.TextInput" do
|
87
|
+
optional :text, :string, 1
|
88
|
+
optional :language_code, :string, 2
|
89
|
+
end
|
90
|
+
add_message "google.cloud.dialogflow.v2.EventInput" do
|
91
|
+
optional :name, :string, 1
|
92
|
+
optional :parameters, :message, 2, "google.protobuf.Struct"
|
93
|
+
optional :language_code, :string, 3
|
94
|
+
end
|
95
|
+
add_enum "google.cloud.dialogflow.v2.AudioEncoding" do
|
96
|
+
value :AUDIO_ENCODING_UNSPECIFIED, 0
|
97
|
+
value :AUDIO_ENCODING_LINEAR_16, 1
|
98
|
+
value :AUDIO_ENCODING_FLAC, 2
|
99
|
+
value :AUDIO_ENCODING_MULAW, 3
|
100
|
+
value :AUDIO_ENCODING_AMR, 4
|
101
|
+
value :AUDIO_ENCODING_AMR_WB, 5
|
102
|
+
value :AUDIO_ENCODING_OGG_OPUS, 6
|
103
|
+
value :AUDIO_ENCODING_SPEEX_WITH_HEADER_BYTE, 7
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
module Google
|
108
|
+
module Cloud
|
109
|
+
module Dialogflow
|
110
|
+
module V2
|
111
|
+
DetectIntentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.DetectIntentRequest").msgclass
|
112
|
+
DetectIntentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.DetectIntentResponse").msgclass
|
113
|
+
QueryParameters = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryParameters").msgclass
|
114
|
+
QueryInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryInput").msgclass
|
115
|
+
QueryResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.QueryResult").msgclass
|
116
|
+
StreamingDetectIntentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingDetectIntentRequest").msgclass
|
117
|
+
StreamingDetectIntentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingDetectIntentResponse").msgclass
|
118
|
+
StreamingRecognitionResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingRecognitionResult").msgclass
|
119
|
+
StreamingRecognitionResult::MessageType = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.StreamingRecognitionResult.MessageType").enummodule
|
120
|
+
InputAudioConfig = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.InputAudioConfig").msgclass
|
121
|
+
TextInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.TextInput").msgclass
|
122
|
+
EventInput = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.EventInput").msgclass
|
123
|
+
AudioEncoding = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.AudioEncoding").enummodule
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,55 @@
|
|
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 2018 Google Inc.
|
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
|
+
require 'grpc'
|
20
|
+
require 'google/cloud/dialogflow/v2/session_pb'
|
21
|
+
|
22
|
+
module Google
|
23
|
+
module Cloud
|
24
|
+
module Dialogflow
|
25
|
+
module V2
|
26
|
+
module Sessions
|
27
|
+
# A session represents an interaction with a user. You retrieve user input
|
28
|
+
# and pass it to the [DetectIntent][google.cloud.dialogflow.v2.Sessions.DetectIntent] (or
|
29
|
+
# [StreamingDetectIntent][google.cloud.dialogflow.v2.Sessions.StreamingDetectIntent]) method to determine
|
30
|
+
# user intent and respond.
|
31
|
+
class Service
|
32
|
+
|
33
|
+
include GRPC::GenericService
|
34
|
+
|
35
|
+
self.marshal_class_method = :encode
|
36
|
+
self.unmarshal_class_method = :decode
|
37
|
+
self.service_name = 'google.cloud.dialogflow.v2.Sessions'
|
38
|
+
|
39
|
+
# Processes a natural language query and returns structured, actionable data
|
40
|
+
# as a result. This method is not idempotent, because it may cause contexts
|
41
|
+
# and session entity types to be updated, which in turn might affect
|
42
|
+
# results of future queries.
|
43
|
+
rpc :DetectIntent, DetectIntentRequest, DetectIntentResponse
|
44
|
+
# Processes a natural language query in audio format in a streaming fashion
|
45
|
+
# and returns structured, actionable data as a result. This method is only
|
46
|
+
# available via the gRPC API (not REST).
|
47
|
+
rpc :StreamingDetectIntent, stream(StreamingDetectIntentRequest), stream(StreamingDetectIntentResponse)
|
48
|
+
end
|
49
|
+
|
50
|
+
Stub = Service.rpc_stub_class
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,286 @@
|
|
1
|
+
# Copyright 2018 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
|
+
require "json"
|
23
|
+
require "pathname"
|
24
|
+
|
25
|
+
require "google/gax"
|
26
|
+
|
27
|
+
require "google/cloud/dialogflow/v2/session_pb"
|
28
|
+
require "google/cloud/dialogflow/credentials"
|
29
|
+
|
30
|
+
module Google
|
31
|
+
module Cloud
|
32
|
+
module Dialogflow
|
33
|
+
module V2
|
34
|
+
# A session represents an interaction with a user. You retrieve user input
|
35
|
+
# and pass it to the {Google::Cloud::Dialogflow::V2::Sessions::DetectIntent DetectIntent} (or
|
36
|
+
# {Google::Cloud::Dialogflow::V2::Sessions::StreamingDetectIntent StreamingDetectIntent}) method to determine
|
37
|
+
# user intent and respond.
|
38
|
+
#
|
39
|
+
# @!attribute [r] sessions_stub
|
40
|
+
# @return [Google::Cloud::Dialogflow::V2::Sessions::Stub]
|
41
|
+
class SessionsClient
|
42
|
+
attr_reader :sessions_stub
|
43
|
+
|
44
|
+
# The default address of the service.
|
45
|
+
SERVICE_ADDRESS = "dialogflow.googleapis.com".freeze
|
46
|
+
|
47
|
+
# The default port of the service.
|
48
|
+
DEFAULT_SERVICE_PORT = 443
|
49
|
+
|
50
|
+
DEFAULT_TIMEOUT = 30
|
51
|
+
|
52
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
53
|
+
# this service.
|
54
|
+
ALL_SCOPES = [
|
55
|
+
"https://www.googleapis.com/auth/cloud-platform"
|
56
|
+
].freeze
|
57
|
+
|
58
|
+
|
59
|
+
SESSION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
60
|
+
"projects/{project}/agent/sessions/{session}"
|
61
|
+
)
|
62
|
+
|
63
|
+
private_constant :SESSION_PATH_TEMPLATE
|
64
|
+
|
65
|
+
# Returns a fully-qualified session resource name string.
|
66
|
+
# @param project [String]
|
67
|
+
# @param session [String]
|
68
|
+
# @return [String]
|
69
|
+
def self.session_path project, session
|
70
|
+
SESSION_PATH_TEMPLATE.render(
|
71
|
+
:"project" => project,
|
72
|
+
:"session" => session
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
77
|
+
# Provides the means for authenticating requests made by the client. This parameter can
|
78
|
+
# be many types.
|
79
|
+
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
|
80
|
+
# authenticating requests made by this client.
|
81
|
+
# A `String` will be treated as the path to the keyfile to be used for the construction of
|
82
|
+
# credentials for this client.
|
83
|
+
# A `Hash` will be treated as the contents of a keyfile to be used for the construction of
|
84
|
+
# credentials for this client.
|
85
|
+
# A `GRPC::Core::Channel` will be used to make calls through.
|
86
|
+
# A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
|
87
|
+
# should already be composed with a `GRPC::Core::CallCredentials` object.
|
88
|
+
# A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
|
89
|
+
# metadata for requests, generally, to give OAuth credentials.
|
90
|
+
# @param scopes [Array<String>]
|
91
|
+
# The OAuth scopes for this service. This parameter is ignored if
|
92
|
+
# an updater_proc is supplied.
|
93
|
+
# @param client_config [Hash]
|
94
|
+
# A Hash for call options for each method. See
|
95
|
+
# Google::Gax#construct_settings for the structure of
|
96
|
+
# this data. Falls back to the default config if not specified
|
97
|
+
# or the specified config is missing data points.
|
98
|
+
# @param timeout [Numeric]
|
99
|
+
# The default timeout, in seconds, for calls made through this client.
|
100
|
+
def initialize \
|
101
|
+
credentials: nil,
|
102
|
+
scopes: ALL_SCOPES,
|
103
|
+
client_config: {},
|
104
|
+
timeout: DEFAULT_TIMEOUT,
|
105
|
+
lib_name: nil,
|
106
|
+
lib_version: ""
|
107
|
+
# These require statements are intentionally placed here to initialize
|
108
|
+
# the gRPC module only when it's required.
|
109
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
110
|
+
require "google/gax/grpc"
|
111
|
+
require "google/cloud/dialogflow/v2/session_services_pb"
|
112
|
+
|
113
|
+
credentials ||= Google::Cloud::Dialogflow::Credentials.default
|
114
|
+
|
115
|
+
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
116
|
+
updater_proc = Google::Cloud::Dialogflow::Credentials.new(credentials).updater_proc
|
117
|
+
end
|
118
|
+
if credentials.is_a?(GRPC::Core::Channel)
|
119
|
+
channel = credentials
|
120
|
+
end
|
121
|
+
if credentials.is_a?(GRPC::Core::ChannelCredentials)
|
122
|
+
chan_creds = credentials
|
123
|
+
end
|
124
|
+
if credentials.is_a?(Proc)
|
125
|
+
updater_proc = credentials
|
126
|
+
end
|
127
|
+
if credentials.is_a?(Google::Auth::Credentials)
|
128
|
+
updater_proc = credentials.updater_proc
|
129
|
+
end
|
130
|
+
|
131
|
+
package_version = Gem.loaded_specs['google-cloud-dialogflow'].version.version
|
132
|
+
|
133
|
+
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
134
|
+
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
135
|
+
google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
|
136
|
+
google_api_client << " grpc/#{GRPC::VERSION}"
|
137
|
+
google_api_client.freeze
|
138
|
+
|
139
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
140
|
+
client_config_file = Pathname.new(__dir__).join(
|
141
|
+
"sessions_client_config.json"
|
142
|
+
)
|
143
|
+
defaults = client_config_file.open do |f|
|
144
|
+
Google::Gax.construct_settings(
|
145
|
+
"google.cloud.dialogflow.v2.Sessions",
|
146
|
+
JSON.parse(f.read),
|
147
|
+
client_config,
|
148
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
149
|
+
timeout,
|
150
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
151
|
+
kwargs: headers
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Allow overriding the service path/port in subclasses.
|
156
|
+
service_path = self.class::SERVICE_ADDRESS
|
157
|
+
port = self.class::DEFAULT_SERVICE_PORT
|
158
|
+
@sessions_stub = Google::Gax::Grpc.create_stub(
|
159
|
+
service_path,
|
160
|
+
port,
|
161
|
+
chan_creds: chan_creds,
|
162
|
+
channel: channel,
|
163
|
+
updater_proc: updater_proc,
|
164
|
+
scopes: scopes,
|
165
|
+
&Google::Cloud::Dialogflow::V2::Sessions::Stub.method(:new)
|
166
|
+
)
|
167
|
+
|
168
|
+
@detect_intent = Google::Gax.create_api_call(
|
169
|
+
@sessions_stub.method(:detect_intent),
|
170
|
+
defaults["detect_intent"]
|
171
|
+
)
|
172
|
+
@streaming_detect_intent = Google::Gax.create_api_call(
|
173
|
+
@sessions_stub.method(:streaming_detect_intent),
|
174
|
+
defaults["streaming_detect_intent"]
|
175
|
+
)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Service calls
|
179
|
+
|
180
|
+
# Processes a natural language query and returns structured, actionable data
|
181
|
+
# as a result. This method is not idempotent, because it may cause contexts
|
182
|
+
# and session entity types to be updated, which in turn might affect
|
183
|
+
# results of future queries.
|
184
|
+
#
|
185
|
+
# @param session [String]
|
186
|
+
# Required. The name of the session this query is sent to. Format:
|
187
|
+
# +projects/<Project ID>/agent/sessions/<Session ID>+. It's up to the API
|
188
|
+
# caller to choose an appropriate session ID. It can be a random number or
|
189
|
+
# some type of user identifier (preferably hashed). The length of the session
|
190
|
+
# ID must not exceed 36 bytes.
|
191
|
+
# @param query_input [Google::Cloud::Dialogflow::V2::QueryInput | Hash]
|
192
|
+
# Required. The input specification. It can be set to:
|
193
|
+
#
|
194
|
+
# 1. an audio config
|
195
|
+
# which instructs the speech recognizer how to process the speech audio,
|
196
|
+
#
|
197
|
+
# 2. a conversational query in the form of text, or
|
198
|
+
#
|
199
|
+
# 3. an event that specifies which intent to trigger.
|
200
|
+
# A hash of the same form as `Google::Cloud::Dialogflow::V2::QueryInput`
|
201
|
+
# can also be provided.
|
202
|
+
# @param query_params [Google::Cloud::Dialogflow::V2::QueryParameters | Hash]
|
203
|
+
# Optional. The parameters of this query.
|
204
|
+
# A hash of the same form as `Google::Cloud::Dialogflow::V2::QueryParameters`
|
205
|
+
# can also be provided.
|
206
|
+
# @param input_audio [String]
|
207
|
+
# Optional. The natural language speech audio to be processed. This field
|
208
|
+
# should be populated iff +query_input+ is set to an input audio config.
|
209
|
+
# A single request can contain up to 1 minute of speech audio data.
|
210
|
+
# @param options [Google::Gax::CallOptions]
|
211
|
+
# Overrides the default settings for this call, e.g, timeout,
|
212
|
+
# retries, etc.
|
213
|
+
# @return [Google::Cloud::Dialogflow::V2::DetectIntentResponse]
|
214
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
215
|
+
# @example
|
216
|
+
# require "google/cloud/dialogflow/v2"
|
217
|
+
#
|
218
|
+
# sessions_client = Google::Cloud::Dialogflow::V2::Sessions.new
|
219
|
+
# formatted_session = Google::Cloud::Dialogflow::V2::SessionsClient.session_path("[PROJECT]", "[SESSION]")
|
220
|
+
#
|
221
|
+
# # TODO: Initialize +query_input+:
|
222
|
+
# query_input = {}
|
223
|
+
# response = sessions_client.detect_intent(formatted_session, query_input)
|
224
|
+
|
225
|
+
def detect_intent \
|
226
|
+
session,
|
227
|
+
query_input,
|
228
|
+
query_params: nil,
|
229
|
+
input_audio: nil,
|
230
|
+
options: nil
|
231
|
+
req = {
|
232
|
+
session: session,
|
233
|
+
query_input: query_input,
|
234
|
+
query_params: query_params,
|
235
|
+
input_audio: input_audio
|
236
|
+
}.delete_if { |_, v| v.nil? }
|
237
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::DetectIntentRequest)
|
238
|
+
@detect_intent.call(req, options)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Processes a natural language query in audio format in a streaming fashion
|
242
|
+
# and returns structured, actionable data as a result. This method is only
|
243
|
+
# available via the gRPC API (not REST).
|
244
|
+
#
|
245
|
+
# @param reqs [Enumerable<Google::Cloud::Dialogflow::V2::StreamingDetectIntentRequest>]
|
246
|
+
# The input requests.
|
247
|
+
# @param options [Google::Gax::CallOptions]
|
248
|
+
# Overrides the default settings for this call, e.g, timeout,
|
249
|
+
# retries, etc.
|
250
|
+
# @return [Enumerable<Google::Cloud::Dialogflow::V2::StreamingDetectIntentResponse>]
|
251
|
+
# An enumerable of Google::Cloud::Dialogflow::V2::StreamingDetectIntentResponse instances.
|
252
|
+
#
|
253
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
254
|
+
#
|
255
|
+
# @note
|
256
|
+
# EXPERIMENTAL:
|
257
|
+
# Streaming requests are still undergoing review.
|
258
|
+
# This method interface might change in the future.
|
259
|
+
#
|
260
|
+
# @example
|
261
|
+
# require "google/cloud/dialogflow/v2"
|
262
|
+
#
|
263
|
+
# sessions_client = Google::Cloud::Dialogflow::V2::Sessions.new
|
264
|
+
#
|
265
|
+
# # TODO: Initialize +session+:
|
266
|
+
# session = ''
|
267
|
+
#
|
268
|
+
# # TODO: Initialize +query_input+:
|
269
|
+
# query_input = {}
|
270
|
+
# request = { session: session, query_input: query_input }
|
271
|
+
# requests = [request]
|
272
|
+
# sessions_client.streaming_detect_intent(requests).each do |element|
|
273
|
+
# # Process element.
|
274
|
+
# end
|
275
|
+
|
276
|
+
def streaming_detect_intent reqs, options: nil
|
277
|
+
request_protos = reqs.lazy.map do |req|
|
278
|
+
Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::StreamingDetectIntentRequest)
|
279
|
+
end
|
280
|
+
@streaming_detect_intent.call(request_protos, options)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|