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.
 
 
 

145 lines
5.4 KiB

  1. // Copyright 2018 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package dialogflow
  16. import (
  17. "cloud.google.com/go/internal/version"
  18. gax "github.com/googleapis/gax-go"
  19. "golang.org/x/net/context"
  20. "google.golang.org/api/option"
  21. "google.golang.org/api/transport"
  22. dialogflowpb "google.golang.org/genproto/googleapis/cloud/dialogflow/v2"
  23. "google.golang.org/grpc"
  24. "google.golang.org/grpc/metadata"
  25. )
  26. // SessionsCallOptions contains the retry settings for each method of SessionsClient.
  27. type SessionsCallOptions struct {
  28. DetectIntent []gax.CallOption
  29. StreamingDetectIntent []gax.CallOption
  30. }
  31. func defaultSessionsClientOptions() []option.ClientOption {
  32. return []option.ClientOption{
  33. option.WithEndpoint("dialogflow.googleapis.com:443"),
  34. option.WithScopes(DefaultAuthScopes()...),
  35. }
  36. }
  37. func defaultSessionsCallOptions() *SessionsCallOptions {
  38. retry := map[[2]string][]gax.CallOption{}
  39. return &SessionsCallOptions{
  40. DetectIntent: retry[[2]string{"default", "non_idempotent"}],
  41. StreamingDetectIntent: retry[[2]string{"default", "non_idempotent"}],
  42. }
  43. }
  44. // SessionsClient is a client for interacting with Dialogflow API.
  45. //
  46. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  47. type SessionsClient struct {
  48. // The connection to the service.
  49. conn *grpc.ClientConn
  50. // The gRPC API client.
  51. sessionsClient dialogflowpb.SessionsClient
  52. // The call options for this service.
  53. CallOptions *SessionsCallOptions
  54. // The x-goog-* metadata to be sent with each request.
  55. xGoogMetadata metadata.MD
  56. }
  57. // NewSessionsClient creates a new sessions client.
  58. //
  59. // A session represents an interaction with a user. You retrieve user input
  60. // and pass it to the [DetectIntent][google.cloud.dialogflow.v2.Sessions.DetectIntent] (or
  61. // [StreamingDetectIntent][google.cloud.dialogflow.v2.Sessions.StreamingDetectIntent]) method to determine
  62. // 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", version.Go()}, keyval...)
  90. kv = append(kv, "gapic", version.Repo, "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. }