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