1// Copyright 2020 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17package dialogflow 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 "github.com/golang/protobuf/proto" 27 gax "github.com/googleapis/gax-go/v2" 28 "google.golang.org/api/iterator" 29 "google.golang.org/api/option" 30 "google.golang.org/api/transport" 31 dialogflowpb "google.golang.org/genproto/googleapis/cloud/dialogflow/v2" 32 "google.golang.org/grpc" 33 "google.golang.org/grpc/codes" 34 "google.golang.org/grpc/metadata" 35) 36 37// SessionEntityTypesCallOptions contains the retry settings for each method of SessionEntityTypesClient. 38type SessionEntityTypesCallOptions struct { 39 ListSessionEntityTypes []gax.CallOption 40 GetSessionEntityType []gax.CallOption 41 CreateSessionEntityType []gax.CallOption 42 UpdateSessionEntityType []gax.CallOption 43 DeleteSessionEntityType []gax.CallOption 44} 45 46func defaultSessionEntityTypesClientOptions() []option.ClientOption { 47 return []option.ClientOption{ 48 option.WithEndpoint("dialogflow.googleapis.com:443"), 49 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 50 option.WithScopes(DefaultAuthScopes()...), 51 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 52 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 53 } 54} 55 56func defaultSessionEntityTypesCallOptions() *SessionEntityTypesCallOptions { 57 return &SessionEntityTypesCallOptions{ 58 ListSessionEntityTypes: []gax.CallOption{ 59 gax.WithRetry(func() gax.Retryer { 60 return gax.OnCodes([]codes.Code{ 61 codes.Unavailable, 62 codes.DeadlineExceeded, 63 }, gax.Backoff{ 64 Initial: 100 * time.Millisecond, 65 Max: 60000 * time.Millisecond, 66 Multiplier: 1.30, 67 }) 68 }), 69 }, 70 GetSessionEntityType: []gax.CallOption{ 71 gax.WithRetry(func() gax.Retryer { 72 return gax.OnCodes([]codes.Code{ 73 codes.Unavailable, 74 codes.DeadlineExceeded, 75 }, gax.Backoff{ 76 Initial: 100 * time.Millisecond, 77 Max: 60000 * time.Millisecond, 78 Multiplier: 1.30, 79 }) 80 }), 81 }, 82 CreateSessionEntityType: []gax.CallOption{}, 83 UpdateSessionEntityType: []gax.CallOption{}, 84 DeleteSessionEntityType: []gax.CallOption{ 85 gax.WithRetry(func() gax.Retryer { 86 return gax.OnCodes([]codes.Code{ 87 codes.Unavailable, 88 codes.DeadlineExceeded, 89 }, gax.Backoff{ 90 Initial: 100 * time.Millisecond, 91 Max: 60000 * time.Millisecond, 92 Multiplier: 1.30, 93 }) 94 }), 95 }, 96 } 97} 98 99// SessionEntityTypesClient is a client for interacting with Dialogflow API. 100// 101// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 102type SessionEntityTypesClient struct { 103 // The connection to the service. 104 conn *grpc.ClientConn 105 106 // The gRPC API client. 107 sessionEntityTypesClient dialogflowpb.SessionEntityTypesClient 108 109 // The call options for this service. 110 CallOptions *SessionEntityTypesCallOptions 111 112 // The x-goog-* metadata to be sent with each request. 113 xGoogMetadata metadata.MD 114} 115 116// NewSessionEntityTypesClient creates a new session entity types client. 117// 118// Entities are extracted from user input and represent parameters that are 119// meaningful to your application. For example, a date range, a proper name 120// such as a geographic location or landmark, and so on. Entities represent 121// actionable data for your application. 122// 123// Session entity types are referred to as User entity types and are 124// entities that are built for an individual user such as 125// favorites, preferences, playlists, and so on. You can redefine a session 126// entity type at the session level. 127// 128// Session entity methods do not work with Google Assistant integration. 129// Contact Dialogflow support if you need to use session entities 130// with Google Assistant integration. 131// 132// For more information about entity types, see the 133// Dialogflow 134// documentation (at https://cloud.google.com/dialogflow/docs/entities-overview). 135func NewSessionEntityTypesClient(ctx context.Context, opts ...option.ClientOption) (*SessionEntityTypesClient, error) { 136 conn, err := transport.DialGRPC(ctx, append(defaultSessionEntityTypesClientOptions(), opts...)...) 137 if err != nil { 138 return nil, err 139 } 140 c := &SessionEntityTypesClient{ 141 conn: conn, 142 CallOptions: defaultSessionEntityTypesCallOptions(), 143 144 sessionEntityTypesClient: dialogflowpb.NewSessionEntityTypesClient(conn), 145 } 146 c.setGoogleClientInfo() 147 148 return c, nil 149} 150 151// Connection returns the client's connection to the API service. 152func (c *SessionEntityTypesClient) Connection() *grpc.ClientConn { 153 return c.conn 154} 155 156// Close closes the connection to the API service. The user should invoke this when 157// the client is no longer required. 158func (c *SessionEntityTypesClient) Close() error { 159 return c.conn.Close() 160} 161 162// setGoogleClientInfo sets the name and version of the application in 163// the `x-goog-api-client` header passed on each request. Intended for 164// use by Google-written clients. 165func (c *SessionEntityTypesClient) setGoogleClientInfo(keyval ...string) { 166 kv := append([]string{"gl-go", versionGo()}, keyval...) 167 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 168 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 169} 170 171// ListSessionEntityTypes returns the list of all session entity types in the specified session. 172// 173// This method doesn’t work with Google Assistant integration. 174// Contact Dialogflow support if you need to use session entities 175// with Google Assistant integration. 176func (c *SessionEntityTypesClient) ListSessionEntityTypes(ctx context.Context, req *dialogflowpb.ListSessionEntityTypesRequest, opts ...gax.CallOption) *SessionEntityTypeIterator { 177 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 178 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 179 opts = append(c.CallOptions.ListSessionEntityTypes[0:len(c.CallOptions.ListSessionEntityTypes):len(c.CallOptions.ListSessionEntityTypes)], opts...) 180 it := &SessionEntityTypeIterator{} 181 req = proto.Clone(req).(*dialogflowpb.ListSessionEntityTypesRequest) 182 it.InternalFetch = func(pageSize int, pageToken string) ([]*dialogflowpb.SessionEntityType, string, error) { 183 var resp *dialogflowpb.ListSessionEntityTypesResponse 184 req.PageToken = pageToken 185 if pageSize > math.MaxInt32 { 186 req.PageSize = math.MaxInt32 187 } else { 188 req.PageSize = int32(pageSize) 189 } 190 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 191 var err error 192 resp, err = c.sessionEntityTypesClient.ListSessionEntityTypes(ctx, req, settings.GRPC...) 193 return err 194 }, opts...) 195 if err != nil { 196 return nil, "", err 197 } 198 199 it.Response = resp 200 return resp.SessionEntityTypes, resp.NextPageToken, nil 201 } 202 fetch := func(pageSize int, pageToken string) (string, error) { 203 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 204 if err != nil { 205 return "", err 206 } 207 it.items = append(it.items, items...) 208 return nextPageToken, nil 209 } 210 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 211 it.pageInfo.MaxSize = int(req.PageSize) 212 it.pageInfo.Token = req.PageToken 213 return it 214} 215 216// GetSessionEntityType retrieves the specified session entity type. 217// 218// This method doesn’t work with Google Assistant integration. 219// Contact Dialogflow support if you need to use session entities 220// with Google Assistant integration. 221func (c *SessionEntityTypesClient) GetSessionEntityType(ctx context.Context, req *dialogflowpb.GetSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) { 222 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 223 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 224 opts = append(c.CallOptions.GetSessionEntityType[0:len(c.CallOptions.GetSessionEntityType):len(c.CallOptions.GetSessionEntityType)], opts...) 225 var resp *dialogflowpb.SessionEntityType 226 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 227 var err error 228 resp, err = c.sessionEntityTypesClient.GetSessionEntityType(ctx, req, settings.GRPC...) 229 return err 230 }, opts...) 231 if err != nil { 232 return nil, err 233 } 234 return resp, nil 235} 236 237// CreateSessionEntityType creates a session entity type. 238// 239// If the specified session entity type already exists, overrides the session 240// entity type. 241// 242// This method doesn’t work with Google Assistant integration. 243// Contact Dialogflow support if you need to use session entities 244// with Google Assistant integration. 245func (c *SessionEntityTypesClient) CreateSessionEntityType(ctx context.Context, req *dialogflowpb.CreateSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) { 246 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 247 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 248 opts = append(c.CallOptions.CreateSessionEntityType[0:len(c.CallOptions.CreateSessionEntityType):len(c.CallOptions.CreateSessionEntityType)], opts...) 249 var resp *dialogflowpb.SessionEntityType 250 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 251 var err error 252 resp, err = c.sessionEntityTypesClient.CreateSessionEntityType(ctx, req, settings.GRPC...) 253 return err 254 }, opts...) 255 if err != nil { 256 return nil, err 257 } 258 return resp, nil 259} 260 261// UpdateSessionEntityType updates the specified session entity type. 262// 263// This method doesn’t work with Google Assistant integration. 264// Contact Dialogflow support if you need to use session entities 265// with Google Assistant integration. 266func (c *SessionEntityTypesClient) UpdateSessionEntityType(ctx context.Context, req *dialogflowpb.UpdateSessionEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.SessionEntityType, error) { 267 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "session_entity_type.name", url.QueryEscape(req.GetSessionEntityType().GetName()))) 268 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 269 opts = append(c.CallOptions.UpdateSessionEntityType[0:len(c.CallOptions.UpdateSessionEntityType):len(c.CallOptions.UpdateSessionEntityType)], opts...) 270 var resp *dialogflowpb.SessionEntityType 271 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 272 var err error 273 resp, err = c.sessionEntityTypesClient.UpdateSessionEntityType(ctx, req, settings.GRPC...) 274 return err 275 }, opts...) 276 if err != nil { 277 return nil, err 278 } 279 return resp, nil 280} 281 282// DeleteSessionEntityType deletes the specified session entity type. 283// 284// This method doesn’t work with Google Assistant integration. 285// Contact Dialogflow support if you need to use session entities 286// with Google Assistant integration. 287func (c *SessionEntityTypesClient) DeleteSessionEntityType(ctx context.Context, req *dialogflowpb.DeleteSessionEntityTypeRequest, opts ...gax.CallOption) error { 288 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 289 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 290 opts = append(c.CallOptions.DeleteSessionEntityType[0:len(c.CallOptions.DeleteSessionEntityType):len(c.CallOptions.DeleteSessionEntityType)], opts...) 291 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 292 var err error 293 _, err = c.sessionEntityTypesClient.DeleteSessionEntityType(ctx, req, settings.GRPC...) 294 return err 295 }, opts...) 296 return err 297} 298 299// SessionEntityTypeIterator manages a stream of *dialogflowpb.SessionEntityType. 300type SessionEntityTypeIterator struct { 301 items []*dialogflowpb.SessionEntityType 302 pageInfo *iterator.PageInfo 303 nextFunc func() error 304 305 // Response is the raw response for the current page. 306 // It must be cast to the RPC response type. 307 // Calling Next() or InternalFetch() updates this value. 308 Response interface{} 309 310 // InternalFetch is for use by the Google Cloud Libraries only. 311 // It is not part of the stable interface of this package. 312 // 313 // InternalFetch returns results from a single call to the underlying RPC. 314 // The number of results is no greater than pageSize. 315 // If there are no more results, nextPageToken is empty and err is nil. 316 InternalFetch func(pageSize int, pageToken string) (results []*dialogflowpb.SessionEntityType, nextPageToken string, err error) 317} 318 319// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 320func (it *SessionEntityTypeIterator) PageInfo() *iterator.PageInfo { 321 return it.pageInfo 322} 323 324// Next returns the next result. Its second return value is iterator.Done if there are no more 325// results. Once Next returns Done, all subsequent calls will return Done. 326func (it *SessionEntityTypeIterator) Next() (*dialogflowpb.SessionEntityType, error) { 327 var item *dialogflowpb.SessionEntityType 328 if err := it.nextFunc(); err != nil { 329 return item, err 330 } 331 item = it.items[0] 332 it.items = it.items[1:] 333 return item, nil 334} 335 336func (it *SessionEntityTypeIterator) bufLen() int { 337 return len(it.items) 338} 339 340func (it *SessionEntityTypeIterator) takeBuf() interface{} { 341 b := it.items 342 it.items = nil 343 return b 344} 345