google-cloud-dialogflow 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,87 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: google/cloud/dialogflow/v2/agent.proto
|
3
|
+
|
4
|
+
require 'google/protobuf'
|
5
|
+
|
6
|
+
require 'google/api/annotations_pb'
|
7
|
+
require 'google/longrunning/operations_pb'
|
8
|
+
require 'google/protobuf/empty_pb'
|
9
|
+
require 'google/protobuf/field_mask_pb'
|
10
|
+
require 'google/protobuf/struct_pb'
|
11
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
12
|
+
add_message "google.cloud.dialogflow.v2.Agent" do
|
13
|
+
optional :parent, :string, 1
|
14
|
+
optional :display_name, :string, 2
|
15
|
+
optional :default_language_code, :string, 3
|
16
|
+
repeated :supported_language_codes, :string, 4
|
17
|
+
optional :time_zone, :string, 5
|
18
|
+
optional :description, :string, 6
|
19
|
+
optional :avatar_uri, :string, 7
|
20
|
+
optional :enable_logging, :bool, 8
|
21
|
+
optional :match_mode, :enum, 9, "google.cloud.dialogflow.v2.Agent.MatchMode"
|
22
|
+
optional :classification_threshold, :float, 10
|
23
|
+
end
|
24
|
+
add_enum "google.cloud.dialogflow.v2.Agent.MatchMode" do
|
25
|
+
value :MATCH_MODE_UNSPECIFIED, 0
|
26
|
+
value :MATCH_MODE_HYBRID, 1
|
27
|
+
value :MATCH_MODE_ML_ONLY, 2
|
28
|
+
end
|
29
|
+
add_message "google.cloud.dialogflow.v2.GetAgentRequest" do
|
30
|
+
optional :parent, :string, 1
|
31
|
+
end
|
32
|
+
add_message "google.cloud.dialogflow.v2.SearchAgentsRequest" do
|
33
|
+
optional :parent, :string, 1
|
34
|
+
optional :page_size, :int32, 2
|
35
|
+
optional :page_token, :string, 3
|
36
|
+
end
|
37
|
+
add_message "google.cloud.dialogflow.v2.SearchAgentsResponse" do
|
38
|
+
repeated :agents, :message, 1, "google.cloud.dialogflow.v2.Agent"
|
39
|
+
optional :next_page_token, :string, 2
|
40
|
+
end
|
41
|
+
add_message "google.cloud.dialogflow.v2.TrainAgentRequest" do
|
42
|
+
optional :parent, :string, 1
|
43
|
+
end
|
44
|
+
add_message "google.cloud.dialogflow.v2.ExportAgentRequest" do
|
45
|
+
optional :parent, :string, 1
|
46
|
+
optional :agent_uri, :string, 2
|
47
|
+
end
|
48
|
+
add_message "google.cloud.dialogflow.v2.ExportAgentResponse" do
|
49
|
+
oneof :agent do
|
50
|
+
optional :agent_uri, :string, 1
|
51
|
+
optional :agent_content, :bytes, 2
|
52
|
+
end
|
53
|
+
end
|
54
|
+
add_message "google.cloud.dialogflow.v2.ImportAgentRequest" do
|
55
|
+
optional :parent, :string, 1
|
56
|
+
oneof :agent do
|
57
|
+
optional :agent_uri, :string, 2
|
58
|
+
optional :agent_content, :bytes, 3
|
59
|
+
end
|
60
|
+
end
|
61
|
+
add_message "google.cloud.dialogflow.v2.RestoreAgentRequest" do
|
62
|
+
optional :parent, :string, 1
|
63
|
+
oneof :agent do
|
64
|
+
optional :agent_uri, :string, 2
|
65
|
+
optional :agent_content, :bytes, 3
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module Google
|
71
|
+
module Cloud
|
72
|
+
module Dialogflow
|
73
|
+
module V2
|
74
|
+
Agent = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.Agent").msgclass
|
75
|
+
Agent::MatchMode = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.Agent.MatchMode").enummodule
|
76
|
+
GetAgentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.GetAgentRequest").msgclass
|
77
|
+
SearchAgentsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.SearchAgentsRequest").msgclass
|
78
|
+
SearchAgentsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.SearchAgentsResponse").msgclass
|
79
|
+
TrainAgentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.TrainAgentRequest").msgclass
|
80
|
+
ExportAgentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.ExportAgentRequest").msgclass
|
81
|
+
ExportAgentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.ExportAgentResponse").msgclass
|
82
|
+
ImportAgentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.ImportAgentRequest").msgclass
|
83
|
+
RestoreAgentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.dialogflow.v2.RestoreAgentRequest").msgclass
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# Source: google/cloud/dialogflow/v2/agent.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/agent_pb'
|
21
|
+
|
22
|
+
module Google
|
23
|
+
module Cloud
|
24
|
+
module Dialogflow
|
25
|
+
module V2
|
26
|
+
module Agents
|
27
|
+
# Agents are best described as Natural Language Understanding (NLU) modules
|
28
|
+
# that transform user requests into actionable data. You can include agents
|
29
|
+
# in your app, product, or service to determine user intent and respond to the
|
30
|
+
# user in a natural way.
|
31
|
+
#
|
32
|
+
# After you create an agent, you can add [Intents][google.cloud.dialogflow.v2.Intents], [Contexts][google.cloud.dialogflow.v2.Contexts],
|
33
|
+
# [Entity Types][google.cloud.dialogflow.v2.EntityTypes], [Webhooks][google.cloud.dialogflow.v2.WebhookRequest], and so on to
|
34
|
+
# manage the flow of a conversation and match user input to predefined intents
|
35
|
+
# and actions.
|
36
|
+
#
|
37
|
+
# You can create an agent using both Dialogflow Standard Edition and
|
38
|
+
# Dialogflow Enterprise Edition. For details, see
|
39
|
+
# [Dialogflow Editions](/dialogflow-enterprise/docs/editions).
|
40
|
+
#
|
41
|
+
# You can save your agent for backup or versioning by exporting the agent by
|
42
|
+
# using the [ExportAgent][google.cloud.dialogflow.v2.Agents.ExportAgent] method. You can import a saved
|
43
|
+
# agent by using the [ImportAgent][google.cloud.dialogflow.v2.Agents.ImportAgent] method.
|
44
|
+
#
|
45
|
+
# Dialogflow provides several
|
46
|
+
# [prebuilt agents](https://dialogflow.com/docs/prebuilt-agents) for common
|
47
|
+
# conversation scenarios such as determining a date and time, converting
|
48
|
+
# currency, and so on.
|
49
|
+
#
|
50
|
+
# For more information about agents, see the
|
51
|
+
# [Dialogflow documentation](https://dialogflow.com/docs/agents).
|
52
|
+
class Service
|
53
|
+
|
54
|
+
include GRPC::GenericService
|
55
|
+
|
56
|
+
self.marshal_class_method = :encode
|
57
|
+
self.unmarshal_class_method = :decode
|
58
|
+
self.service_name = 'google.cloud.dialogflow.v2.Agents'
|
59
|
+
|
60
|
+
# Retrieves the specified agent.
|
61
|
+
rpc :GetAgent, GetAgentRequest, Agent
|
62
|
+
# Returns the list of agents.
|
63
|
+
#
|
64
|
+
# Since there is at most one conversational agent per project, this method is
|
65
|
+
# useful primarily for listing all agents across projects the caller has
|
66
|
+
# access to. One can achieve that with a wildcard project collection id "-".
|
67
|
+
# Refer to [List
|
68
|
+
# Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
|
69
|
+
rpc :SearchAgents, SearchAgentsRequest, SearchAgentsResponse
|
70
|
+
# Trains the specified agent.
|
71
|
+
#
|
72
|
+
# Operation <response: [google.protobuf.Empty][google.protobuf.Empty],
|
73
|
+
# metadata: [google.protobuf.Struct][google.protobuf.Struct]>
|
74
|
+
rpc :TrainAgent, TrainAgentRequest, Google::Longrunning::Operation
|
75
|
+
# Exports the specified agent to a ZIP file.
|
76
|
+
#
|
77
|
+
# Operation <response: [ExportAgentResponse][google.cloud.dialogflow.v2.ExportAgentResponse],
|
78
|
+
# metadata: [google.protobuf.Struct][google.protobuf.Struct]>
|
79
|
+
rpc :ExportAgent, ExportAgentRequest, Google::Longrunning::Operation
|
80
|
+
# Imports the specified agent from a ZIP file.
|
81
|
+
#
|
82
|
+
# Uploads new intents and entity types without deleting the existing ones.
|
83
|
+
# Intents and entity types with the same name are replaced with the new
|
84
|
+
# versions from ImportAgentRequest.
|
85
|
+
#
|
86
|
+
# Operation <response: [google.protobuf.Empty][google.protobuf.Empty],
|
87
|
+
# metadata: [google.protobuf.Struct][google.protobuf.Struct]>
|
88
|
+
rpc :ImportAgent, ImportAgentRequest, Google::Longrunning::Operation
|
89
|
+
# Restores the specified agent from a ZIP file.
|
90
|
+
#
|
91
|
+
# Replaces the current agent version with a new one. All the intents and
|
92
|
+
# entity types in the older version are deleted.
|
93
|
+
#
|
94
|
+
# Operation <response: [google.protobuf.Empty][google.protobuf.Empty],
|
95
|
+
# metadata: [google.protobuf.Struct][google.protobuf.Struct]>
|
96
|
+
rpc :RestoreAgent, RestoreAgentRequest, Google::Longrunning::Operation
|
97
|
+
end
|
98
|
+
|
99
|
+
Stub = Service.rpc_stub_class
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,639 @@
|
|
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/agent.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
|
+
require "google/gax/operation"
|
27
|
+
require "google/longrunning/operations_client"
|
28
|
+
|
29
|
+
require "google/cloud/dialogflow/v2/agent_pb"
|
30
|
+
require "google/cloud/dialogflow/credentials"
|
31
|
+
|
32
|
+
module Google
|
33
|
+
module Cloud
|
34
|
+
module Dialogflow
|
35
|
+
module V2
|
36
|
+
# Agents are best described as Natural Language Understanding (NLU) modules
|
37
|
+
# that transform user requests into actionable data. You can include agents
|
38
|
+
# in your app, product, or service to determine user intent and respond to the
|
39
|
+
# user in a natural way.
|
40
|
+
#
|
41
|
+
# After you create an agent, you can add {Google::Cloud::Dialogflow::V2::Intents Intents}, {Google::Cloud::Dialogflow::V2::Contexts Contexts},
|
42
|
+
# {Google::Cloud::Dialogflow::V2::EntityTypes Entity Types}, {Google::Cloud::Dialogflow::V2::WebhookRequest Webhooks}, and so on to
|
43
|
+
# manage the flow of a conversation and match user input to predefined intents
|
44
|
+
# and actions.
|
45
|
+
#
|
46
|
+
# You can create an agent using both Dialogflow Standard Edition and
|
47
|
+
# Dialogflow Enterprise Edition. For details, see
|
48
|
+
# [Dialogflow Editions](https://cloud.google.com/dialogflow-enterprise/docs/editions).
|
49
|
+
#
|
50
|
+
# You can save your agent for backup or versioning by exporting the agent by
|
51
|
+
# using the {Google::Cloud::Dialogflow::V2::Agents::ExportAgent ExportAgent} method. You can import a saved
|
52
|
+
# agent by using the {Google::Cloud::Dialogflow::V2::Agents::ImportAgent ImportAgent} method.
|
53
|
+
#
|
54
|
+
# Dialogflow provides several
|
55
|
+
# [prebuilt agents](https://dialogflow.com/docs/prebuilt-agents) for common
|
56
|
+
# conversation scenarios such as determining a date and time, converting
|
57
|
+
# currency, and so on.
|
58
|
+
#
|
59
|
+
# For more information about agents, see the
|
60
|
+
# [Dialogflow documentation](https://dialogflow.com/docs/agents).
|
61
|
+
#
|
62
|
+
# @!attribute [r] agents_stub
|
63
|
+
# @return [Google::Cloud::Dialogflow::V2::Agents::Stub]
|
64
|
+
class AgentsClient
|
65
|
+
attr_reader :agents_stub
|
66
|
+
|
67
|
+
# The default address of the service.
|
68
|
+
SERVICE_ADDRESS = "dialogflow.googleapis.com".freeze
|
69
|
+
|
70
|
+
# The default port of the service.
|
71
|
+
DEFAULT_SERVICE_PORT = 443
|
72
|
+
|
73
|
+
DEFAULT_TIMEOUT = 30
|
74
|
+
|
75
|
+
PAGE_DESCRIPTORS = {
|
76
|
+
"search_agents" => Google::Gax::PageDescriptor.new(
|
77
|
+
"page_token",
|
78
|
+
"next_page_token",
|
79
|
+
"agents")
|
80
|
+
}.freeze
|
81
|
+
|
82
|
+
private_constant :PAGE_DESCRIPTORS
|
83
|
+
|
84
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
85
|
+
# this service.
|
86
|
+
ALL_SCOPES = [
|
87
|
+
"https://www.googleapis.com/auth/cloud-platform"
|
88
|
+
].freeze
|
89
|
+
|
90
|
+
class OperationsClient < Google::Longrunning::OperationsClient
|
91
|
+
self::SERVICE_ADDRESS = AgentsClient::SERVICE_ADDRESS
|
92
|
+
end
|
93
|
+
|
94
|
+
PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
95
|
+
"projects/{project}"
|
96
|
+
)
|
97
|
+
|
98
|
+
private_constant :PROJECT_PATH_TEMPLATE
|
99
|
+
|
100
|
+
# Returns a fully-qualified project resource name string.
|
101
|
+
# @param project [String]
|
102
|
+
# @return [String]
|
103
|
+
def self.project_path project
|
104
|
+
PROJECT_PATH_TEMPLATE.render(
|
105
|
+
:"project" => project
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
110
|
+
# Provides the means for authenticating requests made by the client. This parameter can
|
111
|
+
# be many types.
|
112
|
+
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
|
113
|
+
# authenticating requests made by this client.
|
114
|
+
# A `String` will be treated as the path to the keyfile to be used for the construction of
|
115
|
+
# credentials for this client.
|
116
|
+
# A `Hash` will be treated as the contents of a keyfile to be used for the construction of
|
117
|
+
# credentials for this client.
|
118
|
+
# A `GRPC::Core::Channel` will be used to make calls through.
|
119
|
+
# A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
|
120
|
+
# should already be composed with a `GRPC::Core::CallCredentials` object.
|
121
|
+
# A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
|
122
|
+
# metadata for requests, generally, to give OAuth credentials.
|
123
|
+
# @param scopes [Array<String>]
|
124
|
+
# The OAuth scopes for this service. This parameter is ignored if
|
125
|
+
# an updater_proc is supplied.
|
126
|
+
# @param client_config [Hash]
|
127
|
+
# A Hash for call options for each method. See
|
128
|
+
# Google::Gax#construct_settings for the structure of
|
129
|
+
# this data. Falls back to the default config if not specified
|
130
|
+
# or the specified config is missing data points.
|
131
|
+
# @param timeout [Numeric]
|
132
|
+
# The default timeout, in seconds, for calls made through this client.
|
133
|
+
def initialize \
|
134
|
+
credentials: nil,
|
135
|
+
scopes: ALL_SCOPES,
|
136
|
+
client_config: {},
|
137
|
+
timeout: DEFAULT_TIMEOUT,
|
138
|
+
lib_name: nil,
|
139
|
+
lib_version: ""
|
140
|
+
# These require statements are intentionally placed here to initialize
|
141
|
+
# the gRPC module only when it's required.
|
142
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
143
|
+
require "google/gax/grpc"
|
144
|
+
require "google/cloud/dialogflow/v2/agent_services_pb"
|
145
|
+
|
146
|
+
credentials ||= Google::Cloud::Dialogflow::Credentials.default
|
147
|
+
|
148
|
+
@operations_client = OperationsClient.new(
|
149
|
+
credentials: credentials,
|
150
|
+
scopes: scopes,
|
151
|
+
client_config: client_config,
|
152
|
+
timeout: timeout,
|
153
|
+
lib_name: lib_name,
|
154
|
+
lib_version: lib_version,
|
155
|
+
)
|
156
|
+
|
157
|
+
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
158
|
+
updater_proc = Google::Cloud::Dialogflow::Credentials.new(credentials).updater_proc
|
159
|
+
end
|
160
|
+
if credentials.is_a?(GRPC::Core::Channel)
|
161
|
+
channel = credentials
|
162
|
+
end
|
163
|
+
if credentials.is_a?(GRPC::Core::ChannelCredentials)
|
164
|
+
chan_creds = credentials
|
165
|
+
end
|
166
|
+
if credentials.is_a?(Proc)
|
167
|
+
updater_proc = credentials
|
168
|
+
end
|
169
|
+
if credentials.is_a?(Google::Auth::Credentials)
|
170
|
+
updater_proc = credentials.updater_proc
|
171
|
+
end
|
172
|
+
|
173
|
+
package_version = Gem.loaded_specs['google-cloud-dialogflow'].version.version
|
174
|
+
|
175
|
+
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
176
|
+
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
177
|
+
google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
|
178
|
+
google_api_client << " grpc/#{GRPC::VERSION}"
|
179
|
+
google_api_client.freeze
|
180
|
+
|
181
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
182
|
+
client_config_file = Pathname.new(__dir__).join(
|
183
|
+
"agents_client_config.json"
|
184
|
+
)
|
185
|
+
defaults = client_config_file.open do |f|
|
186
|
+
Google::Gax.construct_settings(
|
187
|
+
"google.cloud.dialogflow.v2.Agents",
|
188
|
+
JSON.parse(f.read),
|
189
|
+
client_config,
|
190
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
191
|
+
timeout,
|
192
|
+
page_descriptors: PAGE_DESCRIPTORS,
|
193
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
194
|
+
kwargs: headers
|
195
|
+
)
|
196
|
+
end
|
197
|
+
|
198
|
+
# Allow overriding the service path/port in subclasses.
|
199
|
+
service_path = self.class::SERVICE_ADDRESS
|
200
|
+
port = self.class::DEFAULT_SERVICE_PORT
|
201
|
+
@agents_stub = Google::Gax::Grpc.create_stub(
|
202
|
+
service_path,
|
203
|
+
port,
|
204
|
+
chan_creds: chan_creds,
|
205
|
+
channel: channel,
|
206
|
+
updater_proc: updater_proc,
|
207
|
+
scopes: scopes,
|
208
|
+
&Google::Cloud::Dialogflow::V2::Agents::Stub.method(:new)
|
209
|
+
)
|
210
|
+
|
211
|
+
@get_agent = Google::Gax.create_api_call(
|
212
|
+
@agents_stub.method(:get_agent),
|
213
|
+
defaults["get_agent"]
|
214
|
+
)
|
215
|
+
@search_agents = Google::Gax.create_api_call(
|
216
|
+
@agents_stub.method(:search_agents),
|
217
|
+
defaults["search_agents"]
|
218
|
+
)
|
219
|
+
@train_agent = Google::Gax.create_api_call(
|
220
|
+
@agents_stub.method(:train_agent),
|
221
|
+
defaults["train_agent"]
|
222
|
+
)
|
223
|
+
@export_agent = Google::Gax.create_api_call(
|
224
|
+
@agents_stub.method(:export_agent),
|
225
|
+
defaults["export_agent"]
|
226
|
+
)
|
227
|
+
@import_agent = Google::Gax.create_api_call(
|
228
|
+
@agents_stub.method(:import_agent),
|
229
|
+
defaults["import_agent"]
|
230
|
+
)
|
231
|
+
@restore_agent = Google::Gax.create_api_call(
|
232
|
+
@agents_stub.method(:restore_agent),
|
233
|
+
defaults["restore_agent"]
|
234
|
+
)
|
235
|
+
end
|
236
|
+
|
237
|
+
# Service calls
|
238
|
+
|
239
|
+
# Retrieves the specified agent.
|
240
|
+
#
|
241
|
+
# @param parent [String]
|
242
|
+
# Required. The project that the agent to fetch is associated with.
|
243
|
+
# Format: +projects/<Project ID>+.
|
244
|
+
# @param options [Google::Gax::CallOptions]
|
245
|
+
# Overrides the default settings for this call, e.g, timeout,
|
246
|
+
# retries, etc.
|
247
|
+
# @return [Google::Cloud::Dialogflow::V2::Agent]
|
248
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
249
|
+
# @example
|
250
|
+
# require "google/cloud/dialogflow/v2"
|
251
|
+
#
|
252
|
+
# agents_client = Google::Cloud::Dialogflow::V2::Agents.new
|
253
|
+
# formatted_parent = Google::Cloud::Dialogflow::V2::AgentsClient.project_path("[PROJECT]")
|
254
|
+
# response = agents_client.get_agent(formatted_parent)
|
255
|
+
|
256
|
+
def get_agent \
|
257
|
+
parent,
|
258
|
+
options: nil
|
259
|
+
req = {
|
260
|
+
parent: parent
|
261
|
+
}.delete_if { |_, v| v.nil? }
|
262
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::GetAgentRequest)
|
263
|
+
@get_agent.call(req, options)
|
264
|
+
end
|
265
|
+
|
266
|
+
# Returns the list of agents.
|
267
|
+
#
|
268
|
+
# Since there is at most one conversational agent per project, this method is
|
269
|
+
# useful primarily for listing all agents across projects the caller has
|
270
|
+
# access to. One can achieve that with a wildcard project collection id "-".
|
271
|
+
# Refer to [List
|
272
|
+
# Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
|
273
|
+
#
|
274
|
+
# @param parent [String]
|
275
|
+
# Required. The project to list agents from.
|
276
|
+
# Format: +projects/<Project ID or '-'>+.
|
277
|
+
# @param page_size [Integer]
|
278
|
+
# The maximum number of resources contained in the underlying API
|
279
|
+
# response. If page streaming is performed per-resource, this
|
280
|
+
# parameter does not affect the return value. If page streaming is
|
281
|
+
# performed per-page, this determines the maximum number of
|
282
|
+
# resources in a page.
|
283
|
+
# @param options [Google::Gax::CallOptions]
|
284
|
+
# Overrides the default settings for this call, e.g, timeout,
|
285
|
+
# retries, etc.
|
286
|
+
# @return [Google::Gax::PagedEnumerable<Google::Cloud::Dialogflow::V2::Agent>]
|
287
|
+
# An enumerable of Google::Cloud::Dialogflow::V2::Agent instances.
|
288
|
+
# See Google::Gax::PagedEnumerable documentation for other
|
289
|
+
# operations such as per-page iteration or access to the response
|
290
|
+
# object.
|
291
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
292
|
+
# @example
|
293
|
+
# require "google/cloud/dialogflow/v2"
|
294
|
+
#
|
295
|
+
# agents_client = Google::Cloud::Dialogflow::V2::Agents.new
|
296
|
+
# formatted_parent = Google::Cloud::Dialogflow::V2::AgentsClient.project_path("[PROJECT]")
|
297
|
+
#
|
298
|
+
# # Iterate over all results.
|
299
|
+
# agents_client.search_agents(formatted_parent).each do |element|
|
300
|
+
# # Process element.
|
301
|
+
# end
|
302
|
+
#
|
303
|
+
# # Or iterate over results one page at a time.
|
304
|
+
# agents_client.search_agents(formatted_parent).each_page do |page|
|
305
|
+
# # Process each page at a time.
|
306
|
+
# page.each do |element|
|
307
|
+
# # Process element.
|
308
|
+
# end
|
309
|
+
# end
|
310
|
+
|
311
|
+
def search_agents \
|
312
|
+
parent,
|
313
|
+
page_size: nil,
|
314
|
+
options: nil
|
315
|
+
req = {
|
316
|
+
parent: parent,
|
317
|
+
page_size: page_size
|
318
|
+
}.delete_if { |_, v| v.nil? }
|
319
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::SearchAgentsRequest)
|
320
|
+
@search_agents.call(req, options)
|
321
|
+
end
|
322
|
+
|
323
|
+
# Trains the specified agent.
|
324
|
+
#
|
325
|
+
# Operation <response: {Google::Protobuf::Empty},
|
326
|
+
# metadata: {Google::Protobuf::Struct}>
|
327
|
+
#
|
328
|
+
# @param parent [String]
|
329
|
+
# Required. The project that the agent to train is associated with.
|
330
|
+
# Format: +projects/<Project ID>+.
|
331
|
+
# @param options [Google::Gax::CallOptions]
|
332
|
+
# Overrides the default settings for this call, e.g, timeout,
|
333
|
+
# retries, etc.
|
334
|
+
# @return [Google::Gax::Operation]
|
335
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
336
|
+
# @example
|
337
|
+
# require "google/cloud/dialogflow/v2"
|
338
|
+
#
|
339
|
+
# agents_client = Google::Cloud::Dialogflow::V2::Agents.new
|
340
|
+
# formatted_parent = Google::Cloud::Dialogflow::V2::AgentsClient.project_path("[PROJECT]")
|
341
|
+
#
|
342
|
+
# # Register a callback during the method call.
|
343
|
+
# operation = agents_client.train_agent(formatted_parent) do |op|
|
344
|
+
# raise op.results.message if op.error?
|
345
|
+
# op_results = op.results
|
346
|
+
# # Process the results.
|
347
|
+
#
|
348
|
+
# metadata = op.metadata
|
349
|
+
# # Process the metadata.
|
350
|
+
# end
|
351
|
+
#
|
352
|
+
# # Or use the return value to register a callback.
|
353
|
+
# operation.on_done do |op|
|
354
|
+
# raise op.results.message if op.error?
|
355
|
+
# op_results = op.results
|
356
|
+
# # Process the results.
|
357
|
+
#
|
358
|
+
# metadata = op.metadata
|
359
|
+
# # Process the metadata.
|
360
|
+
# end
|
361
|
+
#
|
362
|
+
# # Manually reload the operation.
|
363
|
+
# operation.reload!
|
364
|
+
#
|
365
|
+
# # Or block until the operation completes, triggering callbacks on
|
366
|
+
# # completion.
|
367
|
+
# operation.wait_until_done!
|
368
|
+
|
369
|
+
def train_agent \
|
370
|
+
parent,
|
371
|
+
options: nil
|
372
|
+
req = {
|
373
|
+
parent: parent
|
374
|
+
}.delete_if { |_, v| v.nil? }
|
375
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::TrainAgentRequest)
|
376
|
+
operation = Google::Gax::Operation.new(
|
377
|
+
@train_agent.call(req, options),
|
378
|
+
@operations_client,
|
379
|
+
Google::Protobuf::Empty,
|
380
|
+
Google::Protobuf::Struct,
|
381
|
+
call_options: options
|
382
|
+
)
|
383
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
384
|
+
operation
|
385
|
+
end
|
386
|
+
|
387
|
+
# Exports the specified agent to a ZIP file.
|
388
|
+
#
|
389
|
+
# Operation <response: {Google::Cloud::Dialogflow::V2::ExportAgentResponse ExportAgentResponse},
|
390
|
+
# metadata: {Google::Protobuf::Struct}>
|
391
|
+
#
|
392
|
+
# @param parent [String]
|
393
|
+
# Required. The project that the agent to export is associated with.
|
394
|
+
# Format: +projects/<Project ID>+.
|
395
|
+
# @param agent_uri [String]
|
396
|
+
# Optional. The Google Cloud Storage URI to export the agent to.
|
397
|
+
# Note: The URI must start with
|
398
|
+
# "gs://". If left unspecified, the serialized agent is returned inline.
|
399
|
+
# @param options [Google::Gax::CallOptions]
|
400
|
+
# Overrides the default settings for this call, e.g, timeout,
|
401
|
+
# retries, etc.
|
402
|
+
# @return [Google::Gax::Operation]
|
403
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
404
|
+
# @example
|
405
|
+
# require "google/cloud/dialogflow/v2"
|
406
|
+
#
|
407
|
+
# agents_client = Google::Cloud::Dialogflow::V2::Agents.new
|
408
|
+
# formatted_parent = Google::Cloud::Dialogflow::V2::AgentsClient.project_path("[PROJECT]")
|
409
|
+
#
|
410
|
+
# # Register a callback during the method call.
|
411
|
+
# operation = agents_client.export_agent(formatted_parent) do |op|
|
412
|
+
# raise op.results.message if op.error?
|
413
|
+
# op_results = op.results
|
414
|
+
# # Process the results.
|
415
|
+
#
|
416
|
+
# metadata = op.metadata
|
417
|
+
# # Process the metadata.
|
418
|
+
# end
|
419
|
+
#
|
420
|
+
# # Or use the return value to register a callback.
|
421
|
+
# operation.on_done do |op|
|
422
|
+
# raise op.results.message if op.error?
|
423
|
+
# op_results = op.results
|
424
|
+
# # Process the results.
|
425
|
+
#
|
426
|
+
# metadata = op.metadata
|
427
|
+
# # Process the metadata.
|
428
|
+
# end
|
429
|
+
#
|
430
|
+
# # Manually reload the operation.
|
431
|
+
# operation.reload!
|
432
|
+
#
|
433
|
+
# # Or block until the operation completes, triggering callbacks on
|
434
|
+
# # completion.
|
435
|
+
# operation.wait_until_done!
|
436
|
+
|
437
|
+
def export_agent \
|
438
|
+
parent,
|
439
|
+
agent_uri: nil,
|
440
|
+
options: nil
|
441
|
+
req = {
|
442
|
+
parent: parent,
|
443
|
+
agent_uri: agent_uri
|
444
|
+
}.delete_if { |_, v| v.nil? }
|
445
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::ExportAgentRequest)
|
446
|
+
operation = Google::Gax::Operation.new(
|
447
|
+
@export_agent.call(req, options),
|
448
|
+
@operations_client,
|
449
|
+
Google::Cloud::Dialogflow::V2::ExportAgentResponse,
|
450
|
+
Google::Protobuf::Struct,
|
451
|
+
call_options: options
|
452
|
+
)
|
453
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
454
|
+
operation
|
455
|
+
end
|
456
|
+
|
457
|
+
# Imports the specified agent from a ZIP file.
|
458
|
+
#
|
459
|
+
# Uploads new intents and entity types without deleting the existing ones.
|
460
|
+
# Intents and entity types with the same name are replaced with the new
|
461
|
+
# versions from ImportAgentRequest.
|
462
|
+
#
|
463
|
+
# Operation <response: {Google::Protobuf::Empty},
|
464
|
+
# metadata: {Google::Protobuf::Struct}>
|
465
|
+
#
|
466
|
+
# @param parent [String]
|
467
|
+
# Required. The project that the agent to import is associated with.
|
468
|
+
# Format: +projects/<Project ID>+.
|
469
|
+
# @param agent_uri [String]
|
470
|
+
# The URI to a Google Cloud Storage file containing the agent to import.
|
471
|
+
# Note: The URI must start with "gs://".
|
472
|
+
# @param agent_content [String]
|
473
|
+
# The agent to import.
|
474
|
+
#
|
475
|
+
# Example for how to import an agent via the command line:
|
476
|
+
#
|
477
|
+
# curl \
|
478
|
+
# 'https://dialogflow.googleapis.com/v2/projects/<project_name>/agent:import\
|
479
|
+
# -X POST \
|
480
|
+
# -H 'Authorization: Bearer '$(gcloud auth print-access-token) \
|
481
|
+
# -H 'Accept: application/json' \
|
482
|
+
# -H 'Content-Type: application/json' \
|
483
|
+
# --compressed \
|
484
|
+
# --data-binary "{
|
485
|
+
# 'agentContent': '$(cat <agent zip file> | base64 -w 0)'
|
486
|
+
# }"
|
487
|
+
# @param options [Google::Gax::CallOptions]
|
488
|
+
# Overrides the default settings for this call, e.g, timeout,
|
489
|
+
# retries, etc.
|
490
|
+
# @return [Google::Gax::Operation]
|
491
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
492
|
+
# @example
|
493
|
+
# require "google/cloud/dialogflow/v2"
|
494
|
+
#
|
495
|
+
# agents_client = Google::Cloud::Dialogflow::V2::Agents.new
|
496
|
+
# formatted_parent = Google::Cloud::Dialogflow::V2::AgentsClient.project_path("[PROJECT]")
|
497
|
+
#
|
498
|
+
# # Register a callback during the method call.
|
499
|
+
# operation = agents_client.import_agent(formatted_parent) do |op|
|
500
|
+
# raise op.results.message if op.error?
|
501
|
+
# op_results = op.results
|
502
|
+
# # Process the results.
|
503
|
+
#
|
504
|
+
# metadata = op.metadata
|
505
|
+
# # Process the metadata.
|
506
|
+
# end
|
507
|
+
#
|
508
|
+
# # Or use the return value to register a callback.
|
509
|
+
# operation.on_done do |op|
|
510
|
+
# raise op.results.message if op.error?
|
511
|
+
# op_results = op.results
|
512
|
+
# # Process the results.
|
513
|
+
#
|
514
|
+
# metadata = op.metadata
|
515
|
+
# # Process the metadata.
|
516
|
+
# end
|
517
|
+
#
|
518
|
+
# # Manually reload the operation.
|
519
|
+
# operation.reload!
|
520
|
+
#
|
521
|
+
# # Or block until the operation completes, triggering callbacks on
|
522
|
+
# # completion.
|
523
|
+
# operation.wait_until_done!
|
524
|
+
|
525
|
+
def import_agent \
|
526
|
+
parent,
|
527
|
+
agent_uri: nil,
|
528
|
+
agent_content: nil,
|
529
|
+
options: nil
|
530
|
+
req = {
|
531
|
+
parent: parent,
|
532
|
+
agent_uri: agent_uri,
|
533
|
+
agent_content: agent_content
|
534
|
+
}.delete_if { |_, v| v.nil? }
|
535
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::ImportAgentRequest)
|
536
|
+
operation = Google::Gax::Operation.new(
|
537
|
+
@import_agent.call(req, options),
|
538
|
+
@operations_client,
|
539
|
+
Google::Protobuf::Empty,
|
540
|
+
Google::Protobuf::Struct,
|
541
|
+
call_options: options
|
542
|
+
)
|
543
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
544
|
+
operation
|
545
|
+
end
|
546
|
+
|
547
|
+
# Restores the specified agent from a ZIP file.
|
548
|
+
#
|
549
|
+
# Replaces the current agent version with a new one. All the intents and
|
550
|
+
# entity types in the older version are deleted.
|
551
|
+
#
|
552
|
+
# Operation <response: {Google::Protobuf::Empty},
|
553
|
+
# metadata: {Google::Protobuf::Struct}>
|
554
|
+
#
|
555
|
+
# @param parent [String]
|
556
|
+
# Required. The project that the agent to restore is associated with.
|
557
|
+
# Format: +projects/<Project ID>+.
|
558
|
+
# @param agent_uri [String]
|
559
|
+
# The URI to a Google Cloud Storage file containing the agent to restore.
|
560
|
+
# Note: The URI must start with "gs://".
|
561
|
+
# @param agent_content [String]
|
562
|
+
# The agent to restore.
|
563
|
+
#
|
564
|
+
# Example for how to restore an agent via the command line:
|
565
|
+
#
|
566
|
+
# curl \
|
567
|
+
# 'https://dialogflow.googleapis.com/v2/projects/<project_name>/agent:restore\
|
568
|
+
# -X POST \
|
569
|
+
# -H 'Authorization: Bearer '$(gcloud auth print-access-token) \
|
570
|
+
# -H 'Accept: application/json' \
|
571
|
+
# -H 'Content-Type: application/json' \
|
572
|
+
# --compressed \
|
573
|
+
# --data-binary "{
|
574
|
+
# 'agentContent': '$(cat <agent zip file> | base64 -w 0)'
|
575
|
+
# }" \
|
576
|
+
# @param options [Google::Gax::CallOptions]
|
577
|
+
# Overrides the default settings for this call, e.g, timeout,
|
578
|
+
# retries, etc.
|
579
|
+
# @return [Google::Gax::Operation]
|
580
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
581
|
+
# @example
|
582
|
+
# require "google/cloud/dialogflow/v2"
|
583
|
+
#
|
584
|
+
# agents_client = Google::Cloud::Dialogflow::V2::Agents.new
|
585
|
+
# formatted_parent = Google::Cloud::Dialogflow::V2::AgentsClient.project_path("[PROJECT]")
|
586
|
+
#
|
587
|
+
# # Register a callback during the method call.
|
588
|
+
# operation = agents_client.restore_agent(formatted_parent) do |op|
|
589
|
+
# raise op.results.message if op.error?
|
590
|
+
# op_results = op.results
|
591
|
+
# # Process the results.
|
592
|
+
#
|
593
|
+
# metadata = op.metadata
|
594
|
+
# # Process the metadata.
|
595
|
+
# end
|
596
|
+
#
|
597
|
+
# # Or use the return value to register a callback.
|
598
|
+
# operation.on_done do |op|
|
599
|
+
# raise op.results.message if op.error?
|
600
|
+
# op_results = op.results
|
601
|
+
# # Process the results.
|
602
|
+
#
|
603
|
+
# metadata = op.metadata
|
604
|
+
# # Process the metadata.
|
605
|
+
# end
|
606
|
+
#
|
607
|
+
# # Manually reload the operation.
|
608
|
+
# operation.reload!
|
609
|
+
#
|
610
|
+
# # Or block until the operation completes, triggering callbacks on
|
611
|
+
# # completion.
|
612
|
+
# operation.wait_until_done!
|
613
|
+
|
614
|
+
def restore_agent \
|
615
|
+
parent,
|
616
|
+
agent_uri: nil,
|
617
|
+
agent_content: nil,
|
618
|
+
options: nil
|
619
|
+
req = {
|
620
|
+
parent: parent,
|
621
|
+
agent_uri: agent_uri,
|
622
|
+
agent_content: agent_content
|
623
|
+
}.delete_if { |_, v| v.nil? }
|
624
|
+
req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::RestoreAgentRequest)
|
625
|
+
operation = Google::Gax::Operation.new(
|
626
|
+
@restore_agent.call(req, options),
|
627
|
+
@operations_client,
|
628
|
+
Google::Protobuf::Empty,
|
629
|
+
Google::Protobuf::Struct,
|
630
|
+
call_options: options
|
631
|
+
)
|
632
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
633
|
+
operation
|
634
|
+
end
|
635
|
+
end
|
636
|
+
end
|
637
|
+
end
|
638
|
+
end
|
639
|
+
end
|