Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / dialogflow / src / v2beta1 / intents_client.js
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
15 'use strict';
16
17 const gapicConfig = require('./intents_client_config.json');
18 const gax = require('google-gax');
19 const merge = require('lodash.merge');
20 const path = require('path');
21 const protobuf = require('protobufjs');
22
23 const VERSION = require('../../package.json').version;
24
25 /**
26  * An intent represents a mapping between input from a user and an action to
27  * be taken by your application. When you pass user input to the
28  * DetectIntent (or
29  * StreamingDetectIntent)
30  * method, the Dialogflow API analyzes the input and searches for a matching
31  * intent. If no match is found, the Dialogflow API returns a fallback intent
32  * (`is_fallback` = true).
33  *
34  * You can provide additional information for the Dialogflow API to use to
35  * match user input to an intent by adding the following to your intent.
36  *
37  * *   **Contexts** - provide additional context for intent analysis. For
38  *     example, if an intent is related to an object in your application that
39  *     plays music, you can provide a context to determine when to match the
40  *     intent if the user input is “turn it off”.  You can include a context
41  *     that matches the intent when there is previous user input of
42  *     "play music", and not when there is previous user input of
43  *     "turn on the light".
44  *
45  * *   **Events** - allow for matching an intent by using an event name
46  *     instead of user input. Your application can provide an event name and
47  *     related parameters to the Dialogflow API to match an intent. For
48  *     example, when your application starts, you can send a welcome event
49  *     with a user name parameter to the Dialogflow API to match an intent with
50  *     a personalized welcome message for the user.
51  *
52  * *   **Training phrases** - provide examples of user input to train the
53  *     Dialogflow API agent to better match intents.
54  *
55  * For more information about intents, see the
56  * [Dialogflow documentation](https://dialogflow.com/docs/intents).
57  *
58  * @class
59  * @memberof v2beta1
60  */
61 class IntentsClient {
62   /**
63    * Construct an instance of IntentsClient.
64    *
65    * @param {object} [options] - The configuration object. See the subsequent
66    *   parameters for more details.
67    * @param {object} [options.credentials] - Credentials object.
68    * @param {string} [options.credentials.client_email]
69    * @param {string} [options.credentials.private_key]
70    * @param {string} [options.email] - Account email address. Required when
71    *     using a .pem or .p12 keyFilename.
72    * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
73    *     .p12 key downloaded from the Google Developers Console. If you provide
74    *     a path to a JSON file, the projectId option below is not necessary.
75    *     NOTE: .pem and .p12 require you to specify options.email as well.
76    * @param {number} [options.port] - The port on which to connect to
77    *     the remote host.
78    * @param {string} [options.projectId] - The project ID from the Google
79    *     Developer's Console, e.g. 'grape-spaceship-123'. We will also check
80    *     the environment variable GCLOUD_PROJECT for your project ID. If your
81    *     app is running in an environment which supports
82    *     {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
83    *     your project ID will be detected automatically.
84    * @param {function} [options.promise] - Custom promise module to use instead
85    *     of native Promises.
86    * @param {string} [options.servicePath] - The domain name of the
87    *     API remote host.
88    */
89   constructor(opts) {
90     this._descriptors = {};
91
92     // Ensure that options include the service address and port.
93     opts = Object.assign(
94       {
95         clientConfig: {},
96         port: this.constructor.port,
97         servicePath: this.constructor.servicePath,
98       },
99       opts
100     );
101
102     // Create a `gaxGrpc` object, with any grpc-specific options
103     // sent to the client.
104     opts.scopes = this.constructor.scopes;
105     const gaxGrpc = new gax.GrpcClient(opts);
106
107     // Save the auth object to the client, for use by other methods.
108     this.auth = gaxGrpc.auth;
109
110     // Determine the client header string.
111     const clientHeader = [
112       `gl-node/${process.version}`,
113       `grpc/${gaxGrpc.grpcVersion}`,
114       `gax/${gax.version}`,
115       `gapic/${VERSION}`,
116     ];
117     if (opts.libName && opts.libVersion) {
118       clientHeader.push(`${opts.libName}/${opts.libVersion}`);
119     }
120
121     // Load the applicable protos.
122     const protos = merge(
123       {},
124       gaxGrpc.loadProto(
125         path.join(__dirname, '..', '..', 'protos'),
126         'google/cloud/dialogflow/v2beta1/intent.proto'
127       )
128     );
129
130     // This API contains "path templates"; forward-slash-separated
131     // identifiers to uniquely identify resources within the API.
132     // Create useful helper objects for these.
133     this._pathTemplates = {
134       projectAgentPathTemplate: new gax.PathTemplate(
135         'projects/{project}/agent'
136       ),
137       intentPathTemplate: new gax.PathTemplate(
138         'projects/{project}/agent/intents/{intent}'
139       ),
140     };
141
142     // Some of the methods on this service return "paged" results,
143     // (e.g. 50 results at a time, with tokens to get subsequent
144     // pages). Denote the keys used for pagination and results.
145     this._descriptors.page = {
146       listIntents: new gax.PageDescriptor(
147         'pageToken',
148         'nextPageToken',
149         'intents'
150       ),
151     };
152     let protoFilesRoot = new gax.GoogleProtoFilesRoot();
153     protoFilesRoot = protobuf.loadSync(
154       path.join(
155         __dirname,
156         '..',
157         '..',
158         'protos',
159         'google/cloud/dialogflow/v2beta1/intent.proto'
160       ),
161       protoFilesRoot
162     );
163
164     // This API contains "long-running operations", which return a
165     // an Operation object that allows for tracking of the operation,
166     // rather than holding a request open.
167     this.operationsClient = new gax.lro({
168       auth: gaxGrpc.auth,
169       grpc: gaxGrpc.grpc,
170     }).operationsClient(opts);
171
172     const batchUpdateIntentsResponse = protoFilesRoot.lookup(
173       'google.cloud.dialogflow.v2beta1.BatchUpdateIntentsResponse'
174     );
175     const batchUpdateIntentsMetadata = protoFilesRoot.lookup(
176       'google.protobuf.Struct'
177     );
178     const batchDeleteIntentsResponse = protoFilesRoot.lookup(
179       'google.protobuf.Empty'
180     );
181     const batchDeleteIntentsMetadata = protoFilesRoot.lookup(
182       'google.protobuf.Struct'
183     );
184
185     this._descriptors.longrunning = {
186       batchUpdateIntents: new gax.LongrunningDescriptor(
187         this.operationsClient,
188         batchUpdateIntentsResponse.decode.bind(batchUpdateIntentsResponse),
189         batchUpdateIntentsMetadata.decode.bind(batchUpdateIntentsMetadata)
190       ),
191       batchDeleteIntents: new gax.LongrunningDescriptor(
192         this.operationsClient,
193         batchDeleteIntentsResponse.decode.bind(batchDeleteIntentsResponse),
194         batchDeleteIntentsMetadata.decode.bind(batchDeleteIntentsMetadata)
195       ),
196     };
197
198     // Put together the default options sent with requests.
199     const defaults = gaxGrpc.constructSettings(
200       'google.cloud.dialogflow.v2beta1.Intents',
201       gapicConfig,
202       opts.clientConfig,
203       {'x-goog-api-client': clientHeader.join(' ')}
204     );
205
206     // Set up a dictionary of "inner API calls"; the core implementation
207     // of calling the API is handled in `google-gax`, with this code
208     // merely providing the destination and request information.
209     this._innerApiCalls = {};
210
211     // Put together the "service stub" for
212     // google.cloud.dialogflow.v2beta1.Intents.
213     const intentsStub = gaxGrpc.createStub(
214       protos.google.cloud.dialogflow.v2beta1.Intents,
215       opts
216     );
217
218     // Iterate over each of the methods that the service provides
219     // and create an API call method for each.
220     const intentsStubMethods = [
221       'listIntents',
222       'getIntent',
223       'createIntent',
224       'updateIntent',
225       'deleteIntent',
226       'batchUpdateIntents',
227       'batchDeleteIntents',
228     ];
229     for (const methodName of intentsStubMethods) {
230       this._innerApiCalls[methodName] = gax.createApiCall(
231         intentsStub.then(
232           stub =>
233             function() {
234               const args = Array.prototype.slice.call(arguments, 0);
235               return stub[methodName].apply(stub, args);
236             },
237           err =>
238             function() {
239               throw err;
240             }
241         ),
242         defaults[methodName],
243         this._descriptors.page[methodName] ||
244           this._descriptors.longrunning[methodName]
245       );
246     }
247   }
248
249   /**
250    * The DNS address for this API service.
251    */
252   static get servicePath() {
253     return 'dialogflow.googleapis.com';
254   }
255
256   /**
257    * The port for this API service.
258    */
259   static get port() {
260     return 443;
261   }
262
263   /**
264    * The scopes needed to make gRPC calls for every method defined
265    * in this service.
266    */
267   static get scopes() {
268     return ['https://www.googleapis.com/auth/cloud-platform'];
269   }
270
271   /**
272    * Return the project ID used by this class.
273    * @param {function(Error, string)} callback - the callback to
274    *   be called with the current project Id.
275    */
276   getProjectId(callback) {
277     return this.auth.getProjectId(callback);
278   }
279
280   // -------------------
281   // -- Service calls --
282   // -------------------
283
284   /**
285    * Returns the list of all intents in the specified agent.
286    *
287    * @param {Object} request
288    *   The request object that will be sent.
289    * @param {string} request.parent
290    *   Required. The agent to list all intents from.
291    *   Format: `projects/<Project ID>/agent`.
292    * @param {string} [request.languageCode]
293    *   Optional. The language to list training phrases, parameters and rich
294    *   messages for. If not specified, the agent's default language is used.
295    *   [More than a dozen
296    *   languages](https://dialogflow.com/docs/reference/language) are supported.
297    *   Note: languages must be enabled in the agent before they can be used.
298    * @param {number} [request.intentView]
299    *   Optional. The resource view to apply to the returned intent.
300    *
301    *   The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
302    * @param {number} [request.pageSize]
303    *   The maximum number of resources contained in the underlying API
304    *   response. If page streaming is performed per-resource, this
305    *   parameter does not affect the return value. If page streaming is
306    *   performed per-page, this determines the maximum number of
307    *   resources in a page.
308    * @param {Object} [options]
309    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
310    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
311    * @param {function(?Error, ?Array, ?Object, ?Object)} [callback]
312    *   The function which will be called with the result of the API call.
313    *
314    *   The second parameter to the callback is Array of [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
315    *
316    *   When autoPaginate: false is specified through options, it contains the result
317    *   in a single response. If the response indicates the next page exists, the third
318    *   parameter is set to be used for the next request object. The fourth parameter keeps
319    *   the raw response object of an object representing [ListIntentsResponse]{@link google.cloud.dialogflow.v2beta1.ListIntentsResponse}.
320    * @returns {Promise} - The promise which resolves to an array.
321    *   The first element of the array is Array of [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
322    *
323    *   When autoPaginate: false is specified through options, the array has three elements.
324    *   The first element is Array of [Intent]{@link google.cloud.dialogflow.v2beta1.Intent} in a single response.
325    *   The second element is the next request object if the response
326    *   indicates the next page exists, or null. The third element is
327    *   an object representing [ListIntentsResponse]{@link google.cloud.dialogflow.v2beta1.ListIntentsResponse}.
328    *
329    *   The promise has a method named "cancel" which cancels the ongoing API call.
330    *
331    * @example
332    *
333    * const dialogflow = require('dialogflow');
334    *
335    * const client = new dialogflow.v2beta1.IntentsClient({
336    *   // optional auth parameters.
337    * });
338    *
339    * // Iterate over all elements.
340    * const formattedParent = client.projectAgentPath('[PROJECT]');
341    *
342    * client.listIntents({parent: formattedParent})
343    *   .then(responses => {
344    *     const resources = responses[0];
345    *     for (const resource of resources) {
346    *       // doThingsWith(resource)
347    *     }
348    *   })
349    *   .catch(err => {
350    *     console.error(err);
351    *   });
352    *
353    * // Or obtain the paged response.
354    * const formattedParent = client.projectAgentPath('[PROJECT]');
355    *
356    *
357    * const options = {autoPaginate: false};
358    * const callback = responses => {
359    *   // The actual resources in a response.
360    *   const resources = responses[0];
361    *   // The next request if the response shows that there are more responses.
362    *   const nextRequest = responses[1];
363    *   // The actual response object, if necessary.
364    *   // const rawResponse = responses[2];
365    *   for (const resource of resources) {
366    *     // doThingsWith(resource);
367    *   }
368    *   if (nextRequest) {
369    *     // Fetch the next page.
370    *     return client.listIntents(nextRequest, options).then(callback);
371    *   }
372    * }
373    * client.listIntents({parent: formattedParent}, options)
374    *   .then(callback)
375    *   .catch(err => {
376    *     console.error(err);
377    *   });
378    */
379   listIntents(request, options, callback) {
380     if (options instanceof Function && callback === undefined) {
381       callback = options;
382       options = {};
383     }
384     options = options || {};
385
386     return this._innerApiCalls.listIntents(request, options, callback);
387   }
388
389   /**
390    * Equivalent to {@link listIntents}, but returns a NodeJS Stream object.
391    *
392    * This fetches the paged responses for {@link listIntents} continuously
393    * and invokes the callback registered for 'data' event for each element in the
394    * responses.
395    *
396    * The returned object has 'end' method when no more elements are required.
397    *
398    * autoPaginate option will be ignored.
399    *
400    * @see {@link https://nodejs.org/api/stream.html}
401    *
402    * @param {Object} request
403    *   The request object that will be sent.
404    * @param {string} request.parent
405    *   Required. The agent to list all intents from.
406    *   Format: `projects/<Project ID>/agent`.
407    * @param {string} [request.languageCode]
408    *   Optional. The language to list training phrases, parameters and rich
409    *   messages for. If not specified, the agent's default language is used.
410    *   [More than a dozen
411    *   languages](https://dialogflow.com/docs/reference/language) are supported.
412    *   Note: languages must be enabled in the agent before they can be used.
413    * @param {number} [request.intentView]
414    *   Optional. The resource view to apply to the returned intent.
415    *
416    *   The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
417    * @param {number} [request.pageSize]
418    *   The maximum number of resources contained in the underlying API
419    *   response. If page streaming is performed per-resource, this
420    *   parameter does not affect the return value. If page streaming is
421    *   performed per-page, this determines the maximum number of
422    *   resources in a page.
423    * @param {Object} [options]
424    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
425    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
426    * @returns {Stream}
427    *   An object stream which emits an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent} on 'data' event.
428    *
429    * @example
430    *
431    * const dialogflow = require('dialogflow');
432    *
433    * const client = new dialogflow.v2beta1.IntentsClient({
434    *   // optional auth parameters.
435    * });
436    *
437    * const formattedParent = client.projectAgentPath('[PROJECT]');
438    * client.listIntentsStream({parent: formattedParent})
439    *   .on('data', element => {
440    *     // doThingsWith(element)
441    *   }).on('error', err => {
442    *     console.log(err);
443    *   });
444    */
445   listIntentsStream(request, options) {
446     options = options || {};
447
448     return this._descriptors.page.listIntents.createStream(
449       this._innerApiCalls.listIntents,
450       request,
451       options
452     );
453   }
454
455   /**
456    * Retrieves the specified intent.
457    *
458    * @param {Object} request
459    *   The request object that will be sent.
460    * @param {string} request.name
461    *   Required. The name of the intent.
462    *   Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
463    * @param {string} [request.languageCode]
464    *   Optional. The language to retrieve training phrases, parameters and rich
465    *   messages for. If not specified, the agent's default language is used.
466    *   [More than a dozen
467    *   languages](https://dialogflow.com/docs/reference/language) are supported.
468    *   Note: languages must be enabled in the agent, before they can be used.
469    * @param {number} [request.intentView]
470    *   Optional. The resource view to apply to the returned intent.
471    *
472    *   The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
473    * @param {Object} [options]
474    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
475    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
476    * @param {function(?Error, ?Object)} [callback]
477    *   The function which will be called with the result of the API call.
478    *
479    *   The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
480    * @returns {Promise} - The promise which resolves to an array.
481    *   The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
482    *   The promise has a method named "cancel" which cancels the ongoing API call.
483    *
484    * @example
485    *
486    * const dialogflow = require('dialogflow');
487    *
488    * const client = new dialogflow.v2beta1.IntentsClient({
489    *   // optional auth parameters.
490    * });
491    *
492    * const formattedName = client.intentPath('[PROJECT]', '[INTENT]');
493    * client.getIntent({name: formattedName})
494    *   .then(responses => {
495    *     const response = responses[0];
496    *     // doThingsWith(response)
497    *   })
498    *   .catch(err => {
499    *     console.error(err);
500    *   });
501    */
502   getIntent(request, options, callback) {
503     if (options instanceof Function && callback === undefined) {
504       callback = options;
505       options = {};
506     }
507     options = options || {};
508
509     return this._innerApiCalls.getIntent(request, options, callback);
510   }
511
512   /**
513    * Creates an intent in the specified agent.
514    *
515    * @param {Object} request
516    *   The request object that will be sent.
517    * @param {string} request.parent
518    *   Required. The agent to create a intent for.
519    *   Format: `projects/<Project ID>/agent`.
520    * @param {Object} request.intent
521    *   Required. The intent to create.
522    *
523    *   This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}
524    * @param {string} [request.languageCode]
525    *   Optional. The language of training phrases, parameters and rich messages
526    *   defined in `intent`. If not specified, the agent's default language is
527    *   used. [More than a dozen
528    *   languages](https://dialogflow.com/docs/reference/language) are supported.
529    *   Note: languages must be enabled in the agent, before they can be used.
530    * @param {number} [request.intentView]
531    *   Optional. The resource view to apply to the returned intent.
532    *
533    *   The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
534    * @param {Object} [options]
535    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
536    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
537    * @param {function(?Error, ?Object)} [callback]
538    *   The function which will be called with the result of the API call.
539    *
540    *   The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
541    * @returns {Promise} - The promise which resolves to an array.
542    *   The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
543    *   The promise has a method named "cancel" which cancels the ongoing API call.
544    *
545    * @example
546    *
547    * const dialogflow = require('dialogflow');
548    *
549    * const client = new dialogflow.v2beta1.IntentsClient({
550    *   // optional auth parameters.
551    * });
552    *
553    * const formattedParent = client.projectAgentPath('[PROJECT]');
554    * const intent = {};
555    * const request = {
556    *   parent: formattedParent,
557    *   intent: intent,
558    * };
559    * client.createIntent(request)
560    *   .then(responses => {
561    *     const response = responses[0];
562    *     // doThingsWith(response)
563    *   })
564    *   .catch(err => {
565    *     console.error(err);
566    *   });
567    */
568   createIntent(request, options, callback) {
569     if (options instanceof Function && callback === undefined) {
570       callback = options;
571       options = {};
572     }
573     options = options || {};
574
575     return this._innerApiCalls.createIntent(request, options, callback);
576   }
577
578   /**
579    * Updates the specified intent.
580    *
581    * @param {Object} request
582    *   The request object that will be sent.
583    * @param {Object} request.intent
584    *   Required. The intent to update.
585    *   Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
586    *
587    *   This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}
588    * @param {string} request.languageCode
589    *   Optional. The language of training phrases, parameters and rich messages
590    *   defined in `intent`. If not specified, the agent's default language is
591    *   used. [More than a dozen
592    *   languages](https://dialogflow.com/docs/reference/language) are supported.
593    *   Note: languages must be enabled in the agent, before they can be used.
594    * @param {Object} [request.updateMask]
595    *   Optional. The mask to control which fields get updated.
596    *
597    *   This object should have the same structure as [FieldMask]{@link google.protobuf.FieldMask}
598    * @param {number} [request.intentView]
599    *   Optional. The resource view to apply to the returned intent.
600    *
601    *   The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
602    * @param {Object} [options]
603    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
604    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
605    * @param {function(?Error, ?Object)} [callback]
606    *   The function which will be called with the result of the API call.
607    *
608    *   The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
609    * @returns {Promise} - The promise which resolves to an array.
610    *   The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
611    *   The promise has a method named "cancel" which cancels the ongoing API call.
612    *
613    * @example
614    *
615    * const dialogflow = require('dialogflow');
616    *
617    * const client = new dialogflow.v2beta1.IntentsClient({
618    *   // optional auth parameters.
619    * });
620    *
621    * const intent = {};
622    * const languageCode = '';
623    * const request = {
624    *   intent: intent,
625    *   languageCode: languageCode,
626    * };
627    * client.updateIntent(request)
628    *   .then(responses => {
629    *     const response = responses[0];
630    *     // doThingsWith(response)
631    *   })
632    *   .catch(err => {
633    *     console.error(err);
634    *   });
635    */
636   updateIntent(request, options, callback) {
637     if (options instanceof Function && callback === undefined) {
638       callback = options;
639       options = {};
640     }
641     options = options || {};
642
643     return this._innerApiCalls.updateIntent(request, options, callback);
644   }
645
646   /**
647    * Deletes the specified intent.
648    *
649    * @param {Object} request
650    *   The request object that will be sent.
651    * @param {string} request.name
652    *   Required. The name of the intent to delete.
653    *   Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
654    * @param {Object} [options]
655    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
656    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
657    * @param {function(?Error)} [callback]
658    *   The function which will be called with the result of the API call.
659    * @returns {Promise} - The promise which resolves when API call finishes.
660    *   The promise has a method named "cancel" which cancels the ongoing API call.
661    *
662    * @example
663    *
664    * const dialogflow = require('dialogflow');
665    *
666    * const client = new dialogflow.v2beta1.IntentsClient({
667    *   // optional auth parameters.
668    * });
669    *
670    * const formattedName = client.intentPath('[PROJECT]', '[INTENT]');
671    * client.deleteIntent({name: formattedName}).catch(err => {
672    *   console.error(err);
673    * });
674    */
675   deleteIntent(request, options, callback) {
676     if (options instanceof Function && callback === undefined) {
677       callback = options;
678       options = {};
679     }
680     options = options || {};
681
682     return this._innerApiCalls.deleteIntent(request, options, callback);
683   }
684
685   /**
686    * Updates/Creates multiple intents in the specified agent.
687    *
688    * Operation <response:
689    * BatchUpdateIntentsResponse>
690    *
691    * @param {Object} request
692    *   The request object that will be sent.
693    * @param {string} request.parent
694    *   Required. The name of the agent to update or create intents in.
695    *   Format: `projects/<Project ID>/agent`.
696    * @param {string} request.languageCode
697    *   Optional. The language of training phrases, parameters and rich messages
698    *   defined in `intents`. If not specified, the agent's default language is
699    *   used. [More than a dozen
700    *   languages](https://dialogflow.com/docs/reference/language) are supported.
701    *   Note: languages must be enabled in the agent, before they can be used.
702    * @param {string} [request.intentBatchUri]
703    *   The URI to a Google Cloud Storage file containing intents to update or
704    *   create. The file format can either be a serialized proto (of IntentBatch
705    *   type) or JSON object. Note: The URI must start with "gs://".
706    * @param {Object} [request.intentBatchInline]
707    *   The collection of intents to update or create.
708    *
709    *   This object should have the same structure as [IntentBatch]{@link google.cloud.dialogflow.v2beta1.IntentBatch}
710    * @param {Object} [request.updateMask]
711    *   Optional. The mask to control which fields get updated.
712    *
713    *   This object should have the same structure as [FieldMask]{@link google.protobuf.FieldMask}
714    * @param {number} [request.intentView]
715    *   Optional. The resource view to apply to the returned intent.
716    *
717    *   The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
718    * @param {Object} [options]
719    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
720    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
721    * @param {function(?Error, ?Object)} [callback]
722    *   The function which will be called with the result of the API call.
723    *
724    *   The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
725    * @returns {Promise} - The promise which resolves to an array.
726    *   The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
727    *   The promise has a method named "cancel" which cancels the ongoing API call.
728    *
729    * @example
730    *
731    * const dialogflow = require('dialogflow');
732    *
733    * const client = new dialogflow.v2beta1.IntentsClient({
734    *   // optional auth parameters.
735    * });
736    *
737    * const formattedParent = client.projectAgentPath('[PROJECT]');
738    * const languageCode = '';
739    * const request = {
740    *   parent: formattedParent,
741    *   languageCode: languageCode,
742    * };
743    *
744    * // Handle the operation using the promise pattern.
745    * client.batchUpdateIntents(request)
746    *   .then(responses => {
747    *     const [operation, initialApiResponse] = responses;
748    *
749    *     // Operation#promise starts polling for the completion of the LRO.
750    *     return operation.promise();
751    *   })
752    *   .then(responses => {
753    *     const result = responses[0];
754    *     const metadata = responses[1];
755    *     const finalApiResponse = responses[2];
756    *   })
757    *   .catch(err => {
758    *     console.error(err);
759    *   });
760    *
761    * const formattedParent = client.projectAgentPath('[PROJECT]');
762    * const languageCode = '';
763    * const request = {
764    *   parent: formattedParent,
765    *   languageCode: languageCode,
766    * };
767    *
768    * // Handle the operation using the event emitter pattern.
769    * client.batchUpdateIntents(request)
770    *   .then(responses => {
771    *     const [operation, initialApiResponse] = responses;
772    *
773    *     // Adding a listener for the "complete" event starts polling for the
774    *     // completion of the operation.
775    *     operation.on('complete', (result, metadata, finalApiResponse) => {
776    *       // doSomethingWith(result);
777    *     });
778    *
779    *     // Adding a listener for the "progress" event causes the callback to be
780    *     // called on any change in metadata when the operation is polled.
781    *     operation.on('progress', (metadata, apiResponse) => {
782    *       // doSomethingWith(metadata)
783    *     });
784    *
785    *     // Adding a listener for the "error" event handles any errors found during polling.
786    *     operation.on('error', err => {
787    *       // throw(err);
788    *     });
789    *   })
790    *   .catch(err => {
791    *     console.error(err);
792    *   });
793    *
794    * const formattedParent = client.projectAgentPath('[PROJECT]');
795    * const languageCode = '';
796    * const request = {
797    *   parent: formattedParent,
798    *   languageCode: languageCode,
799    * };
800    *
801    * // Handle the operation using the await pattern.
802    * const [operation] = await client.batchUpdateIntents(request);
803    *
804    * const [response] = await operation.promise();
805    */
806   batchUpdateIntents(request, options, callback) {
807     if (options instanceof Function && callback === undefined) {
808       callback = options;
809       options = {};
810     }
811     options = options || {};
812
813     return this._innerApiCalls.batchUpdateIntents(request, options, callback);
814   }
815
816   /**
817    * Deletes intents in the specified agent.
818    *
819    * Operation <response: google.protobuf.Empty>
820    *
821    * @param {Object} request
822    *   The request object that will be sent.
823    * @param {string} request.parent
824    *   Required. The name of the agent to delete all entities types for. Format:
825    *   `projects/<Project ID>/agent`.
826    * @param {Object[]} request.intents
827    *   Required. The collection of intents to delete. Only intent `name` must be
828    *   filled in.
829    *
830    *   This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}
831    * @param {Object} [options]
832    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
833    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
834    * @param {function(?Error, ?Object)} [callback]
835    *   The function which will be called with the result of the API call.
836    *
837    *   The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
838    * @returns {Promise} - The promise which resolves to an array.
839    *   The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
840    *   The promise has a method named "cancel" which cancels the ongoing API call.
841    *
842    * @example
843    *
844    * const dialogflow = require('dialogflow');
845    *
846    * const client = new dialogflow.v2beta1.IntentsClient({
847    *   // optional auth parameters.
848    * });
849    *
850    * const formattedParent = client.projectAgentPath('[PROJECT]');
851    * const intents = [];
852    * const request = {
853    *   parent: formattedParent,
854    *   intents: intents,
855    * };
856    *
857    * // Handle the operation using the promise pattern.
858    * client.batchDeleteIntents(request)
859    *   .then(responses => {
860    *     const [operation, initialApiResponse] = responses;
861    *
862    *     // Operation#promise starts polling for the completion of the LRO.
863    *     return operation.promise();
864    *   })
865    *   .then(responses => {
866    *     const result = responses[0];
867    *     const metadata = responses[1];
868    *     const finalApiResponse = responses[2];
869    *   })
870    *   .catch(err => {
871    *     console.error(err);
872    *   });
873    *
874    * const formattedParent = client.projectAgentPath('[PROJECT]');
875    * const intents = [];
876    * const request = {
877    *   parent: formattedParent,
878    *   intents: intents,
879    * };
880    *
881    * // Handle the operation using the event emitter pattern.
882    * client.batchDeleteIntents(request)
883    *   .then(responses => {
884    *     const [operation, initialApiResponse] = responses;
885    *
886    *     // Adding a listener for the "complete" event starts polling for the
887    *     // completion of the operation.
888    *     operation.on('complete', (result, metadata, finalApiResponse) => {
889    *       // doSomethingWith(result);
890    *     });
891    *
892    *     // Adding a listener for the "progress" event causes the callback to be
893    *     // called on any change in metadata when the operation is polled.
894    *     operation.on('progress', (metadata, apiResponse) => {
895    *       // doSomethingWith(metadata)
896    *     });
897    *
898    *     // Adding a listener for the "error" event handles any errors found during polling.
899    *     operation.on('error', err => {
900    *       // throw(err);
901    *     });
902    *   })
903    *   .catch(err => {
904    *     console.error(err);
905    *   });
906    *
907    * const formattedParent = client.projectAgentPath('[PROJECT]');
908    * const intents = [];
909    * const request = {
910    *   parent: formattedParent,
911    *   intents: intents,
912    * };
913    *
914    * // Handle the operation using the await pattern.
915    * const [operation] = await client.batchDeleteIntents(request);
916    *
917    * const [response] = await operation.promise();
918    */
919   batchDeleteIntents(request, options, callback) {
920     if (options instanceof Function && callback === undefined) {
921       callback = options;
922       options = {};
923     }
924     options = options || {};
925
926     return this._innerApiCalls.batchDeleteIntents(request, options, callback);
927   }
928
929   // --------------------
930   // -- Path templates --
931   // --------------------
932
933   /**
934    * Return a fully-qualified project_agent resource name string.
935    *
936    * @param {String} project
937    * @returns {String}
938    */
939   projectAgentPath(project) {
940     return this._pathTemplates.projectAgentPathTemplate.render({
941       project: project,
942     });
943   }
944
945   /**
946    * Return a fully-qualified intent resource name string.
947    *
948    * @param {String} project
949    * @param {String} intent
950    * @returns {String}
951    */
952   intentPath(project, intent) {
953     return this._pathTemplates.intentPathTemplate.render({
954       project: project,
955       intent: intent,
956     });
957   }
958
959   /**
960    * Parse the projectAgentName from a project_agent resource.
961    *
962    * @param {String} projectAgentName
963    *   A fully-qualified path representing a project_agent resources.
964    * @returns {String} - A string representing the project.
965    */
966   matchProjectFromProjectAgentName(projectAgentName) {
967     return this._pathTemplates.projectAgentPathTemplate.match(projectAgentName)
968       .project;
969   }
970
971   /**
972    * Parse the intentName from a intent resource.
973    *
974    * @param {String} intentName
975    *   A fully-qualified path representing a intent resources.
976    * @returns {String} - A string representing the project.
977    */
978   matchProjectFromIntentName(intentName) {
979     return this._pathTemplates.intentPathTemplate.match(intentName).project;
980   }
981
982   /**
983    * Parse the intentName from a intent resource.
984    *
985    * @param {String} intentName
986    *   A fully-qualified path representing a intent resources.
987    * @returns {String} - A string representing the intent.
988    */
989   matchIntentFromIntentName(intentName) {
990     return this._pathTemplates.intentPathTemplate.match(intentName).intent;
991   }
992 }
993
994 module.exports = IntentsClient;