From febbdcf13fcea3f5d8186c3d3dface1c0d27ef9e Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Tue, 23 Mar 2021 11:05:09 -0600 Subject: [PATCH] feat(dialogflow/cx): start generating apiv3 (#3850) Fixes: #3634 --- dialogflow/cx/apiv3/agents_client.go | 660 ++++++++++++ .../cx/apiv3/agents_client_example_test.go | 226 +++++ dialogflow/cx/apiv3/doc.go | 118 +++ dialogflow/cx/apiv3/entity_types_client.go | 368 +++++++ .../apiv3/entity_types_client_example_test.go | 138 +++ dialogflow/cx/apiv3/environments_client.go | 582 +++++++++++ .../apiv3/environments_client_example_test.go | 175 ++++ dialogflow/cx/apiv3/experiments_client.go | 438 ++++++++ .../apiv3/experiments_client_example_test.go | 178 ++++ dialogflow/cx/apiv3/flows_client.go | 553 ++++++++++ .../cx/apiv3/flows_client_example_test.go | 201 ++++ dialogflow/cx/apiv3/gapic_metadata.json | 565 +++++++++++ dialogflow/cx/apiv3/intents_client.go | 368 +++++++ .../cx/apiv3/intents_client_example_test.go | 138 +++ dialogflow/cx/apiv3/pages_client.go | 368 +++++++ .../cx/apiv3/pages_client_example_test.go | 138 +++ .../cx/apiv3/security_settings_client.go | 369 +++++++ .../security_settings_client_example_test.go | 138 +++ .../cx/apiv3/session_entity_types_client.go | 371 +++++++ ...ession_entity_types_client_example_test.go | 138 +++ dialogflow/cx/apiv3/sessions_client.go | 272 +++++ .../cx/apiv3/sessions_client_example_test.go | 131 +++ dialogflow/cx/apiv3/test_cases_client.go | 944 ++++++++++++++++++ .../apiv3/test_cases_client_example_test.go | 285 ++++++ .../apiv3/transition_route_groups_client.go | 368 +++++++ ...sition_route_groups_client_example_test.go | 138 +++ dialogflow/cx/apiv3/versions_client.go | 552 ++++++++++ .../cx/apiv3/versions_client_example_test.go | 166 +++ dialogflow/cx/apiv3/webhooks_client.go | 368 +++++++ .../cx/apiv3/webhooks_client_example_test.go | 138 +++ internal/.repo-metadata-full.json | 8 + internal/gapicgen/generator/config.go | 9 + 32 files changed, 9609 insertions(+) create mode 100644 dialogflow/cx/apiv3/agents_client.go create mode 100644 dialogflow/cx/apiv3/agents_client_example_test.go create mode 100644 dialogflow/cx/apiv3/doc.go create mode 100644 dialogflow/cx/apiv3/entity_types_client.go create mode 100644 dialogflow/cx/apiv3/entity_types_client_example_test.go create mode 100644 dialogflow/cx/apiv3/environments_client.go create mode 100644 dialogflow/cx/apiv3/environments_client_example_test.go create mode 100644 dialogflow/cx/apiv3/experiments_client.go create mode 100644 dialogflow/cx/apiv3/experiments_client_example_test.go create mode 100644 dialogflow/cx/apiv3/flows_client.go create mode 100644 dialogflow/cx/apiv3/flows_client_example_test.go create mode 100644 dialogflow/cx/apiv3/gapic_metadata.json create mode 100644 dialogflow/cx/apiv3/intents_client.go create mode 100644 dialogflow/cx/apiv3/intents_client_example_test.go create mode 100644 dialogflow/cx/apiv3/pages_client.go create mode 100644 dialogflow/cx/apiv3/pages_client_example_test.go create mode 100644 dialogflow/cx/apiv3/security_settings_client.go create mode 100644 dialogflow/cx/apiv3/security_settings_client_example_test.go create mode 100644 dialogflow/cx/apiv3/session_entity_types_client.go create mode 100644 dialogflow/cx/apiv3/session_entity_types_client_example_test.go create mode 100644 dialogflow/cx/apiv3/sessions_client.go create mode 100644 dialogflow/cx/apiv3/sessions_client_example_test.go create mode 100644 dialogflow/cx/apiv3/test_cases_client.go create mode 100644 dialogflow/cx/apiv3/test_cases_client_example_test.go create mode 100644 dialogflow/cx/apiv3/transition_route_groups_client.go create mode 100644 dialogflow/cx/apiv3/transition_route_groups_client_example_test.go create mode 100644 dialogflow/cx/apiv3/versions_client.go create mode 100644 dialogflow/cx/apiv3/versions_client_example_test.go create mode 100644 dialogflow/cx/apiv3/webhooks_client.go create mode 100644 dialogflow/cx/apiv3/webhooks_client_example_test.go diff --git a/dialogflow/cx/apiv3/agents_client.go b/dialogflow/cx/apiv3/agents_client.go new file mode 100644 index 00000000000..645d586b8e3 --- /dev/null +++ b/dialogflow/cx/apiv3/agents_client.go @@ -0,0 +1,660 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + structpb "github.com/golang/protobuf/ptypes/struct" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newAgentsClientHook clientHook + +// AgentsCallOptions contains the retry settings for each method of AgentsClient. +type AgentsCallOptions struct { + ListAgents []gax.CallOption + GetAgent []gax.CallOption + CreateAgent []gax.CallOption + UpdateAgent []gax.CallOption + DeleteAgent []gax.CallOption + ExportAgent []gax.CallOption + RestoreAgent []gax.CallOption + ValidateAgent []gax.CallOption + GetAgentValidationResult []gax.CallOption +} + +func defaultAgentsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultAgentsCallOptions() *AgentsCallOptions { + return &AgentsCallOptions{ + ListAgents: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetAgent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateAgent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateAgent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteAgent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ExportAgent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + RestoreAgent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ValidateAgent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetAgentValidationResult: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// AgentsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type AgentsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + agentsClient cxpb.AgentsClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *AgentsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewAgentsClient creates a new agents client. +// +// Service for managing Agents. +func NewAgentsClient(ctx context.Context, opts ...option.ClientOption) (*AgentsClient, error) { + clientOpts := defaultAgentsClientOptions() + + if newAgentsClientHook != nil { + hookOpts, err := newAgentsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &AgentsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultAgentsCallOptions(), + + agentsClient: cxpb.NewAgentsClient(connPool), + } + c.setGoogleClientInfo() + + c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *AgentsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *AgentsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *AgentsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListAgents returns the list of all agents in the specified location. +func (c *AgentsClient) ListAgents(ctx context.Context, req *cxpb.ListAgentsRequest, opts ...gax.CallOption) *AgentIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListAgents[0:len(c.CallOptions.ListAgents):len(c.CallOptions.ListAgents)], opts...) + it := &AgentIterator{} + req = proto.Clone(req).(*cxpb.ListAgentsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Agent, string, error) { + var resp *cxpb.ListAgentsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.ListAgents(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetAgents(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetAgent retrieves the specified agent. +func (c *AgentsClient) GetAgent(ctx context.Context, req *cxpb.GetAgentRequest, opts ...gax.CallOption) (*cxpb.Agent, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetAgent[0:len(c.CallOptions.GetAgent):len(c.CallOptions.GetAgent)], opts...) + var resp *cxpb.Agent + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.GetAgent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateAgent creates an agent in the specified location. +func (c *AgentsClient) CreateAgent(ctx context.Context, req *cxpb.CreateAgentRequest, opts ...gax.CallOption) (*cxpb.Agent, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateAgent[0:len(c.CallOptions.CreateAgent):len(c.CallOptions.CreateAgent)], opts...) + var resp *cxpb.Agent + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.CreateAgent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateAgent updates the specified agent. +func (c *AgentsClient) UpdateAgent(ctx context.Context, req *cxpb.UpdateAgentRequest, opts ...gax.CallOption) (*cxpb.Agent, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "agent.name", url.QueryEscape(req.GetAgent().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateAgent[0:len(c.CallOptions.UpdateAgent):len(c.CallOptions.UpdateAgent)], opts...) + var resp *cxpb.Agent + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.UpdateAgent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteAgent deletes the specified agent. +func (c *AgentsClient) DeleteAgent(ctx context.Context, req *cxpb.DeleteAgentRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteAgent[0:len(c.CallOptions.DeleteAgent):len(c.CallOptions.DeleteAgent)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.agentsClient.DeleteAgent(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// ExportAgent exports the specified agent to a binary file. +func (c *AgentsClient) ExportAgent(ctx context.Context, req *cxpb.ExportAgentRequest, opts ...gax.CallOption) (*ExportAgentOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ExportAgent[0:len(c.CallOptions.ExportAgent):len(c.CallOptions.ExportAgent)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.ExportAgent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &ExportAgentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// RestoreAgent restores the specified agent from a binary file. +// +// Replaces the current agent with a new one. Note that all existing resources +// in agent (e.g. intents, entity types, flows) will be removed. +func (c *AgentsClient) RestoreAgent(ctx context.Context, req *cxpb.RestoreAgentRequest, opts ...gax.CallOption) (*RestoreAgentOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.RestoreAgent[0:len(c.CallOptions.RestoreAgent):len(c.CallOptions.RestoreAgent)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.RestoreAgent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &RestoreAgentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// ValidateAgent validates the specified agent and creates or updates validation results. +// The agent in draft version is validated. Please call this API after the +// training is completed to get the complete validation results. +func (c *AgentsClient) ValidateAgent(ctx context.Context, req *cxpb.ValidateAgentRequest, opts ...gax.CallOption) (*cxpb.AgentValidationResult, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ValidateAgent[0:len(c.CallOptions.ValidateAgent):len(c.CallOptions.ValidateAgent)], opts...) + var resp *cxpb.AgentValidationResult + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.ValidateAgent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// GetAgentValidationResult gets the latest agent validation result. Agent validation is performed +// when ValidateAgent is called. +func (c *AgentsClient) GetAgentValidationResult(ctx context.Context, req *cxpb.GetAgentValidationResultRequest, opts ...gax.CallOption) (*cxpb.AgentValidationResult, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetAgentValidationResult[0:len(c.CallOptions.GetAgentValidationResult):len(c.CallOptions.GetAgentValidationResult)], opts...) + var resp *cxpb.AgentValidationResult + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.agentsClient.GetAgentValidationResult(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ExportAgentOperation manages a long-running operation from ExportAgent. +type ExportAgentOperation struct { + lro *longrunning.Operation +} + +// ExportAgentOperation returns a new ExportAgentOperation from a given name. +// The name must be that of a previously created ExportAgentOperation, possibly from a different process. +func (c *AgentsClient) ExportAgentOperation(name string) *ExportAgentOperation { + return &ExportAgentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *ExportAgentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportAgentResponse, error) { + var resp cxpb.ExportAgentResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *ExportAgentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportAgentResponse, error) { + var resp cxpb.ExportAgentResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *ExportAgentOperation) Metadata() (*structpb.Struct, error) { + var meta structpb.Struct + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *ExportAgentOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *ExportAgentOperation) Name() string { + return op.lro.Name() +} + +// RestoreAgentOperation manages a long-running operation from RestoreAgent. +type RestoreAgentOperation struct { + lro *longrunning.Operation +} + +// RestoreAgentOperation returns a new RestoreAgentOperation from a given name. +// The name must be that of a previously created RestoreAgentOperation, possibly from a different process. +func (c *AgentsClient) RestoreAgentOperation(name string) *RestoreAgentOperation { + return &RestoreAgentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *RestoreAgentOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *RestoreAgentOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.Poll(ctx, nil, opts...) +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *RestoreAgentOperation) Metadata() (*structpb.Struct, error) { + var meta structpb.Struct + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *RestoreAgentOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *RestoreAgentOperation) Name() string { + return op.lro.Name() +} + +// AgentIterator manages a stream of *cxpb.Agent. +type AgentIterator struct { + items []*cxpb.Agent + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Agent, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *AgentIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *AgentIterator) Next() (*cxpb.Agent, error) { + var item *cxpb.Agent + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *AgentIterator) bufLen() int { + return len(it.items) +} + +func (it *AgentIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/agents_client_example_test.go b/dialogflow/cx/apiv3/agents_client_example_test.go new file mode 100644 index 00000000000..848ab2d8ac3 --- /dev/null +++ b/dialogflow/cx/apiv3/agents_client_example_test.go @@ -0,0 +1,226 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewAgentsClient() { + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleAgentsClient_ListAgents() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListAgentsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListAgents(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleAgentsClient_GetAgent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetAgentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetAgent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAgentsClient_CreateAgent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateAgentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateAgent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAgentsClient_UpdateAgent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateAgentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateAgent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAgentsClient_DeleteAgent() { + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteAgentRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteAgent(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleAgentsClient_ExportAgent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ExportAgentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.ExportAgent(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAgentsClient_RestoreAgent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.RestoreAgentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.RestoreAgent(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleAgentsClient_ValidateAgent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ValidateAgentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ValidateAgent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAgentsClient_GetAgentValidationResult() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewAgentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetAgentValidationResultRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetAgentValidationResult(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/dialogflow/cx/apiv3/doc.go b/dialogflow/cx/apiv3/doc.go new file mode 100644 index 00000000000..9e71161604e --- /dev/null +++ b/dialogflow/cx/apiv3/doc.go @@ -0,0 +1,118 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +// Package cx is an auto-generated package for the +// Dialogflow API. +// +// Builds conversational interfaces (for example, chatbots, and voice-powered +// apps and devices). +// +// Use of Context +// +// The ctx passed to NewClient is used for authentication requests and +// for creating the underlying connection, but is not used for subsequent calls. +// Individual methods on the client use the ctx given to them. +// +// To close the open connection, use the Close() method. +// +// For information about setting deadlines, reusing contexts, and more +// please visit pkg.go.dev/cloud.google.com/go. +package cx // import "cloud.google.com/go/dialogflow/cx/apiv3" + +import ( + "context" + "os" + "runtime" + "strconv" + "strings" + "unicode" + + "google.golang.org/api/option" + "google.golang.org/grpc/metadata" +) + +// For more information on implementing a client constructor hook, see +// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. +type clientHookParams struct{} +type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) + +const versionClient = "20210323" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/dialogflow", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/dialogflow/cx/apiv3/entity_types_client.go b/dialogflow/cx/apiv3/entity_types_client.go new file mode 100644 index 00000000000..1283b1ac9ba --- /dev/null +++ b/dialogflow/cx/apiv3/entity_types_client.go @@ -0,0 +1,368 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newEntityTypesClientHook clientHook + +// EntityTypesCallOptions contains the retry settings for each method of EntityTypesClient. +type EntityTypesCallOptions struct { + ListEntityTypes []gax.CallOption + GetEntityType []gax.CallOption + CreateEntityType []gax.CallOption + UpdateEntityType []gax.CallOption + DeleteEntityType []gax.CallOption +} + +func defaultEntityTypesClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultEntityTypesCallOptions() *EntityTypesCallOptions { + return &EntityTypesCallOptions{ + ListEntityTypes: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// EntityTypesClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type EntityTypesClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + entityTypesClient cxpb.EntityTypesClient + + // The call options for this service. + CallOptions *EntityTypesCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewEntityTypesClient creates a new entity types client. +// +// Service for managing EntityTypes. +func NewEntityTypesClient(ctx context.Context, opts ...option.ClientOption) (*EntityTypesClient, error) { + clientOpts := defaultEntityTypesClientOptions() + + if newEntityTypesClientHook != nil { + hookOpts, err := newEntityTypesClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &EntityTypesClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultEntityTypesCallOptions(), + + entityTypesClient: cxpb.NewEntityTypesClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *EntityTypesClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *EntityTypesClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *EntityTypesClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListEntityTypes returns the list of all entity types in the specified agent. +func (c *EntityTypesClient) ListEntityTypes(ctx context.Context, req *cxpb.ListEntityTypesRequest, opts ...gax.CallOption) *EntityTypeIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListEntityTypes[0:len(c.CallOptions.ListEntityTypes):len(c.CallOptions.ListEntityTypes)], opts...) + it := &EntityTypeIterator{} + req = proto.Clone(req).(*cxpb.ListEntityTypesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.EntityType, string, error) { + var resp *cxpb.ListEntityTypesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.entityTypesClient.ListEntityTypes(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetEntityTypes(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetEntityType retrieves the specified entity type. +func (c *EntityTypesClient) GetEntityType(ctx context.Context, req *cxpb.GetEntityTypeRequest, opts ...gax.CallOption) (*cxpb.EntityType, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetEntityType[0:len(c.CallOptions.GetEntityType):len(c.CallOptions.GetEntityType)], opts...) + var resp *cxpb.EntityType + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.entityTypesClient.GetEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateEntityType creates an entity type in the specified agent. +func (c *EntityTypesClient) CreateEntityType(ctx context.Context, req *cxpb.CreateEntityTypeRequest, opts ...gax.CallOption) (*cxpb.EntityType, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateEntityType[0:len(c.CallOptions.CreateEntityType):len(c.CallOptions.CreateEntityType)], opts...) + var resp *cxpb.EntityType + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.entityTypesClient.CreateEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateEntityType updates the specified entity type. +func (c *EntityTypesClient) UpdateEntityType(ctx context.Context, req *cxpb.UpdateEntityTypeRequest, opts ...gax.CallOption) (*cxpb.EntityType, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "entity_type.name", url.QueryEscape(req.GetEntityType().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateEntityType[0:len(c.CallOptions.UpdateEntityType):len(c.CallOptions.UpdateEntityType)], opts...) + var resp *cxpb.EntityType + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.entityTypesClient.UpdateEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteEntityType deletes the specified entity type. +func (c *EntityTypesClient) DeleteEntityType(ctx context.Context, req *cxpb.DeleteEntityTypeRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteEntityType[0:len(c.CallOptions.DeleteEntityType):len(c.CallOptions.DeleteEntityType)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.entityTypesClient.DeleteEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// EntityTypeIterator manages a stream of *cxpb.EntityType. +type EntityTypeIterator struct { + items []*cxpb.EntityType + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.EntityType, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *EntityTypeIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *EntityTypeIterator) Next() (*cxpb.EntityType, error) { + var item *cxpb.EntityType + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *EntityTypeIterator) bufLen() int { + return len(it.items) +} + +func (it *EntityTypeIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/entity_types_client_example_test.go b/dialogflow/cx/apiv3/entity_types_client_example_test.go new file mode 100644 index 00000000000..8f54b093340 --- /dev/null +++ b/dialogflow/cx/apiv3/entity_types_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewEntityTypesClient() { + ctx := context.Background() + c, err := cx.NewEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleEntityTypesClient_ListEntityTypes() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListEntityTypesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListEntityTypes(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleEntityTypesClient_GetEntityType() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetEntityTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleEntityTypesClient_CreateEntityType() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateEntityTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleEntityTypesClient_UpdateEntityType() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateEntityTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleEntityTypesClient_DeleteEntityType() { + ctx := context.Background() + c, err := cx.NewEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteEntityTypeRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/dialogflow/cx/apiv3/environments_client.go b/dialogflow/cx/apiv3/environments_client.go new file mode 100644 index 00000000000..3aeeb5e1a37 --- /dev/null +++ b/dialogflow/cx/apiv3/environments_client.go @@ -0,0 +1,582 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + structpb "github.com/golang/protobuf/ptypes/struct" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newEnvironmentsClientHook clientHook + +// EnvironmentsCallOptions contains the retry settings for each method of EnvironmentsClient. +type EnvironmentsCallOptions struct { + ListEnvironments []gax.CallOption + GetEnvironment []gax.CallOption + CreateEnvironment []gax.CallOption + UpdateEnvironment []gax.CallOption + DeleteEnvironment []gax.CallOption + LookupEnvironmentHistory []gax.CallOption +} + +func defaultEnvironmentsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultEnvironmentsCallOptions() *EnvironmentsCallOptions { + return &EnvironmentsCallOptions{ + ListEnvironments: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetEnvironment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateEnvironment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateEnvironment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteEnvironment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + LookupEnvironmentHistory: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// EnvironmentsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type EnvironmentsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + environmentsClient cxpb.EnvironmentsClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *EnvironmentsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewEnvironmentsClient creates a new environments client. +// +// Service for managing Environments. +func NewEnvironmentsClient(ctx context.Context, opts ...option.ClientOption) (*EnvironmentsClient, error) { + clientOpts := defaultEnvironmentsClientOptions() + + if newEnvironmentsClientHook != nil { + hookOpts, err := newEnvironmentsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &EnvironmentsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultEnvironmentsCallOptions(), + + environmentsClient: cxpb.NewEnvironmentsClient(connPool), + } + c.setGoogleClientInfo() + + c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *EnvironmentsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *EnvironmentsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *EnvironmentsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListEnvironments returns the list of all environments in the specified Agent. +func (c *EnvironmentsClient) ListEnvironments(ctx context.Context, req *cxpb.ListEnvironmentsRequest, opts ...gax.CallOption) *EnvironmentIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListEnvironments[0:len(c.CallOptions.ListEnvironments):len(c.CallOptions.ListEnvironments)], opts...) + it := &EnvironmentIterator{} + req = proto.Clone(req).(*cxpb.ListEnvironmentsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Environment, string, error) { + var resp *cxpb.ListEnvironmentsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.environmentsClient.ListEnvironments(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetEnvironments(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetEnvironment retrieves the specified Environment. +func (c *EnvironmentsClient) GetEnvironment(ctx context.Context, req *cxpb.GetEnvironmentRequest, opts ...gax.CallOption) (*cxpb.Environment, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetEnvironment[0:len(c.CallOptions.GetEnvironment):len(c.CallOptions.GetEnvironment)], opts...) + var resp *cxpb.Environment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.environmentsClient.GetEnvironment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateEnvironment creates an Environment in the specified Agent. +func (c *EnvironmentsClient) CreateEnvironment(ctx context.Context, req *cxpb.CreateEnvironmentRequest, opts ...gax.CallOption) (*CreateEnvironmentOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateEnvironment[0:len(c.CallOptions.CreateEnvironment):len(c.CallOptions.CreateEnvironment)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.environmentsClient.CreateEnvironment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateEnvironmentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// UpdateEnvironment updates the specified Environment. +func (c *EnvironmentsClient) UpdateEnvironment(ctx context.Context, req *cxpb.UpdateEnvironmentRequest, opts ...gax.CallOption) (*UpdateEnvironmentOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "environment.name", url.QueryEscape(req.GetEnvironment().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateEnvironment[0:len(c.CallOptions.UpdateEnvironment):len(c.CallOptions.UpdateEnvironment)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.environmentsClient.UpdateEnvironment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateEnvironmentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DeleteEnvironment deletes the specified Environment. +func (c *EnvironmentsClient) DeleteEnvironment(ctx context.Context, req *cxpb.DeleteEnvironmentRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteEnvironment[0:len(c.CallOptions.DeleteEnvironment):len(c.CallOptions.DeleteEnvironment)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.environmentsClient.DeleteEnvironment(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// LookupEnvironmentHistory looks up the history of the specified Environment. +func (c *EnvironmentsClient) LookupEnvironmentHistory(ctx context.Context, req *cxpb.LookupEnvironmentHistoryRequest, opts ...gax.CallOption) *EnvironmentIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.LookupEnvironmentHistory[0:len(c.CallOptions.LookupEnvironmentHistory):len(c.CallOptions.LookupEnvironmentHistory)], opts...) + it := &EnvironmentIterator{} + req = proto.Clone(req).(*cxpb.LookupEnvironmentHistoryRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Environment, string, error) { + var resp *cxpb.LookupEnvironmentHistoryResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.environmentsClient.LookupEnvironmentHistory(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetEnvironments(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// CreateEnvironmentOperation manages a long-running operation from CreateEnvironment. +type CreateEnvironmentOperation struct { + lro *longrunning.Operation +} + +// CreateEnvironmentOperation returns a new CreateEnvironmentOperation from a given name. +// The name must be that of a previously created CreateEnvironmentOperation, possibly from a different process. +func (c *EnvironmentsClient) CreateEnvironmentOperation(name string) *CreateEnvironmentOperation { + return &CreateEnvironmentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *CreateEnvironmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) { + var resp cxpb.Environment + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *CreateEnvironmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) { + var resp cxpb.Environment + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *CreateEnvironmentOperation) Metadata() (*structpb.Struct, error) { + var meta structpb.Struct + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *CreateEnvironmentOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *CreateEnvironmentOperation) Name() string { + return op.lro.Name() +} + +// UpdateEnvironmentOperation manages a long-running operation from UpdateEnvironment. +type UpdateEnvironmentOperation struct { + lro *longrunning.Operation +} + +// UpdateEnvironmentOperation returns a new UpdateEnvironmentOperation from a given name. +// The name must be that of a previously created UpdateEnvironmentOperation, possibly from a different process. +func (c *EnvironmentsClient) UpdateEnvironmentOperation(name string) *UpdateEnvironmentOperation { + return &UpdateEnvironmentOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *UpdateEnvironmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) { + var resp cxpb.Environment + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *UpdateEnvironmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.Environment, error) { + var resp cxpb.Environment + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *UpdateEnvironmentOperation) Metadata() (*structpb.Struct, error) { + var meta structpb.Struct + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *UpdateEnvironmentOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *UpdateEnvironmentOperation) Name() string { + return op.lro.Name() +} + +// EnvironmentIterator manages a stream of *cxpb.Environment. +type EnvironmentIterator struct { + items []*cxpb.Environment + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Environment, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *EnvironmentIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *EnvironmentIterator) Next() (*cxpb.Environment, error) { + var item *cxpb.Environment + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *EnvironmentIterator) bufLen() int { + return len(it.items) +} + +func (it *EnvironmentIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/environments_client_example_test.go b/dialogflow/cx/apiv3/environments_client_example_test.go new file mode 100644 index 00000000000..d94824607ce --- /dev/null +++ b/dialogflow/cx/apiv3/environments_client_example_test.go @@ -0,0 +1,175 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewEnvironmentsClient() { + ctx := context.Background() + c, err := cx.NewEnvironmentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleEnvironmentsClient_ListEnvironments() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewEnvironmentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListEnvironmentsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListEnvironments(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleEnvironmentsClient_GetEnvironment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewEnvironmentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetEnvironmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetEnvironment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleEnvironmentsClient_CreateEnvironment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewEnvironmentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateEnvironmentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateEnvironment(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleEnvironmentsClient_UpdateEnvironment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewEnvironmentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateEnvironmentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateEnvironment(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleEnvironmentsClient_DeleteEnvironment() { + ctx := context.Background() + c, err := cx.NewEnvironmentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteEnvironmentRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteEnvironment(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleEnvironmentsClient_LookupEnvironmentHistory() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewEnvironmentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.LookupEnvironmentHistoryRequest{ + // TODO: Fill request struct fields. + } + it := c.LookupEnvironmentHistory(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/dialogflow/cx/apiv3/experiments_client.go b/dialogflow/cx/apiv3/experiments_client.go new file mode 100644 index 00000000000..390c542bd69 --- /dev/null +++ b/dialogflow/cx/apiv3/experiments_client.go @@ -0,0 +1,438 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newExperimentsClientHook clientHook + +// ExperimentsCallOptions contains the retry settings for each method of ExperimentsClient. +type ExperimentsCallOptions struct { + ListExperiments []gax.CallOption + GetExperiment []gax.CallOption + CreateExperiment []gax.CallOption + UpdateExperiment []gax.CallOption + DeleteExperiment []gax.CallOption + StartExperiment []gax.CallOption + StopExperiment []gax.CallOption +} + +func defaultExperimentsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultExperimentsCallOptions() *ExperimentsCallOptions { + return &ExperimentsCallOptions{ + ListExperiments: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetExperiment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateExperiment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateExperiment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteExperiment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + StartExperiment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + StopExperiment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// ExperimentsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type ExperimentsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + experimentsClient cxpb.ExperimentsClient + + // The call options for this service. + CallOptions *ExperimentsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewExperimentsClient creates a new experiments client. +// +// Service for managing Experiments. +func NewExperimentsClient(ctx context.Context, opts ...option.ClientOption) (*ExperimentsClient, error) { + clientOpts := defaultExperimentsClientOptions() + + if newExperimentsClientHook != nil { + hookOpts, err := newExperimentsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &ExperimentsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultExperimentsCallOptions(), + + experimentsClient: cxpb.NewExperimentsClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ExperimentsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *ExperimentsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *ExperimentsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListExperiments returns the list of all experiments in the specified Environment. +func (c *ExperimentsClient) ListExperiments(ctx context.Context, req *cxpb.ListExperimentsRequest, opts ...gax.CallOption) *ExperimentIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListExperiments[0:len(c.CallOptions.ListExperiments):len(c.CallOptions.ListExperiments)], opts...) + it := &ExperimentIterator{} + req = proto.Clone(req).(*cxpb.ListExperimentsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Experiment, string, error) { + var resp *cxpb.ListExperimentsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.experimentsClient.ListExperiments(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetExperiments(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetExperiment retrieves the specified Experiment. +func (c *ExperimentsClient) GetExperiment(ctx context.Context, req *cxpb.GetExperimentRequest, opts ...gax.CallOption) (*cxpb.Experiment, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetExperiment[0:len(c.CallOptions.GetExperiment):len(c.CallOptions.GetExperiment)], opts...) + var resp *cxpb.Experiment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.experimentsClient.GetExperiment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateExperiment creates an Experiment in the specified Environment. +func (c *ExperimentsClient) CreateExperiment(ctx context.Context, req *cxpb.CreateExperimentRequest, opts ...gax.CallOption) (*cxpb.Experiment, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateExperiment[0:len(c.CallOptions.CreateExperiment):len(c.CallOptions.CreateExperiment)], opts...) + var resp *cxpb.Experiment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.experimentsClient.CreateExperiment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateExperiment updates the specified Experiment. +func (c *ExperimentsClient) UpdateExperiment(ctx context.Context, req *cxpb.UpdateExperimentRequest, opts ...gax.CallOption) (*cxpb.Experiment, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "experiment.name", url.QueryEscape(req.GetExperiment().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateExperiment[0:len(c.CallOptions.UpdateExperiment):len(c.CallOptions.UpdateExperiment)], opts...) + var resp *cxpb.Experiment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.experimentsClient.UpdateExperiment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteExperiment deletes the specified Experiment. +func (c *ExperimentsClient) DeleteExperiment(ctx context.Context, req *cxpb.DeleteExperimentRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteExperiment[0:len(c.CallOptions.DeleteExperiment):len(c.CallOptions.DeleteExperiment)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.experimentsClient.DeleteExperiment(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// StartExperiment starts the specified Experiment. This rpc only changes the state of +// experiment from PENDING to RUNNING. +func (c *ExperimentsClient) StartExperiment(ctx context.Context, req *cxpb.StartExperimentRequest, opts ...gax.CallOption) (*cxpb.Experiment, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.StartExperiment[0:len(c.CallOptions.StartExperiment):len(c.CallOptions.StartExperiment)], opts...) + var resp *cxpb.Experiment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.experimentsClient.StartExperiment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// StopExperiment stops the specified Experiment. This rpc only changes the state of +// experiment from RUNNING to DONE. +func (c *ExperimentsClient) StopExperiment(ctx context.Context, req *cxpb.StopExperimentRequest, opts ...gax.CallOption) (*cxpb.Experiment, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.StopExperiment[0:len(c.CallOptions.StopExperiment):len(c.CallOptions.StopExperiment)], opts...) + var resp *cxpb.Experiment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.experimentsClient.StopExperiment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ExperimentIterator manages a stream of *cxpb.Experiment. +type ExperimentIterator struct { + items []*cxpb.Experiment + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Experiment, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ExperimentIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *ExperimentIterator) Next() (*cxpb.Experiment, error) { + var item *cxpb.Experiment + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ExperimentIterator) bufLen() int { + return len(it.items) +} + +func (it *ExperimentIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/experiments_client_example_test.go b/dialogflow/cx/apiv3/experiments_client_example_test.go new file mode 100644 index 00000000000..bc8efccabbf --- /dev/null +++ b/dialogflow/cx/apiv3/experiments_client_example_test.go @@ -0,0 +1,178 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewExperimentsClient() { + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleExperimentsClient_ListExperiments() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListExperimentsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListExperiments(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleExperimentsClient_GetExperiment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetExperimentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetExperiment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExperimentsClient_CreateExperiment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateExperimentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateExperiment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExperimentsClient_UpdateExperiment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateExperimentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateExperiment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExperimentsClient_DeleteExperiment() { + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteExperimentRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteExperiment(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleExperimentsClient_StartExperiment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.StartExperimentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.StartExperiment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExperimentsClient_StopExperiment() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewExperimentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.StopExperimentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.StopExperiment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/dialogflow/cx/apiv3/flows_client.go b/dialogflow/cx/apiv3/flows_client.go new file mode 100644 index 00000000000..83f713d0a0c --- /dev/null +++ b/dialogflow/cx/apiv3/flows_client.go @@ -0,0 +1,553 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + structpb "github.com/golang/protobuf/ptypes/struct" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newFlowsClientHook clientHook + +// FlowsCallOptions contains the retry settings for each method of FlowsClient. +type FlowsCallOptions struct { + CreateFlow []gax.CallOption + DeleteFlow []gax.CallOption + ListFlows []gax.CallOption + GetFlow []gax.CallOption + UpdateFlow []gax.CallOption + TrainFlow []gax.CallOption + ValidateFlow []gax.CallOption + GetFlowValidationResult []gax.CallOption +} + +func defaultFlowsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultFlowsCallOptions() *FlowsCallOptions { + return &FlowsCallOptions{ + CreateFlow: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteFlow: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListFlows: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetFlow: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateFlow: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + TrainFlow: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ValidateFlow: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetFlowValidationResult: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// FlowsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type FlowsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + flowsClient cxpb.FlowsClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *FlowsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewFlowsClient creates a new flows client. +// +// Service for managing Flows. +func NewFlowsClient(ctx context.Context, opts ...option.ClientOption) (*FlowsClient, error) { + clientOpts := defaultFlowsClientOptions() + + if newFlowsClientHook != nil { + hookOpts, err := newFlowsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &FlowsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultFlowsCallOptions(), + + flowsClient: cxpb.NewFlowsClient(connPool), + } + c.setGoogleClientInfo() + + c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *FlowsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *FlowsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *FlowsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateFlow creates a flow in the specified agent. +func (c *FlowsClient) CreateFlow(ctx context.Context, req *cxpb.CreateFlowRequest, opts ...gax.CallOption) (*cxpb.Flow, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateFlow[0:len(c.CallOptions.CreateFlow):len(c.CallOptions.CreateFlow)], opts...) + var resp *cxpb.Flow + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flowsClient.CreateFlow(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteFlow deletes a specified flow. +func (c *FlowsClient) DeleteFlow(ctx context.Context, req *cxpb.DeleteFlowRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteFlow[0:len(c.CallOptions.DeleteFlow):len(c.CallOptions.DeleteFlow)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.flowsClient.DeleteFlow(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// ListFlows returns the list of all flows in the specified agent. +func (c *FlowsClient) ListFlows(ctx context.Context, req *cxpb.ListFlowsRequest, opts ...gax.CallOption) *FlowIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListFlows[0:len(c.CallOptions.ListFlows):len(c.CallOptions.ListFlows)], opts...) + it := &FlowIterator{} + req = proto.Clone(req).(*cxpb.ListFlowsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Flow, string, error) { + var resp *cxpb.ListFlowsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flowsClient.ListFlows(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetFlows(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetFlow retrieves the specified flow. +func (c *FlowsClient) GetFlow(ctx context.Context, req *cxpb.GetFlowRequest, opts ...gax.CallOption) (*cxpb.Flow, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetFlow[0:len(c.CallOptions.GetFlow):len(c.CallOptions.GetFlow)], opts...) + var resp *cxpb.Flow + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flowsClient.GetFlow(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateFlow updates the specified flow. +func (c *FlowsClient) UpdateFlow(ctx context.Context, req *cxpb.UpdateFlowRequest, opts ...gax.CallOption) (*cxpb.Flow, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "flow.name", url.QueryEscape(req.GetFlow().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateFlow[0:len(c.CallOptions.UpdateFlow):len(c.CallOptions.UpdateFlow)], opts...) + var resp *cxpb.Flow + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flowsClient.UpdateFlow(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// TrainFlow trains the specified flow. Note that only the flow in ‘draft’ environment +// is trained. +func (c *FlowsClient) TrainFlow(ctx context.Context, req *cxpb.TrainFlowRequest, opts ...gax.CallOption) (*TrainFlowOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.TrainFlow[0:len(c.CallOptions.TrainFlow):len(c.CallOptions.TrainFlow)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flowsClient.TrainFlow(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &TrainFlowOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// ValidateFlow validates the specified flow and creates or updates validation results. +// Please call this API after the training is completed to get the complete +// validation results. +func (c *FlowsClient) ValidateFlow(ctx context.Context, req *cxpb.ValidateFlowRequest, opts ...gax.CallOption) (*cxpb.FlowValidationResult, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ValidateFlow[0:len(c.CallOptions.ValidateFlow):len(c.CallOptions.ValidateFlow)], opts...) + var resp *cxpb.FlowValidationResult + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flowsClient.ValidateFlow(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// GetFlowValidationResult gets the latest flow validation result. Flow validation is performed +// when ValidateFlow is called. +func (c *FlowsClient) GetFlowValidationResult(ctx context.Context, req *cxpb.GetFlowValidationResultRequest, opts ...gax.CallOption) (*cxpb.FlowValidationResult, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetFlowValidationResult[0:len(c.CallOptions.GetFlowValidationResult):len(c.CallOptions.GetFlowValidationResult)], opts...) + var resp *cxpb.FlowValidationResult + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flowsClient.GetFlowValidationResult(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// TrainFlowOperation manages a long-running operation from TrainFlow. +type TrainFlowOperation struct { + lro *longrunning.Operation +} + +// TrainFlowOperation returns a new TrainFlowOperation from a given name. +// The name must be that of a previously created TrainFlowOperation, possibly from a different process. +func (c *FlowsClient) TrainFlowOperation(name string) *TrainFlowOperation { + return &TrainFlowOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *TrainFlowOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *TrainFlowOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.Poll(ctx, nil, opts...) +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *TrainFlowOperation) Metadata() (*structpb.Struct, error) { + var meta structpb.Struct + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *TrainFlowOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *TrainFlowOperation) Name() string { + return op.lro.Name() +} + +// FlowIterator manages a stream of *cxpb.Flow. +type FlowIterator struct { + items []*cxpb.Flow + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Flow, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *FlowIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *FlowIterator) Next() (*cxpb.Flow, error) { + var item *cxpb.Flow + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *FlowIterator) bufLen() int { + return len(it.items) +} + +func (it *FlowIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/flows_client_example_test.go b/dialogflow/cx/apiv3/flows_client_example_test.go new file mode 100644 index 00000000000..f2464eebfc9 --- /dev/null +++ b/dialogflow/cx/apiv3/flows_client_example_test.go @@ -0,0 +1,201 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewFlowsClient() { + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleFlowsClient_CreateFlow() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateFlowRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateFlow(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFlowsClient_DeleteFlow() { + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteFlowRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteFlow(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleFlowsClient_ListFlows() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListFlowsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListFlows(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleFlowsClient_GetFlow() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetFlowRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetFlow(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFlowsClient_UpdateFlow() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateFlowRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateFlow(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFlowsClient_TrainFlow() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.TrainFlowRequest{ + // TODO: Fill request struct fields. + } + op, err := c.TrainFlow(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleFlowsClient_ValidateFlow() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ValidateFlowRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ValidateFlow(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFlowsClient_GetFlowValidationResult() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewFlowsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetFlowValidationResultRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetFlowValidationResult(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/dialogflow/cx/apiv3/gapic_metadata.json b/dialogflow/cx/apiv3/gapic_metadata.json new file mode 100644 index 00000000000..f4b58d1f182 --- /dev/null +++ b/dialogflow/cx/apiv3/gapic_metadata.json @@ -0,0 +1,565 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.dialogflow.cx.v3", + "libraryPackage": "cloud.google.com/go/dialogflow/cx/apiv3", + "services": { + "Agents": { + "clients": { + "grpc": { + "libraryClient": "AgentsClient", + "rpcs": { + "CreateAgent": { + "methods": [ + "CreateAgent" + ] + }, + "DeleteAgent": { + "methods": [ + "DeleteAgent" + ] + }, + "ExportAgent": { + "methods": [ + "ExportAgent" + ] + }, + "GetAgent": { + "methods": [ + "GetAgent" + ] + }, + "GetAgentValidationResult": { + "methods": [ + "GetAgentValidationResult" + ] + }, + "ListAgents": { + "methods": [ + "ListAgents" + ] + }, + "RestoreAgent": { + "methods": [ + "RestoreAgent" + ] + }, + "UpdateAgent": { + "methods": [ + "UpdateAgent" + ] + }, + "ValidateAgent": { + "methods": [ + "ValidateAgent" + ] + } + } + } + } + }, + "EntityTypes": { + "clients": { + "grpc": { + "libraryClient": "EntityTypesClient", + "rpcs": { + "CreateEntityType": { + "methods": [ + "CreateEntityType" + ] + }, + "DeleteEntityType": { + "methods": [ + "DeleteEntityType" + ] + }, + "GetEntityType": { + "methods": [ + "GetEntityType" + ] + }, + "ListEntityTypes": { + "methods": [ + "ListEntityTypes" + ] + }, + "UpdateEntityType": { + "methods": [ + "UpdateEntityType" + ] + } + } + } + } + }, + "Environments": { + "clients": { + "grpc": { + "libraryClient": "EnvironmentsClient", + "rpcs": { + "CreateEnvironment": { + "methods": [ + "CreateEnvironment" + ] + }, + "DeleteEnvironment": { + "methods": [ + "DeleteEnvironment" + ] + }, + "GetEnvironment": { + "methods": [ + "GetEnvironment" + ] + }, + "ListEnvironments": { + "methods": [ + "ListEnvironments" + ] + }, + "LookupEnvironmentHistory": { + "methods": [ + "LookupEnvironmentHistory" + ] + }, + "UpdateEnvironment": { + "methods": [ + "UpdateEnvironment" + ] + } + } + } + } + }, + "Experiments": { + "clients": { + "grpc": { + "libraryClient": "ExperimentsClient", + "rpcs": { + "CreateExperiment": { + "methods": [ + "CreateExperiment" + ] + }, + "DeleteExperiment": { + "methods": [ + "DeleteExperiment" + ] + }, + "GetExperiment": { + "methods": [ + "GetExperiment" + ] + }, + "ListExperiments": { + "methods": [ + "ListExperiments" + ] + }, + "StartExperiment": { + "methods": [ + "StartExperiment" + ] + }, + "StopExperiment": { + "methods": [ + "StopExperiment" + ] + }, + "UpdateExperiment": { + "methods": [ + "UpdateExperiment" + ] + } + } + } + } + }, + "Flows": { + "clients": { + "grpc": { + "libraryClient": "FlowsClient", + "rpcs": { + "CreateFlow": { + "methods": [ + "CreateFlow" + ] + }, + "DeleteFlow": { + "methods": [ + "DeleteFlow" + ] + }, + "GetFlow": { + "methods": [ + "GetFlow" + ] + }, + "GetFlowValidationResult": { + "methods": [ + "GetFlowValidationResult" + ] + }, + "ListFlows": { + "methods": [ + "ListFlows" + ] + }, + "TrainFlow": { + "methods": [ + "TrainFlow" + ] + }, + "UpdateFlow": { + "methods": [ + "UpdateFlow" + ] + }, + "ValidateFlow": { + "methods": [ + "ValidateFlow" + ] + } + } + } + } + }, + "Intents": { + "clients": { + "grpc": { + "libraryClient": "IntentsClient", + "rpcs": { + "CreateIntent": { + "methods": [ + "CreateIntent" + ] + }, + "DeleteIntent": { + "methods": [ + "DeleteIntent" + ] + }, + "GetIntent": { + "methods": [ + "GetIntent" + ] + }, + "ListIntents": { + "methods": [ + "ListIntents" + ] + }, + "UpdateIntent": { + "methods": [ + "UpdateIntent" + ] + } + } + } + } + }, + "Pages": { + "clients": { + "grpc": { + "libraryClient": "PagesClient", + "rpcs": { + "CreatePage": { + "methods": [ + "CreatePage" + ] + }, + "DeletePage": { + "methods": [ + "DeletePage" + ] + }, + "GetPage": { + "methods": [ + "GetPage" + ] + }, + "ListPages": { + "methods": [ + "ListPages" + ] + }, + "UpdatePage": { + "methods": [ + "UpdatePage" + ] + } + } + } + } + }, + "SecuritySettingsService": { + "clients": { + "grpc": { + "libraryClient": "SecuritySettingsClient", + "rpcs": { + "CreateSecuritySettings": { + "methods": [ + "CreateSecuritySettings" + ] + }, + "DeleteSecuritySettings": { + "methods": [ + "DeleteSecuritySettings" + ] + }, + "GetSecuritySettings": { + "methods": [ + "GetSecuritySettings" + ] + }, + "ListSecuritySettings": { + "methods": [ + "ListSecuritySettings" + ] + }, + "UpdateSecuritySettings": { + "methods": [ + "UpdateSecuritySettings" + ] + } + } + } + } + }, + "SessionEntityTypes": { + "clients": { + "grpc": { + "libraryClient": "SessionEntityTypesClient", + "rpcs": { + "CreateSessionEntityType": { + "methods": [ + "CreateSessionEntityType" + ] + }, + "DeleteSessionEntityType": { + "methods": [ + "DeleteSessionEntityType" + ] + }, + "GetSessionEntityType": { + "methods": [ + "GetSessionEntityType" + ] + }, + "ListSessionEntityTypes": { + "methods": [ + "ListSessionEntityTypes" + ] + }, + "UpdateSessionEntityType": { + "methods": [ + "UpdateSessionEntityType" + ] + } + } + } + } + }, + "Sessions": { + "clients": { + "grpc": { + "libraryClient": "SessionsClient", + "rpcs": { + "DetectIntent": { + "methods": [ + "DetectIntent" + ] + }, + "FulfillIntent": { + "methods": [ + "FulfillIntent" + ] + }, + "MatchIntent": { + "methods": [ + "MatchIntent" + ] + }, + "StreamingDetectIntent": { + "methods": [ + "StreamingDetectIntent" + ] + } + } + } + } + }, + "TestCases": { + "clients": { + "grpc": { + "libraryClient": "TestCasesClient", + "rpcs": { + "BatchDeleteTestCases": { + "methods": [ + "BatchDeleteTestCases" + ] + }, + "BatchRunTestCases": { + "methods": [ + "BatchRunTestCases" + ] + }, + "CalculateCoverage": { + "methods": [ + "CalculateCoverage" + ] + }, + "CreateTestCase": { + "methods": [ + "CreateTestCase" + ] + }, + "ExportTestCases": { + "methods": [ + "ExportTestCases" + ] + }, + "GetTestCase": { + "methods": [ + "GetTestCase" + ] + }, + "ImportTestCases": { + "methods": [ + "ImportTestCases" + ] + }, + "ListTestCaseResults": { + "methods": [ + "ListTestCaseResults" + ] + }, + "ListTestCases": { + "methods": [ + "ListTestCases" + ] + }, + "RunTestCase": { + "methods": [ + "RunTestCase" + ] + }, + "UpdateTestCase": { + "methods": [ + "UpdateTestCase" + ] + } + } + } + } + }, + "TransitionRouteGroups": { + "clients": { + "grpc": { + "libraryClient": "TransitionRouteGroupsClient", + "rpcs": { + "CreateTransitionRouteGroup": { + "methods": [ + "CreateTransitionRouteGroup" + ] + }, + "DeleteTransitionRouteGroup": { + "methods": [ + "DeleteTransitionRouteGroup" + ] + }, + "GetTransitionRouteGroup": { + "methods": [ + "GetTransitionRouteGroup" + ] + }, + "ListTransitionRouteGroups": { + "methods": [ + "ListTransitionRouteGroups" + ] + }, + "UpdateTransitionRouteGroup": { + "methods": [ + "UpdateTransitionRouteGroup" + ] + } + } + } + } + }, + "Versions": { + "clients": { + "grpc": { + "libraryClient": "VersionsClient", + "rpcs": { + "CreateVersion": { + "methods": [ + "CreateVersion" + ] + }, + "DeleteVersion": { + "methods": [ + "DeleteVersion" + ] + }, + "GetVersion": { + "methods": [ + "GetVersion" + ] + }, + "ListVersions": { + "methods": [ + "ListVersions" + ] + }, + "LoadVersion": { + "methods": [ + "LoadVersion" + ] + }, + "UpdateVersion": { + "methods": [ + "UpdateVersion" + ] + } + } + } + } + }, + "Webhooks": { + "clients": { + "grpc": { + "libraryClient": "WebhooksClient", + "rpcs": { + "CreateWebhook": { + "methods": [ + "CreateWebhook" + ] + }, + "DeleteWebhook": { + "methods": [ + "DeleteWebhook" + ] + }, + "GetWebhook": { + "methods": [ + "GetWebhook" + ] + }, + "ListWebhooks": { + "methods": [ + "ListWebhooks" + ] + }, + "UpdateWebhook": { + "methods": [ + "UpdateWebhook" + ] + } + } + } + } + } + } +} diff --git a/dialogflow/cx/apiv3/intents_client.go b/dialogflow/cx/apiv3/intents_client.go new file mode 100644 index 00000000000..10774e861f7 --- /dev/null +++ b/dialogflow/cx/apiv3/intents_client.go @@ -0,0 +1,368 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newIntentsClientHook clientHook + +// IntentsCallOptions contains the retry settings for each method of IntentsClient. +type IntentsCallOptions struct { + ListIntents []gax.CallOption + GetIntent []gax.CallOption + CreateIntent []gax.CallOption + UpdateIntent []gax.CallOption + DeleteIntent []gax.CallOption +} + +func defaultIntentsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultIntentsCallOptions() *IntentsCallOptions { + return &IntentsCallOptions{ + ListIntents: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetIntent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateIntent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateIntent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteIntent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// IntentsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type IntentsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + intentsClient cxpb.IntentsClient + + // The call options for this service. + CallOptions *IntentsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewIntentsClient creates a new intents client. +// +// Service for managing Intents. +func NewIntentsClient(ctx context.Context, opts ...option.ClientOption) (*IntentsClient, error) { + clientOpts := defaultIntentsClientOptions() + + if newIntentsClientHook != nil { + hookOpts, err := newIntentsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &IntentsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultIntentsCallOptions(), + + intentsClient: cxpb.NewIntentsClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *IntentsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *IntentsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *IntentsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListIntents returns the list of all intents in the specified agent. +func (c *IntentsClient) ListIntents(ctx context.Context, req *cxpb.ListIntentsRequest, opts ...gax.CallOption) *IntentIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListIntents[0:len(c.CallOptions.ListIntents):len(c.CallOptions.ListIntents)], opts...) + it := &IntentIterator{} + req = proto.Clone(req).(*cxpb.ListIntentsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Intent, string, error) { + var resp *cxpb.ListIntentsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.intentsClient.ListIntents(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetIntents(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetIntent retrieves the specified intent. +func (c *IntentsClient) GetIntent(ctx context.Context, req *cxpb.GetIntentRequest, opts ...gax.CallOption) (*cxpb.Intent, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetIntent[0:len(c.CallOptions.GetIntent):len(c.CallOptions.GetIntent)], opts...) + var resp *cxpb.Intent + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.intentsClient.GetIntent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateIntent creates an intent in the specified agent. +func (c *IntentsClient) CreateIntent(ctx context.Context, req *cxpb.CreateIntentRequest, opts ...gax.CallOption) (*cxpb.Intent, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateIntent[0:len(c.CallOptions.CreateIntent):len(c.CallOptions.CreateIntent)], opts...) + var resp *cxpb.Intent + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.intentsClient.CreateIntent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateIntent updates the specified intent. +func (c *IntentsClient) UpdateIntent(ctx context.Context, req *cxpb.UpdateIntentRequest, opts ...gax.CallOption) (*cxpb.Intent, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "intent.name", url.QueryEscape(req.GetIntent().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateIntent[0:len(c.CallOptions.UpdateIntent):len(c.CallOptions.UpdateIntent)], opts...) + var resp *cxpb.Intent + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.intentsClient.UpdateIntent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteIntent deletes the specified intent. +func (c *IntentsClient) DeleteIntent(ctx context.Context, req *cxpb.DeleteIntentRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteIntent[0:len(c.CallOptions.DeleteIntent):len(c.CallOptions.DeleteIntent)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.intentsClient.DeleteIntent(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// IntentIterator manages a stream of *cxpb.Intent. +type IntentIterator struct { + items []*cxpb.Intent + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Intent, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *IntentIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *IntentIterator) Next() (*cxpb.Intent, error) { + var item *cxpb.Intent + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *IntentIterator) bufLen() int { + return len(it.items) +} + +func (it *IntentIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/intents_client_example_test.go b/dialogflow/cx/apiv3/intents_client_example_test.go new file mode 100644 index 00000000000..804ebd26f2b --- /dev/null +++ b/dialogflow/cx/apiv3/intents_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewIntentsClient() { + ctx := context.Background() + c, err := cx.NewIntentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleIntentsClient_ListIntents() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewIntentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListIntentsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListIntents(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleIntentsClient_GetIntent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewIntentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetIntentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIntent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleIntentsClient_CreateIntent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewIntentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateIntentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateIntent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleIntentsClient_UpdateIntent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewIntentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateIntentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateIntent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleIntentsClient_DeleteIntent() { + ctx := context.Background() + c, err := cx.NewIntentsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteIntentRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteIntent(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/dialogflow/cx/apiv3/pages_client.go b/dialogflow/cx/apiv3/pages_client.go new file mode 100644 index 00000000000..8df429c54b3 --- /dev/null +++ b/dialogflow/cx/apiv3/pages_client.go @@ -0,0 +1,368 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newPagesClientHook clientHook + +// PagesCallOptions contains the retry settings for each method of PagesClient. +type PagesCallOptions struct { + ListPages []gax.CallOption + GetPage []gax.CallOption + CreatePage []gax.CallOption + UpdatePage []gax.CallOption + DeletePage []gax.CallOption +} + +func defaultPagesClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultPagesCallOptions() *PagesCallOptions { + return &PagesCallOptions{ + ListPages: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetPage: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreatePage: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdatePage: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeletePage: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// PagesClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type PagesClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + pagesClient cxpb.PagesClient + + // The call options for this service. + CallOptions *PagesCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewPagesClient creates a new pages client. +// +// Service for managing [Pages][google.cloud.dialogflow.cx.v3.Page (at http://google.cloud.dialogflow.cx.v3.Page)]. +func NewPagesClient(ctx context.Context, opts ...option.ClientOption) (*PagesClient, error) { + clientOpts := defaultPagesClientOptions() + + if newPagesClientHook != nil { + hookOpts, err := newPagesClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &PagesClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultPagesCallOptions(), + + pagesClient: cxpb.NewPagesClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *PagesClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *PagesClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *PagesClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListPages returns the list of all pages in the specified flow. +func (c *PagesClient) ListPages(ctx context.Context, req *cxpb.ListPagesRequest, opts ...gax.CallOption) *PageIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListPages[0:len(c.CallOptions.ListPages):len(c.CallOptions.ListPages)], opts...) + it := &PageIterator{} + req = proto.Clone(req).(*cxpb.ListPagesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Page, string, error) { + var resp *cxpb.ListPagesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.pagesClient.ListPages(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetPages(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetPage retrieves the specified page. +func (c *PagesClient) GetPage(ctx context.Context, req *cxpb.GetPageRequest, opts ...gax.CallOption) (*cxpb.Page, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetPage[0:len(c.CallOptions.GetPage):len(c.CallOptions.GetPage)], opts...) + var resp *cxpb.Page + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.pagesClient.GetPage(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreatePage creates a page in the specified flow. +func (c *PagesClient) CreatePage(ctx context.Context, req *cxpb.CreatePageRequest, opts ...gax.CallOption) (*cxpb.Page, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreatePage[0:len(c.CallOptions.CreatePage):len(c.CallOptions.CreatePage)], opts...) + var resp *cxpb.Page + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.pagesClient.CreatePage(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdatePage updates the specified page. +func (c *PagesClient) UpdatePage(ctx context.Context, req *cxpb.UpdatePageRequest, opts ...gax.CallOption) (*cxpb.Page, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "page.name", url.QueryEscape(req.GetPage().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdatePage[0:len(c.CallOptions.UpdatePage):len(c.CallOptions.UpdatePage)], opts...) + var resp *cxpb.Page + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.pagesClient.UpdatePage(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeletePage deletes the specified page. +func (c *PagesClient) DeletePage(ctx context.Context, req *cxpb.DeletePageRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeletePage[0:len(c.CallOptions.DeletePage):len(c.CallOptions.DeletePage)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.pagesClient.DeletePage(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// PageIterator manages a stream of *cxpb.Page. +type PageIterator struct { + items []*cxpb.Page + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Page, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *PageIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *PageIterator) Next() (*cxpb.Page, error) { + var item *cxpb.Page + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *PageIterator) bufLen() int { + return len(it.items) +} + +func (it *PageIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/pages_client_example_test.go b/dialogflow/cx/apiv3/pages_client_example_test.go new file mode 100644 index 00000000000..51f8840a4ac --- /dev/null +++ b/dialogflow/cx/apiv3/pages_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewPagesClient() { + ctx := context.Background() + c, err := cx.NewPagesClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExamplePagesClient_ListPages() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewPagesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListPagesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListPages(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExamplePagesClient_GetPage() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewPagesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetPageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetPage(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePagesClient_CreatePage() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewPagesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreatePageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreatePage(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePagesClient_UpdatePage() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewPagesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdatePageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdatePage(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePagesClient_DeletePage() { + ctx := context.Background() + c, err := cx.NewPagesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeletePageRequest{ + // TODO: Fill request struct fields. + } + err = c.DeletePage(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/dialogflow/cx/apiv3/security_settings_client.go b/dialogflow/cx/apiv3/security_settings_client.go new file mode 100644 index 00000000000..e548a1c4e5e --- /dev/null +++ b/dialogflow/cx/apiv3/security_settings_client.go @@ -0,0 +1,369 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newSecuritySettingsClientHook clientHook + +// SecuritySettingsCallOptions contains the retry settings for each method of SecuritySettingsClient. +type SecuritySettingsCallOptions struct { + CreateSecuritySettings []gax.CallOption + GetSecuritySettings []gax.CallOption + UpdateSecuritySettings []gax.CallOption + ListSecuritySettings []gax.CallOption + DeleteSecuritySettings []gax.CallOption +} + +func defaultSecuritySettingsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultSecuritySettingsCallOptions() *SecuritySettingsCallOptions { + return &SecuritySettingsCallOptions{ + CreateSecuritySettings: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetSecuritySettings: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateSecuritySettings: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListSecuritySettings: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteSecuritySettings: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// SecuritySettingsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type SecuritySettingsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + securitySettingsClient cxpb.SecuritySettingsServiceClient + + // The call options for this service. + CallOptions *SecuritySettingsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSecuritySettingsClient creates a new security settings service client. +// +// Service for managing security settings for Dialogflow. +func NewSecuritySettingsClient(ctx context.Context, opts ...option.ClientOption) (*SecuritySettingsClient, error) { + clientOpts := defaultSecuritySettingsClientOptions() + + if newSecuritySettingsClientHook != nil { + hookOpts, err := newSecuritySettingsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &SecuritySettingsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultSecuritySettingsCallOptions(), + + securitySettingsClient: cxpb.NewSecuritySettingsServiceClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SecuritySettingsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *SecuritySettingsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *SecuritySettingsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// CreateSecuritySettings create security settings in the specified location. +func (c *SecuritySettingsClient) CreateSecuritySettings(ctx context.Context, req *cxpb.CreateSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateSecuritySettings[0:len(c.CallOptions.CreateSecuritySettings):len(c.CallOptions.CreateSecuritySettings)], opts...) + var resp *cxpb.SecuritySettings + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.securitySettingsClient.CreateSecuritySettings(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// GetSecuritySettings retrieves the specified SecuritySettings. +// The returned settings may be stale by up to 1 minute. +func (c *SecuritySettingsClient) GetSecuritySettings(ctx context.Context, req *cxpb.GetSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetSecuritySettings[0:len(c.CallOptions.GetSecuritySettings):len(c.CallOptions.GetSecuritySettings)], opts...) + var resp *cxpb.SecuritySettings + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.securitySettingsClient.GetSecuritySettings(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateSecuritySettings updates the specified SecuritySettings. +func (c *SecuritySettingsClient) UpdateSecuritySettings(ctx context.Context, req *cxpb.UpdateSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "security_settings.name", url.QueryEscape(req.GetSecuritySettings().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateSecuritySettings[0:len(c.CallOptions.UpdateSecuritySettings):len(c.CallOptions.UpdateSecuritySettings)], opts...) + var resp *cxpb.SecuritySettings + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.securitySettingsClient.UpdateSecuritySettings(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ListSecuritySettings returns the list of all security settings in the specified location. +func (c *SecuritySettingsClient) ListSecuritySettings(ctx context.Context, req *cxpb.ListSecuritySettingsRequest, opts ...gax.CallOption) *SecuritySettingsIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListSecuritySettings[0:len(c.CallOptions.ListSecuritySettings):len(c.CallOptions.ListSecuritySettings)], opts...) + it := &SecuritySettingsIterator{} + req = proto.Clone(req).(*cxpb.ListSecuritySettingsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.SecuritySettings, string, error) { + var resp *cxpb.ListSecuritySettingsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.securitySettingsClient.ListSecuritySettings(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetSecuritySettings(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// DeleteSecuritySettings deletes the specified SecuritySettings. +func (c *SecuritySettingsClient) DeleteSecuritySettings(ctx context.Context, req *cxpb.DeleteSecuritySettingsRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteSecuritySettings[0:len(c.CallOptions.DeleteSecuritySettings):len(c.CallOptions.DeleteSecuritySettings)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.securitySettingsClient.DeleteSecuritySettings(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// SecuritySettingsIterator manages a stream of *cxpb.SecuritySettings. +type SecuritySettingsIterator struct { + items []*cxpb.SecuritySettings + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.SecuritySettings, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *SecuritySettingsIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *SecuritySettingsIterator) Next() (*cxpb.SecuritySettings, error) { + var item *cxpb.SecuritySettings + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *SecuritySettingsIterator) bufLen() int { + return len(it.items) +} + +func (it *SecuritySettingsIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/security_settings_client_example_test.go b/dialogflow/cx/apiv3/security_settings_client_example_test.go new file mode 100644 index 00000000000..cd299ce1a26 --- /dev/null +++ b/dialogflow/cx/apiv3/security_settings_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewSecuritySettingsClient() { + ctx := context.Background() + c, err := cx.NewSecuritySettingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleSecuritySettingsClient_CreateSecuritySettings() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSecuritySettingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateSecuritySettingsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateSecuritySettings(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecuritySettingsClient_GetSecuritySettings() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSecuritySettingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetSecuritySettingsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetSecuritySettings(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecuritySettingsClient_UpdateSecuritySettings() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSecuritySettingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateSecuritySettingsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateSecuritySettings(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecuritySettingsClient_ListSecuritySettings() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewSecuritySettingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListSecuritySettingsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListSecuritySettings(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleSecuritySettingsClient_DeleteSecuritySettings() { + ctx := context.Background() + c, err := cx.NewSecuritySettingsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteSecuritySettingsRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteSecuritySettings(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/dialogflow/cx/apiv3/session_entity_types_client.go b/dialogflow/cx/apiv3/session_entity_types_client.go new file mode 100644 index 00000000000..14ffad37981 --- /dev/null +++ b/dialogflow/cx/apiv3/session_entity_types_client.go @@ -0,0 +1,371 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newSessionEntityTypesClientHook clientHook + +// SessionEntityTypesCallOptions contains the retry settings for each method of SessionEntityTypesClient. +type SessionEntityTypesCallOptions struct { + ListSessionEntityTypes []gax.CallOption + GetSessionEntityType []gax.CallOption + CreateSessionEntityType []gax.CallOption + UpdateSessionEntityType []gax.CallOption + DeleteSessionEntityType []gax.CallOption +} + +func defaultSessionEntityTypesClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultSessionEntityTypesCallOptions() *SessionEntityTypesCallOptions { + return &SessionEntityTypesCallOptions{ + ListSessionEntityTypes: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetSessionEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateSessionEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateSessionEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteSessionEntityType: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// SessionEntityTypesClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type SessionEntityTypesClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + sessionEntityTypesClient cxpb.SessionEntityTypesClient + + // The call options for this service. + CallOptions *SessionEntityTypesCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSessionEntityTypesClient creates a new session entity types client. +// +// Service for managing SessionEntityTypes. +func NewSessionEntityTypesClient(ctx context.Context, opts ...option.ClientOption) (*SessionEntityTypesClient, error) { + clientOpts := defaultSessionEntityTypesClientOptions() + + if newSessionEntityTypesClientHook != nil { + hookOpts, err := newSessionEntityTypesClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &SessionEntityTypesClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultSessionEntityTypesCallOptions(), + + sessionEntityTypesClient: cxpb.NewSessionEntityTypesClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SessionEntityTypesClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *SessionEntityTypesClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *SessionEntityTypesClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListSessionEntityTypes returns the list of all session entity types in the specified session. +func (c *SessionEntityTypesClient) ListSessionEntityTypes(ctx context.Context, req *cxpb.ListSessionEntityTypesRequest, opts ...gax.CallOption) *SessionEntityTypeIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListSessionEntityTypes[0:len(c.CallOptions.ListSessionEntityTypes):len(c.CallOptions.ListSessionEntityTypes)], opts...) + it := &SessionEntityTypeIterator{} + req = proto.Clone(req).(*cxpb.ListSessionEntityTypesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.SessionEntityType, string, error) { + var resp *cxpb.ListSessionEntityTypesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionEntityTypesClient.ListSessionEntityTypes(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetSessionEntityTypes(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetSessionEntityType retrieves the specified session entity type. +func (c *SessionEntityTypesClient) GetSessionEntityType(ctx context.Context, req *cxpb.GetSessionEntityTypeRequest, opts ...gax.CallOption) (*cxpb.SessionEntityType, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetSessionEntityType[0:len(c.CallOptions.GetSessionEntityType):len(c.CallOptions.GetSessionEntityType)], opts...) + var resp *cxpb.SessionEntityType + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionEntityTypesClient.GetSessionEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateSessionEntityType creates a session entity type. +// +// If the specified session entity type already exists, overrides the +// session entity type. +func (c *SessionEntityTypesClient) CreateSessionEntityType(ctx context.Context, req *cxpb.CreateSessionEntityTypeRequest, opts ...gax.CallOption) (*cxpb.SessionEntityType, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateSessionEntityType[0:len(c.CallOptions.CreateSessionEntityType):len(c.CallOptions.CreateSessionEntityType)], opts...) + var resp *cxpb.SessionEntityType + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionEntityTypesClient.CreateSessionEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateSessionEntityType updates the specified session entity type. +func (c *SessionEntityTypesClient) UpdateSessionEntityType(ctx context.Context, req *cxpb.UpdateSessionEntityTypeRequest, opts ...gax.CallOption) (*cxpb.SessionEntityType, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "session_entity_type.name", url.QueryEscape(req.GetSessionEntityType().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateSessionEntityType[0:len(c.CallOptions.UpdateSessionEntityType):len(c.CallOptions.UpdateSessionEntityType)], opts...) + var resp *cxpb.SessionEntityType + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionEntityTypesClient.UpdateSessionEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteSessionEntityType deletes the specified session entity type. +func (c *SessionEntityTypesClient) DeleteSessionEntityType(ctx context.Context, req *cxpb.DeleteSessionEntityTypeRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteSessionEntityType[0:len(c.CallOptions.DeleteSessionEntityType):len(c.CallOptions.DeleteSessionEntityType)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.sessionEntityTypesClient.DeleteSessionEntityType(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// SessionEntityTypeIterator manages a stream of *cxpb.SessionEntityType. +type SessionEntityTypeIterator struct { + items []*cxpb.SessionEntityType + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.SessionEntityType, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *SessionEntityTypeIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *SessionEntityTypeIterator) Next() (*cxpb.SessionEntityType, error) { + var item *cxpb.SessionEntityType + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *SessionEntityTypeIterator) bufLen() int { + return len(it.items) +} + +func (it *SessionEntityTypeIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/session_entity_types_client_example_test.go b/dialogflow/cx/apiv3/session_entity_types_client_example_test.go new file mode 100644 index 00000000000..eea7879d00a --- /dev/null +++ b/dialogflow/cx/apiv3/session_entity_types_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewSessionEntityTypesClient() { + ctx := context.Background() + c, err := cx.NewSessionEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleSessionEntityTypesClient_ListSessionEntityTypes() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewSessionEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListSessionEntityTypesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListSessionEntityTypes(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleSessionEntityTypesClient_GetSessionEntityType() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSessionEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetSessionEntityTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetSessionEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSessionEntityTypesClient_CreateSessionEntityType() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSessionEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateSessionEntityTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateSessionEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSessionEntityTypesClient_UpdateSessionEntityType() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSessionEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateSessionEntityTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateSessionEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSessionEntityTypesClient_DeleteSessionEntityType() { + ctx := context.Background() + c, err := cx.NewSessionEntityTypesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteSessionEntityTypeRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteSessionEntityType(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/dialogflow/cx/apiv3/sessions_client.go b/dialogflow/cx/apiv3/sessions_client.go new file mode 100644 index 00000000000..3a7b8fa7fd9 --- /dev/null +++ b/dialogflow/cx/apiv3/sessions_client.go @@ -0,0 +1,272 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newSessionsClientHook clientHook + +// SessionsCallOptions contains the retry settings for each method of SessionsClient. +type SessionsCallOptions struct { + DetectIntent []gax.CallOption + StreamingDetectIntent []gax.CallOption + MatchIntent []gax.CallOption + FulfillIntent []gax.CallOption +} + +func defaultSessionsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultSessionsCallOptions() *SessionsCallOptions { + return &SessionsCallOptions{ + DetectIntent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + StreamingDetectIntent: []gax.CallOption{}, + MatchIntent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + FulfillIntent: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// SessionsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type SessionsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + sessionsClient cxpb.SessionsClient + + // The call options for this service. + CallOptions *SessionsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSessionsClient creates a new sessions client. +// +// A session represents an interaction with a user. You retrieve user input +// and pass it to the DetectIntent method to determine +// user intent and respond. +func NewSessionsClient(ctx context.Context, opts ...option.ClientOption) (*SessionsClient, error) { + clientOpts := defaultSessionsClientOptions() + + if newSessionsClientHook != nil { + hookOpts, err := newSessionsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &SessionsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultSessionsCallOptions(), + + sessionsClient: cxpb.NewSessionsClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SessionsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *SessionsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *SessionsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// DetectIntent processes a natural language query and returns structured, actionable data +// as a result. This method is not idempotent, because it may cause session +// entity types to be updated, which in turn might affect results of future +// queries. +// +// Note: Always use agent versions for production traffic. +// See Versions and +// environments (at https://cloud.google.com/dialogflow/cx/docs/concept/version). +func (c *SessionsClient) DetectIntent(ctx context.Context, req *cxpb.DetectIntentRequest, opts ...gax.CallOption) (*cxpb.DetectIntentResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 220000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "session", url.QueryEscape(req.GetSession()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DetectIntent[0:len(c.CallOptions.DetectIntent):len(c.CallOptions.DetectIntent)], opts...) + var resp *cxpb.DetectIntentResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionsClient.DetectIntent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// StreamingDetectIntent processes a natural language query in audio format in a streaming fashion +// and returns structured, actionable data as a result. This method is only +// available via the gRPC API (not REST). +// +// Note: Always use agent versions for production traffic. +// See Versions and +// environments (at https://cloud.google.com/dialogflow/cx/docs/concept/version). +func (c *SessionsClient) StreamingDetectIntent(ctx context.Context, opts ...gax.CallOption) (cxpb.Sessions_StreamingDetectIntentClient, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.StreamingDetectIntent[0:len(c.CallOptions.StreamingDetectIntent):len(c.CallOptions.StreamingDetectIntent)], opts...) + var resp cxpb.Sessions_StreamingDetectIntentClient + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionsClient.StreamingDetectIntent(ctx, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// MatchIntent returns preliminary intent match results, doesn’t change the session +// status. +func (c *SessionsClient) MatchIntent(ctx context.Context, req *cxpb.MatchIntentRequest, opts ...gax.CallOption) (*cxpb.MatchIntentResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "session", url.QueryEscape(req.GetSession()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.MatchIntent[0:len(c.CallOptions.MatchIntent):len(c.CallOptions.MatchIntent)], opts...) + var resp *cxpb.MatchIntentResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionsClient.MatchIntent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// FulfillIntent fulfills a matched intent returned by MatchIntent. +// Must be called after MatchIntent, with input from +// MatchIntentResponse. Otherwise, the behavior is undefined. +func (c *SessionsClient) FulfillIntent(ctx context.Context, req *cxpb.FulfillIntentRequest, opts ...gax.CallOption) (*cxpb.FulfillIntentResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "match_intent_request.session", url.QueryEscape(req.GetMatchIntentRequest().GetSession()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.FulfillIntent[0:len(c.CallOptions.FulfillIntent):len(c.CallOptions.FulfillIntent)], opts...) + var resp *cxpb.FulfillIntentResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.sessionsClient.FulfillIntent(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/dialogflow/cx/apiv3/sessions_client_example_test.go b/dialogflow/cx/apiv3/sessions_client_example_test.go new file mode 100644 index 00000000000..8c36fa95fdc --- /dev/null +++ b/dialogflow/cx/apiv3/sessions_client_example_test.go @@ -0,0 +1,131 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + "io" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewSessionsClient() { + ctx := context.Background() + c, err := cx.NewSessionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleSessionsClient_DetectIntent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSessionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DetectIntentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DetectIntent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSessionsClient_StreamingDetectIntent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSessionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + stream, err := c.StreamingDetectIntent(ctx) + if err != nil { + // TODO: Handle error. + } + go func() { + reqs := []*cxpb.StreamingDetectIntentRequest{ + // TODO: Create requests. + } + for _, req := range reqs { + if err := stream.Send(req); err != nil { + // TODO: Handle error. + } + } + stream.CloseSend() + }() + for { + resp, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + // TODO: handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleSessionsClient_MatchIntent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSessionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.MatchIntentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.MatchIntent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSessionsClient_FulfillIntent() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewSessionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.FulfillIntentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.FulfillIntent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/dialogflow/cx/apiv3/test_cases_client.go b/dialogflow/cx/apiv3/test_cases_client.go new file mode 100644 index 00000000000..83c135edf88 --- /dev/null +++ b/dialogflow/cx/apiv3/test_cases_client.go @@ -0,0 +1,944 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newTestCasesClientHook clientHook + +// TestCasesCallOptions contains the retry settings for each method of TestCasesClient. +type TestCasesCallOptions struct { + ListTestCases []gax.CallOption + BatchDeleteTestCases []gax.CallOption + GetTestCase []gax.CallOption + CreateTestCase []gax.CallOption + UpdateTestCase []gax.CallOption + RunTestCase []gax.CallOption + BatchRunTestCases []gax.CallOption + CalculateCoverage []gax.CallOption + ImportTestCases []gax.CallOption + ExportTestCases []gax.CallOption + ListTestCaseResults []gax.CallOption +} + +func defaultTestCasesClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultTestCasesCallOptions() *TestCasesCallOptions { + return &TestCasesCallOptions{ + ListTestCases: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + BatchDeleteTestCases: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetTestCase: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateTestCase: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateTestCase: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + RunTestCase: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + BatchRunTestCases: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CalculateCoverage: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ImportTestCases: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ExportTestCases: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListTestCaseResults: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// TestCasesClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type TestCasesClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + testCasesClient cxpb.TestCasesClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *TestCasesCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTestCasesClient creates a new test cases client. +// +// Service for managing [Test Cases][google.cloud.dialogflow.cx.v3.TestCase] and +// [Test Case Results][google.cloud.dialogflow.cx.v3.TestCaseResult]. +func NewTestCasesClient(ctx context.Context, opts ...option.ClientOption) (*TestCasesClient, error) { + clientOpts := defaultTestCasesClientOptions() + + if newTestCasesClientHook != nil { + hookOpts, err := newTestCasesClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &TestCasesClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultTestCasesCallOptions(), + + testCasesClient: cxpb.NewTestCasesClient(connPool), + } + c.setGoogleClientInfo() + + c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TestCasesClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *TestCasesClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *TestCasesClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListTestCases fetches a list of test cases for a given agent. +func (c *TestCasesClient) ListTestCases(ctx context.Context, req *cxpb.ListTestCasesRequest, opts ...gax.CallOption) *TestCaseIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListTestCases[0:len(c.CallOptions.ListTestCases):len(c.CallOptions.ListTestCases)], opts...) + it := &TestCaseIterator{} + req = proto.Clone(req).(*cxpb.ListTestCasesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.TestCase, string, error) { + var resp *cxpb.ListTestCasesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.ListTestCases(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetTestCases(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// BatchDeleteTestCases batch deletes test cases. +func (c *TestCasesClient) BatchDeleteTestCases(ctx context.Context, req *cxpb.BatchDeleteTestCasesRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.BatchDeleteTestCases[0:len(c.CallOptions.BatchDeleteTestCases):len(c.CallOptions.BatchDeleteTestCases)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.testCasesClient.BatchDeleteTestCases(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// GetTestCase gets a test case. +func (c *TestCasesClient) GetTestCase(ctx context.Context, req *cxpb.GetTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetTestCase[0:len(c.CallOptions.GetTestCase):len(c.CallOptions.GetTestCase)], opts...) + var resp *cxpb.TestCase + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.GetTestCase(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateTestCase creates a test case for the given agent. +func (c *TestCasesClient) CreateTestCase(ctx context.Context, req *cxpb.CreateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateTestCase[0:len(c.CallOptions.CreateTestCase):len(c.CallOptions.CreateTestCase)], opts...) + var resp *cxpb.TestCase + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.CreateTestCase(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateTestCase updates the specified test case. +func (c *TestCasesClient) UpdateTestCase(ctx context.Context, req *cxpb.UpdateTestCaseRequest, opts ...gax.CallOption) (*cxpb.TestCase, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "test_case.name", url.QueryEscape(req.GetTestCase().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateTestCase[0:len(c.CallOptions.UpdateTestCase):len(c.CallOptions.UpdateTestCase)], opts...) + var resp *cxpb.TestCase + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.UpdateTestCase(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// RunTestCase kicks off a test case run. +func (c *TestCasesClient) RunTestCase(ctx context.Context, req *cxpb.RunTestCaseRequest, opts ...gax.CallOption) (*RunTestCaseOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.RunTestCase[0:len(c.CallOptions.RunTestCase):len(c.CallOptions.RunTestCase)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.RunTestCase(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &RunTestCaseOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// BatchRunTestCases kicks off a batch run of test cases. +func (c *TestCasesClient) BatchRunTestCases(ctx context.Context, req *cxpb.BatchRunTestCasesRequest, opts ...gax.CallOption) (*BatchRunTestCasesOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.BatchRunTestCases[0:len(c.CallOptions.BatchRunTestCases):len(c.CallOptions.BatchRunTestCases)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.BatchRunTestCases(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &BatchRunTestCasesOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// CalculateCoverage calculates the test coverage for an agent. +func (c *TestCasesClient) CalculateCoverage(ctx context.Context, req *cxpb.CalculateCoverageRequest, opts ...gax.CallOption) (*cxpb.CalculateCoverageResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "agent", url.QueryEscape(req.GetAgent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CalculateCoverage[0:len(c.CallOptions.CalculateCoverage):len(c.CallOptions.CalculateCoverage)], opts...) + var resp *cxpb.CalculateCoverageResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.CalculateCoverage(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ImportTestCases imports the test cases from a Cloud Storage bucket or a local file. It +// always creates new test cases and won’t overwite any existing ones. The +// provided ID in the imported test case is neglected. +func (c *TestCasesClient) ImportTestCases(ctx context.Context, req *cxpb.ImportTestCasesRequest, opts ...gax.CallOption) (*ImportTestCasesOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ImportTestCases[0:len(c.CallOptions.ImportTestCases):len(c.CallOptions.ImportTestCases)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.ImportTestCases(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &ImportTestCasesOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// ExportTestCases exports the test cases under the agent to a Cloud Storage bucket or a local +// file. Filter can be applied to export a subset of test cases. +func (c *TestCasesClient) ExportTestCases(ctx context.Context, req *cxpb.ExportTestCasesRequest, opts ...gax.CallOption) (*ExportTestCasesOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ExportTestCases[0:len(c.CallOptions.ExportTestCases):len(c.CallOptions.ExportTestCases)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.ExportTestCases(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &ExportTestCasesOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// ListTestCaseResults fetches a list of results for a given test case. +func (c *TestCasesClient) ListTestCaseResults(ctx context.Context, req *cxpb.ListTestCaseResultsRequest, opts ...gax.CallOption) *TestCaseResultIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListTestCaseResults[0:len(c.CallOptions.ListTestCaseResults):len(c.CallOptions.ListTestCaseResults)], opts...) + it := &TestCaseResultIterator{} + req = proto.Clone(req).(*cxpb.ListTestCaseResultsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.TestCaseResult, string, error) { + var resp *cxpb.ListTestCaseResultsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.testCasesClient.ListTestCaseResults(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetTestCaseResults(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// BatchRunTestCasesOperation manages a long-running operation from BatchRunTestCases. +type BatchRunTestCasesOperation struct { + lro *longrunning.Operation +} + +// BatchRunTestCasesOperation returns a new BatchRunTestCasesOperation from a given name. +// The name must be that of a previously created BatchRunTestCasesOperation, possibly from a different process. +func (c *TestCasesClient) BatchRunTestCasesOperation(name string) *BatchRunTestCasesOperation { + return &BatchRunTestCasesOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *BatchRunTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.BatchRunTestCasesResponse, error) { + var resp cxpb.BatchRunTestCasesResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *BatchRunTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.BatchRunTestCasesResponse, error) { + var resp cxpb.BatchRunTestCasesResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *BatchRunTestCasesOperation) Metadata() (*cxpb.BatchRunTestCasesMetadata, error) { + var meta cxpb.BatchRunTestCasesMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *BatchRunTestCasesOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *BatchRunTestCasesOperation) Name() string { + return op.lro.Name() +} + +// ExportTestCasesOperation manages a long-running operation from ExportTestCases. +type ExportTestCasesOperation struct { + lro *longrunning.Operation +} + +// ExportTestCasesOperation returns a new ExportTestCasesOperation from a given name. +// The name must be that of a previously created ExportTestCasesOperation, possibly from a different process. +func (c *TestCasesClient) ExportTestCasesOperation(name string) *ExportTestCasesOperation { + return &ExportTestCasesOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *ExportTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportTestCasesResponse, error) { + var resp cxpb.ExportTestCasesResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *ExportTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.ExportTestCasesResponse, error) { + var resp cxpb.ExportTestCasesResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *ExportTestCasesOperation) Metadata() (*cxpb.ExportTestCasesMetadata, error) { + var meta cxpb.ExportTestCasesMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *ExportTestCasesOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *ExportTestCasesOperation) Name() string { + return op.lro.Name() +} + +// ImportTestCasesOperation manages a long-running operation from ImportTestCases. +type ImportTestCasesOperation struct { + lro *longrunning.Operation +} + +// ImportTestCasesOperation returns a new ImportTestCasesOperation from a given name. +// The name must be that of a previously created ImportTestCasesOperation, possibly from a different process. +func (c *TestCasesClient) ImportTestCasesOperation(name string) *ImportTestCasesOperation { + return &ImportTestCasesOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *ImportTestCasesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.ImportTestCasesResponse, error) { + var resp cxpb.ImportTestCasesResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *ImportTestCasesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.ImportTestCasesResponse, error) { + var resp cxpb.ImportTestCasesResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *ImportTestCasesOperation) Metadata() (*cxpb.ImportTestCasesMetadata, error) { + var meta cxpb.ImportTestCasesMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *ImportTestCasesOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *ImportTestCasesOperation) Name() string { + return op.lro.Name() +} + +// RunTestCaseOperation manages a long-running operation from RunTestCase. +type RunTestCaseOperation struct { + lro *longrunning.Operation +} + +// RunTestCaseOperation returns a new RunTestCaseOperation from a given name. +// The name must be that of a previously created RunTestCaseOperation, possibly from a different process. +func (c *TestCasesClient) RunTestCaseOperation(name string) *RunTestCaseOperation { + return &RunTestCaseOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *RunTestCaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.RunTestCaseResponse, error) { + var resp cxpb.RunTestCaseResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *RunTestCaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.RunTestCaseResponse, error) { + var resp cxpb.RunTestCaseResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *RunTestCaseOperation) Metadata() (*cxpb.RunTestCaseMetadata, error) { + var meta cxpb.RunTestCaseMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *RunTestCaseOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *RunTestCaseOperation) Name() string { + return op.lro.Name() +} + +// TestCaseIterator manages a stream of *cxpb.TestCase. +type TestCaseIterator struct { + items []*cxpb.TestCase + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.TestCase, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *TestCaseIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *TestCaseIterator) Next() (*cxpb.TestCase, error) { + var item *cxpb.TestCase + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *TestCaseIterator) bufLen() int { + return len(it.items) +} + +func (it *TestCaseIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// TestCaseResultIterator manages a stream of *cxpb.TestCaseResult. +type TestCaseResultIterator struct { + items []*cxpb.TestCaseResult + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.TestCaseResult, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *TestCaseResultIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *TestCaseResultIterator) Next() (*cxpb.TestCaseResult, error) { + var item *cxpb.TestCaseResult + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *TestCaseResultIterator) bufLen() int { + return len(it.items) +} + +func (it *TestCaseResultIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/test_cases_client_example_test.go b/dialogflow/cx/apiv3/test_cases_client_example_test.go new file mode 100644 index 00000000000..2f7e7a82fd1 --- /dev/null +++ b/dialogflow/cx/apiv3/test_cases_client_example_test.go @@ -0,0 +1,285 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewTestCasesClient() { + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleTestCasesClient_ListTestCases() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListTestCasesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListTestCases(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleTestCasesClient_BatchDeleteTestCases() { + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.BatchDeleteTestCasesRequest{ + // TODO: Fill request struct fields. + } + err = c.BatchDeleteTestCases(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleTestCasesClient_GetTestCase() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetTestCaseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetTestCase(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_CreateTestCase() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateTestCaseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateTestCase(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_UpdateTestCase() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateTestCaseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateTestCase(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_RunTestCase() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.RunTestCaseRequest{ + // TODO: Fill request struct fields. + } + op, err := c.RunTestCase(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_BatchRunTestCases() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.BatchRunTestCasesRequest{ + // TODO: Fill request struct fields. + } + op, err := c.BatchRunTestCases(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_CalculateCoverage() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CalculateCoverageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CalculateCoverage(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_ImportTestCases() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ImportTestCasesRequest{ + // TODO: Fill request struct fields. + } + op, err := c.ImportTestCases(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_ExportTestCases() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ExportTestCasesRequest{ + // TODO: Fill request struct fields. + } + op, err := c.ExportTestCases(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTestCasesClient_ListTestCaseResults() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewTestCasesClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListTestCaseResultsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListTestCaseResults(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/dialogflow/cx/apiv3/transition_route_groups_client.go b/dialogflow/cx/apiv3/transition_route_groups_client.go new file mode 100644 index 00000000000..f86ed37f45a --- /dev/null +++ b/dialogflow/cx/apiv3/transition_route_groups_client.go @@ -0,0 +1,368 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newTransitionRouteGroupsClientHook clientHook + +// TransitionRouteGroupsCallOptions contains the retry settings for each method of TransitionRouteGroupsClient. +type TransitionRouteGroupsCallOptions struct { + ListTransitionRouteGroups []gax.CallOption + GetTransitionRouteGroup []gax.CallOption + CreateTransitionRouteGroup []gax.CallOption + UpdateTransitionRouteGroup []gax.CallOption + DeleteTransitionRouteGroup []gax.CallOption +} + +func defaultTransitionRouteGroupsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultTransitionRouteGroupsCallOptions() *TransitionRouteGroupsCallOptions { + return &TransitionRouteGroupsCallOptions{ + ListTransitionRouteGroups: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetTransitionRouteGroup: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateTransitionRouteGroup: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateTransitionRouteGroup: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteTransitionRouteGroup: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// TransitionRouteGroupsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type TransitionRouteGroupsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + transitionRouteGroupsClient cxpb.TransitionRouteGroupsClient + + // The call options for this service. + CallOptions *TransitionRouteGroupsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTransitionRouteGroupsClient creates a new transition route groups client. +// +// Service for managing TransitionRouteGroups. +func NewTransitionRouteGroupsClient(ctx context.Context, opts ...option.ClientOption) (*TransitionRouteGroupsClient, error) { + clientOpts := defaultTransitionRouteGroupsClientOptions() + + if newTransitionRouteGroupsClientHook != nil { + hookOpts, err := newTransitionRouteGroupsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &TransitionRouteGroupsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultTransitionRouteGroupsCallOptions(), + + transitionRouteGroupsClient: cxpb.NewTransitionRouteGroupsClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TransitionRouteGroupsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *TransitionRouteGroupsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *TransitionRouteGroupsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListTransitionRouteGroups returns the list of all transition route groups in the specified flow. +func (c *TransitionRouteGroupsClient) ListTransitionRouteGroups(ctx context.Context, req *cxpb.ListTransitionRouteGroupsRequest, opts ...gax.CallOption) *TransitionRouteGroupIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListTransitionRouteGroups[0:len(c.CallOptions.ListTransitionRouteGroups):len(c.CallOptions.ListTransitionRouteGroups)], opts...) + it := &TransitionRouteGroupIterator{} + req = proto.Clone(req).(*cxpb.ListTransitionRouteGroupsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.TransitionRouteGroup, string, error) { + var resp *cxpb.ListTransitionRouteGroupsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.transitionRouteGroupsClient.ListTransitionRouteGroups(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetTransitionRouteGroups(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetTransitionRouteGroup retrieves the specified TransitionRouteGroup. +func (c *TransitionRouteGroupsClient) GetTransitionRouteGroup(ctx context.Context, req *cxpb.GetTransitionRouteGroupRequest, opts ...gax.CallOption) (*cxpb.TransitionRouteGroup, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetTransitionRouteGroup[0:len(c.CallOptions.GetTransitionRouteGroup):len(c.CallOptions.GetTransitionRouteGroup)], opts...) + var resp *cxpb.TransitionRouteGroup + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.transitionRouteGroupsClient.GetTransitionRouteGroup(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateTransitionRouteGroup creates an TransitionRouteGroup in the specified flow. +func (c *TransitionRouteGroupsClient) CreateTransitionRouteGroup(ctx context.Context, req *cxpb.CreateTransitionRouteGroupRequest, opts ...gax.CallOption) (*cxpb.TransitionRouteGroup, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateTransitionRouteGroup[0:len(c.CallOptions.CreateTransitionRouteGroup):len(c.CallOptions.CreateTransitionRouteGroup)], opts...) + var resp *cxpb.TransitionRouteGroup + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.transitionRouteGroupsClient.CreateTransitionRouteGroup(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateTransitionRouteGroup updates the specified TransitionRouteGroup. +func (c *TransitionRouteGroupsClient) UpdateTransitionRouteGroup(ctx context.Context, req *cxpb.UpdateTransitionRouteGroupRequest, opts ...gax.CallOption) (*cxpb.TransitionRouteGroup, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "transition_route_group.name", url.QueryEscape(req.GetTransitionRouteGroup().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateTransitionRouteGroup[0:len(c.CallOptions.UpdateTransitionRouteGroup):len(c.CallOptions.UpdateTransitionRouteGroup)], opts...) + var resp *cxpb.TransitionRouteGroup + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.transitionRouteGroupsClient.UpdateTransitionRouteGroup(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteTransitionRouteGroup deletes the specified TransitionRouteGroup. +func (c *TransitionRouteGroupsClient) DeleteTransitionRouteGroup(ctx context.Context, req *cxpb.DeleteTransitionRouteGroupRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteTransitionRouteGroup[0:len(c.CallOptions.DeleteTransitionRouteGroup):len(c.CallOptions.DeleteTransitionRouteGroup)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.transitionRouteGroupsClient.DeleteTransitionRouteGroup(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// TransitionRouteGroupIterator manages a stream of *cxpb.TransitionRouteGroup. +type TransitionRouteGroupIterator struct { + items []*cxpb.TransitionRouteGroup + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.TransitionRouteGroup, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *TransitionRouteGroupIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *TransitionRouteGroupIterator) Next() (*cxpb.TransitionRouteGroup, error) { + var item *cxpb.TransitionRouteGroup + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *TransitionRouteGroupIterator) bufLen() int { + return len(it.items) +} + +func (it *TransitionRouteGroupIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/transition_route_groups_client_example_test.go b/dialogflow/cx/apiv3/transition_route_groups_client_example_test.go new file mode 100644 index 00000000000..85f3407396b --- /dev/null +++ b/dialogflow/cx/apiv3/transition_route_groups_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewTransitionRouteGroupsClient() { + ctx := context.Background() + c, err := cx.NewTransitionRouteGroupsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleTransitionRouteGroupsClient_ListTransitionRouteGroups() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewTransitionRouteGroupsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListTransitionRouteGroupsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListTransitionRouteGroups(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleTransitionRouteGroupsClient_GetTransitionRouteGroup() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTransitionRouteGroupsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetTransitionRouteGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetTransitionRouteGroup(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTransitionRouteGroupsClient_CreateTransitionRouteGroup() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTransitionRouteGroupsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateTransitionRouteGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateTransitionRouteGroup(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTransitionRouteGroupsClient_UpdateTransitionRouteGroup() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewTransitionRouteGroupsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateTransitionRouteGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateTransitionRouteGroup(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTransitionRouteGroupsClient_DeleteTransitionRouteGroup() { + ctx := context.Background() + c, err := cx.NewTransitionRouteGroupsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteTransitionRouteGroupRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteTransitionRouteGroup(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/dialogflow/cx/apiv3/versions_client.go b/dialogflow/cx/apiv3/versions_client.go new file mode 100644 index 00000000000..54c2d00570b --- /dev/null +++ b/dialogflow/cx/apiv3/versions_client.go @@ -0,0 +1,552 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + structpb "github.com/golang/protobuf/ptypes/struct" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newVersionsClientHook clientHook + +// VersionsCallOptions contains the retry settings for each method of VersionsClient. +type VersionsCallOptions struct { + ListVersions []gax.CallOption + GetVersion []gax.CallOption + CreateVersion []gax.CallOption + UpdateVersion []gax.CallOption + DeleteVersion []gax.CallOption + LoadVersion []gax.CallOption +} + +func defaultVersionsClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultVersionsCallOptions() *VersionsCallOptions { + return &VersionsCallOptions{ + ListVersions: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetVersion: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateVersion: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateVersion: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteVersion: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + LoadVersion: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// VersionsClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type VersionsClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + versionsClient cxpb.VersionsClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *VersionsCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewVersionsClient creates a new versions client. +// +// Service for managing Versions. +func NewVersionsClient(ctx context.Context, opts ...option.ClientOption) (*VersionsClient, error) { + clientOpts := defaultVersionsClientOptions() + + if newVersionsClientHook != nil { + hookOpts, err := newVersionsClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &VersionsClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultVersionsCallOptions(), + + versionsClient: cxpb.NewVersionsClient(connPool), + } + c.setGoogleClientInfo() + + c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *VersionsClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *VersionsClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *VersionsClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListVersions returns the list of all versions in the specified Flow. +func (c *VersionsClient) ListVersions(ctx context.Context, req *cxpb.ListVersionsRequest, opts ...gax.CallOption) *VersionIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListVersions[0:len(c.CallOptions.ListVersions):len(c.CallOptions.ListVersions)], opts...) + it := &VersionIterator{} + req = proto.Clone(req).(*cxpb.ListVersionsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Version, string, error) { + var resp *cxpb.ListVersionsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.ListVersions(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetVersions(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetVersion retrieves the specified Version. +func (c *VersionsClient) GetVersion(ctx context.Context, req *cxpb.GetVersionRequest, opts ...gax.CallOption) (*cxpb.Version, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetVersion[0:len(c.CallOptions.GetVersion):len(c.CallOptions.GetVersion)], opts...) + var resp *cxpb.Version + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.GetVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateVersion creates a Version in the specified Flow. +func (c *VersionsClient) CreateVersion(ctx context.Context, req *cxpb.CreateVersionRequest, opts ...gax.CallOption) (*CreateVersionOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateVersion[0:len(c.CallOptions.CreateVersion):len(c.CallOptions.CreateVersion)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.CreateVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateVersionOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// UpdateVersion updates the specified Version. +func (c *VersionsClient) UpdateVersion(ctx context.Context, req *cxpb.UpdateVersionRequest, opts ...gax.CallOption) (*cxpb.Version, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "version.name", url.QueryEscape(req.GetVersion().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateVersion[0:len(c.CallOptions.UpdateVersion):len(c.CallOptions.UpdateVersion)], opts...) + var resp *cxpb.Version + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.UpdateVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteVersion deletes the specified Version. +func (c *VersionsClient) DeleteVersion(ctx context.Context, req *cxpb.DeleteVersionRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteVersion[0:len(c.CallOptions.DeleteVersion):len(c.CallOptions.DeleteVersion)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.versionsClient.DeleteVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// LoadVersion loads a specified version to draft version. +func (c *VersionsClient) LoadVersion(ctx context.Context, req *cxpb.LoadVersionRequest, opts ...gax.CallOption) (*LoadVersionOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.LoadVersion[0:len(c.CallOptions.LoadVersion):len(c.CallOptions.LoadVersion)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.versionsClient.LoadVersion(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &LoadVersionOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// CreateVersionOperation manages a long-running operation from CreateVersion. +type CreateVersionOperation struct { + lro *longrunning.Operation +} + +// CreateVersionOperation returns a new CreateVersionOperation from a given name. +// The name must be that of a previously created CreateVersionOperation, possibly from a different process. +func (c *VersionsClient) CreateVersionOperation(name string) *CreateVersionOperation { + return &CreateVersionOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *CreateVersionOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*cxpb.Version, error) { + var resp cxpb.Version + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *CreateVersionOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*cxpb.Version, error) { + var resp cxpb.Version + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *CreateVersionOperation) Metadata() (*cxpb.CreateVersionOperationMetadata, error) { + var meta cxpb.CreateVersionOperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *CreateVersionOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *CreateVersionOperation) Name() string { + return op.lro.Name() +} + +// LoadVersionOperation manages a long-running operation from LoadVersion. +type LoadVersionOperation struct { + lro *longrunning.Operation +} + +// LoadVersionOperation returns a new LoadVersionOperation from a given name. +// The name must be that of a previously created LoadVersionOperation, possibly from a different process. +func (c *VersionsClient) LoadVersionOperation(name string) *LoadVersionOperation { + return &LoadVersionOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *LoadVersionOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *LoadVersionOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.Poll(ctx, nil, opts...) +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *LoadVersionOperation) Metadata() (*structpb.Struct, error) { + var meta structpb.Struct + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *LoadVersionOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *LoadVersionOperation) Name() string { + return op.lro.Name() +} + +// VersionIterator manages a stream of *cxpb.Version. +type VersionIterator struct { + items []*cxpb.Version + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Version, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *VersionIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *VersionIterator) Next() (*cxpb.Version, error) { + var item *cxpb.Version + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *VersionIterator) bufLen() int { + return len(it.items) +} + +func (it *VersionIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/versions_client_example_test.go b/dialogflow/cx/apiv3/versions_client_example_test.go new file mode 100644 index 00000000000..fe0503014f2 --- /dev/null +++ b/dialogflow/cx/apiv3/versions_client_example_test.go @@ -0,0 +1,166 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewVersionsClient() { + ctx := context.Background() + c, err := cx.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleVersionsClient_ListVersions() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListVersionsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListVersions(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleVersionsClient_GetVersion() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetVersionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVersionsClient_CreateVersion() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateVersionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVersionsClient_UpdateVersion() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateVersionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVersionsClient_DeleteVersion() { + ctx := context.Background() + c, err := cx.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteVersionRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleVersionsClient_LoadVersion() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewVersionsClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.LoadVersionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.LoadVersion(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/dialogflow/cx/apiv3/webhooks_client.go b/dialogflow/cx/apiv3/webhooks_client.go new file mode 100644 index 00000000000..475468a4fdf --- /dev/null +++ b/dialogflow/cx/apiv3/webhooks_client.go @@ -0,0 +1,368 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newWebhooksClientHook clientHook + +// WebhooksCallOptions contains the retry settings for each method of WebhooksClient. +type WebhooksCallOptions struct { + ListWebhooks []gax.CallOption + GetWebhook []gax.CallOption + CreateWebhook []gax.CallOption + UpdateWebhook []gax.CallOption + DeleteWebhook []gax.CallOption +} + +func defaultWebhooksClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultWebhooksCallOptions() *WebhooksCallOptions { + return &WebhooksCallOptions{ + ListWebhooks: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetWebhook: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateWebhook: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + UpdateWebhook: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteWebhook: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + } +} + +// WebhooksClient is a client for interacting with Dialogflow API. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type WebhooksClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + webhooksClient cxpb.WebhooksClient + + // The call options for this service. + CallOptions *WebhooksCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewWebhooksClient creates a new webhooks client. +// +// Service for managing Webhooks. +func NewWebhooksClient(ctx context.Context, opts ...option.ClientOption) (*WebhooksClient, error) { + clientOpts := defaultWebhooksClientOptions() + + if newWebhooksClientHook != nil { + hookOpts, err := newWebhooksClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &WebhooksClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultWebhooksCallOptions(), + + webhooksClient: cxpb.NewWebhooksClient(connPool), + } + c.setGoogleClientInfo() + + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *WebhooksClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *WebhooksClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *WebhooksClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListWebhooks returns the list of all webhooks in the specified agent. +func (c *WebhooksClient) ListWebhooks(ctx context.Context, req *cxpb.ListWebhooksRequest, opts ...gax.CallOption) *WebhookIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListWebhooks[0:len(c.CallOptions.ListWebhooks):len(c.CallOptions.ListWebhooks)], opts...) + it := &WebhookIterator{} + req = proto.Clone(req).(*cxpb.ListWebhooksRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.Webhook, string, error) { + var resp *cxpb.ListWebhooksResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.webhooksClient.ListWebhooks(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetWebhooks(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetWebhook retrieves the specified webhook. +func (c *WebhooksClient) GetWebhook(ctx context.Context, req *cxpb.GetWebhookRequest, opts ...gax.CallOption) (*cxpb.Webhook, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetWebhook[0:len(c.CallOptions.GetWebhook):len(c.CallOptions.GetWebhook)], opts...) + var resp *cxpb.Webhook + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.webhooksClient.GetWebhook(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateWebhook creates a webhook in the specified agent. +func (c *WebhooksClient) CreateWebhook(ctx context.Context, req *cxpb.CreateWebhookRequest, opts ...gax.CallOption) (*cxpb.Webhook, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateWebhook[0:len(c.CallOptions.CreateWebhook):len(c.CallOptions.CreateWebhook)], opts...) + var resp *cxpb.Webhook + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.webhooksClient.CreateWebhook(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// UpdateWebhook updates the specified webhook. +func (c *WebhooksClient) UpdateWebhook(ctx context.Context, req *cxpb.UpdateWebhookRequest, opts ...gax.CallOption) (*cxpb.Webhook, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "webhook.name", url.QueryEscape(req.GetWebhook().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UpdateWebhook[0:len(c.CallOptions.UpdateWebhook):len(c.CallOptions.UpdateWebhook)], opts...) + var resp *cxpb.Webhook + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.webhooksClient.UpdateWebhook(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// DeleteWebhook deletes the specified webhook. +func (c *WebhooksClient) DeleteWebhook(ctx context.Context, req *cxpb.DeleteWebhookRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteWebhook[0:len(c.CallOptions.DeleteWebhook):len(c.CallOptions.DeleteWebhook)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.webhooksClient.DeleteWebhook(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// WebhookIterator manages a stream of *cxpb.Webhook. +type WebhookIterator struct { + items []*cxpb.Webhook + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*cxpb.Webhook, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *WebhookIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *WebhookIterator) Next() (*cxpb.Webhook, error) { + var item *cxpb.Webhook + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *WebhookIterator) bufLen() int { + return len(it.items) +} + +func (it *WebhookIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dialogflow/cx/apiv3/webhooks_client_example_test.go b/dialogflow/cx/apiv3/webhooks_client_example_test.go new file mode 100644 index 00000000000..930bc1d3ee5 --- /dev/null +++ b/dialogflow/cx/apiv3/webhooks_client_example_test.go @@ -0,0 +1,138 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package cx_test + +import ( + "context" + + cx "cloud.google.com/go/dialogflow/cx/apiv3" + "google.golang.org/api/iterator" + cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" +) + +func ExampleNewWebhooksClient() { + ctx := context.Background() + c, err := cx.NewWebhooksClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleWebhooksClient_ListWebhooks() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := cx.NewWebhooksClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.ListWebhooksRequest{ + // TODO: Fill request struct fields. + } + it := c.ListWebhooks(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleWebhooksClient_GetWebhook() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewWebhooksClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.GetWebhookRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetWebhook(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleWebhooksClient_CreateWebhook() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewWebhooksClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.CreateWebhookRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateWebhook(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleWebhooksClient_UpdateWebhook() { + // import cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3" + + ctx := context.Background() + c, err := cx.NewWebhooksClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.UpdateWebhookRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateWebhook(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleWebhooksClient_DeleteWebhook() { + ctx := context.Background() + c, err := cx.NewWebhooksClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &cxpb.DeleteWebhookRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteWebhook(ctx, req) + if err != nil { + // TODO: Handle error. + } +} diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 08789a0384c..41a05898fc9 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -359,6 +359,14 @@ "docs_url": "https://pkg.go.dev/cloud.google.com/go/dialogflow/apiv2", "release_level": "ga" }, + "cloud.google.com/go/dialogflow/cx/apiv3": { + "distribution_name": "cloud.google.com/go/dialogflow/cx/apiv3", + "description": "Dialogflow API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://pkg.go.dev/cloud.google.com/go/dialogflow/cx/apiv3", + "release_level": "beta" + }, "cloud.google.com/go/dialogflow/cx/apiv3beta1": { "distribution_name": "cloud.google.com/go/dialogflow/cx/apiv3beta1", "description": "Dialogflow API", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 7220c6903c9..b40e70614a2 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -570,6 +570,15 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/cloud/dialogflow/cx/v3beta1/dialogflow_v3beta1.yaml", releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/dialogflow/cx/v3", + pkg: "cx", + importPath: "cloud.google.com/go/dialogflow/cx/apiv3", + gRPCServiceConfigPath: "google/cloud/dialogflow/cx/v3/dialogflow_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/dialogflow/cx/v3/dialogflow_v3.yaml", + // GA after 2021/04/23 + releaseLevel: "beta", + }, { inputDirectoryPath: "google/cloud/dialogflow/v2", pkg: "dialogflow",