You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

146 lines
5.3 KiB

  1. // Copyright 2019 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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package dialogflow
  16. import (
  17. "context"
  18. gax "github.com/googleapis/gax-go/v2"
  19. "google.golang.org/api/option"
  20. "google.golang.org/api/transport"
  21. dialogflowpb "google.golang.org/genproto/googleapis/cloud/dialogflow/v2"
  22. "google.golang.org/grpc"
  23. "google.golang.org/grpc/metadata"
  24. )
  25. // SessionsCallOptions contains the retry settings for each method of SessionsClient.
  26. type SessionsCallOptions struct {
  27. DetectIntent []gax.CallOption
  28. StreamingDetectIntent []gax.CallOption
  29. }
  30. func defaultSessionsClientOptions() []option.ClientOption {
  31. return []option.ClientOption{
  32. option.WithEndpoint("dialogflow.googleapis.com:443"),
  33. option.WithScopes(DefaultAuthScopes()...),
  34. }
  35. }
  36. func defaultSessionsCallOptions() *SessionsCallOptions {
  37. retry := map[[2]string][]gax.CallOption{}
  38. return &SessionsCallOptions{
  39. DetectIntent: retry[[2]string{"default", "non_idempotent"}],
  40. StreamingDetectIntent: retry[[2]string{"default", "non_idempotent"}],
  41. }
  42. }
  43. // SessionsClient is a client for interacting with Dialogflow API.
  44. //
  45. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  46. type SessionsClient struct {
  47. // The connection to the service.
  48. conn *grpc.ClientConn
  49. // The gRPC API client.
  50. sessionsClient dialogflowpb.SessionsClient
  51. // The call options for this service.
  52. CallOptions *SessionsCallOptions
  53. // The x-goog-* metadata to be sent with each request.
  54. xGoogMetadata metadata.MD
  55. }
  56. // NewSessionsClient creates a new sessions client.
  57. //
  58. // A session represents an interaction with a user. You retrieve user input
  59. // and pass it to the
  60. // [DetectIntent][google.cloud.dialogflow.v2.Sessions.DetectIntent] (or
  61. // [StreamingDetectIntent][google.cloud.dialogflow.v2.Sessions.StreamingDetectIntent])
  62. // method to determine user intent and respond.
  63. func NewSessionsClient(ctx context.Context, opts ...option.ClientOption) (*SessionsClient, error) {
  64. conn, err := transport.DialGRPC(ctx, append(defaultSessionsClientOptions(), opts...)...)
  65. if err != nil {
  66. return nil, err
  67. }
  68. c := &SessionsClient{
  69. conn: conn,
  70. CallOptions: defaultSessionsCallOptions(),
  71. sessionsClient: dialogflowpb.NewSessionsClient(conn),
  72. }
  73. c.setGoogleClientInfo()
  74. return c, nil
  75. }
  76. // Connection returns the client's connection to the API service.
  77. func (c *SessionsClient) Connection() *grpc.ClientConn {
  78. return c.conn
  79. }
  80. // Close closes the connection to the API service. The user should invoke this when
  81. // the client is no longer required.
  82. func (c *SessionsClient) Close() error {
  83. return c.conn.Close()
  84. }
  85. // setGoogleClientInfo sets the name and version of the application in
  86. // the `x-goog-api-client` header passed on each request. Intended for
  87. // use by Google-written clients.
  88. func (c *SessionsClient) setGoogleClientInfo(keyval ...string) {
  89. kv := append([]string{"gl-go", versionGo()}, keyval...)
  90. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  91. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  92. }
  93. // DetectIntent processes a natural language query and returns structured, actionable data
  94. // as a result. This method is not idempotent, because it may cause contexts
  95. // and session entity types to be updated, which in turn might affect
  96. // results of future queries.
  97. func (c *SessionsClient) DetectIntent(ctx context.Context, req *dialogflowpb.DetectIntentRequest, opts ...gax.CallOption) (*dialogflowpb.DetectIntentResponse, error) {
  98. ctx = insertMetadata(ctx, c.xGoogMetadata)
  99. opts = append(c.CallOptions.DetectIntent[0:len(c.CallOptions.DetectIntent):len(c.CallOptions.DetectIntent)], opts...)
  100. var resp *dialogflowpb.DetectIntentResponse
  101. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  102. var err error
  103. resp, err = c.sessionsClient.DetectIntent(ctx, req, settings.GRPC...)
  104. return err
  105. }, opts...)
  106. if err != nil {
  107. return nil, err
  108. }
  109. return resp, nil
  110. }
  111. // StreamingDetectIntent processes a natural language query in audio format in a streaming fashion
  112. // and returns structured, actionable data as a result. This method is only
  113. // available via the gRPC API (not REST).
  114. func (c *SessionsClient) StreamingDetectIntent(ctx context.Context, opts ...gax.CallOption) (dialogflowpb.Sessions_StreamingDetectIntentClient, error) {
  115. ctx = insertMetadata(ctx, c.xGoogMetadata)
  116. opts = append(c.CallOptions.StreamingDetectIntent[0:len(c.CallOptions.StreamingDetectIntent):len(c.CallOptions.StreamingDetectIntent)], opts...)
  117. var resp dialogflowpb.Sessions_StreamingDetectIntentClient
  118. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  119. var err error
  120. resp, err = c.sessionsClient.StreamingDetectIntent(ctx, settings.GRPC...)
  121. return err
  122. }, opts...)
  123. if err != nil {
  124. return nil, err
  125. }
  126. return resp, nil
  127. }