Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / dialogflow / src / v2beta1 / agents_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('./agents_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  * Agents are best described as Natural Language Understanding (NLU) modules
27  * that transform user requests into actionable data. You can include agents
28  * in your app, product, or service to determine user intent and respond to the
29  * user in a natural way.
30  *
31  * After you create an agent, you can add
32  * Intents,
33  * Contexts, Entity
34  * Types,
35  * Webhooks, and so on to
36  * manage the flow of a conversation and match user input to predefined intents
37  * and actions.
38  *
39  * You can create an agent using both Dialogflow Standard Edition and
40  * Dialogflow Enterprise Edition. For details, see
41  * [Dialogflow
42  * Editions](https://cloud.google.com/dialogflow-enterprise/docs/editions).
43  *
44  * You can save your agent for backup or versioning by exporting the agent by
45  * using the ExportAgent
46  * method. You can import a saved agent by using the
47  * ImportAgent method.
48  *
49  * Dialogflow provides several
50  * [prebuilt agents](https://dialogflow.com/docs/prebuilt-agents) for common
51  * conversation scenarios such as determining a date and time, converting
52  * currency, and so on.
53  *
54  * For more information about agents, see the
55  * [Dialogflow documentation](https://dialogflow.com/docs/agents).
56  *
57  * @class
58  * @memberof v2beta1
59  */
60 class AgentsClient {
61   /**
62    * Construct an instance of AgentsClient.
63    *
64    * @param {object} [options] - The configuration object. See the subsequent
65    *   parameters for more details.
66    * @param {object} [options.credentials] - Credentials object.
67    * @param {string} [options.credentials.client_email]
68    * @param {string} [options.credentials.private_key]
69    * @param {string} [options.email] - Account email address. Required when
70    *     using a .pem or .p12 keyFilename.
71    * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
72    *     .p12 key downloaded from the Google Developers Console. If you provide
73    *     a path to a JSON file, the projectId option below is not necessary.
74    *     NOTE: .pem and .p12 require you to specify options.email as well.
75    * @param {number} [options.port] - The port on which to connect to
76    *     the remote host.
77    * @param {string} [options.projectId] - The project ID from the Google
78    *     Developer's Console, e.g. 'grape-spaceship-123'. We will also check
79    *     the environment variable GCLOUD_PROJECT for your project ID. If your
80    *     app is running in an environment which supports
81    *     {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
82    *     your project ID will be detected automatically.
83    * @param {function} [options.promise] - Custom promise module to use instead
84    *     of native Promises.
85    * @param {string} [options.servicePath] - The domain name of the
86    *     API remote host.
87    */
88   constructor(opts) {
89     this._descriptors = {};
90
91     // Ensure that options include the service address and port.
92     opts = Object.assign(
93       {
94         clientConfig: {},
95         port: this.constructor.port,
96         servicePath: this.constructor.servicePath,
97       },
98       opts
99     );
100
101     // Create a `gaxGrpc` object, with any grpc-specific options
102     // sent to the client.
103     opts.scopes = this.constructor.scopes;
104     const gaxGrpc = new gax.GrpcClient(opts);
105
106     // Save the auth object to the client, for use by other methods.
107     this.auth = gaxGrpc.auth;
108
109     // Determine the client header string.
110     const clientHeader = [
111       `gl-node/${process.version}`,
112       `grpc/${gaxGrpc.grpcVersion}`,
113       `gax/${gax.version}`,
114       `gapic/${VERSION}`,
115     ];
116     if (opts.libName && opts.libVersion) {
117       clientHeader.push(`${opts.libName}/${opts.libVersion}`);
118     }
119
120     // Load the applicable protos.
121     const protos = merge(
122       {},
123       gaxGrpc.loadProto(
124         path.join(__dirname, '..', '..', 'protos'),
125         'google/cloud/dialogflow/v2beta1/agent.proto'
126       )
127     );
128
129     // This API contains "path templates"; forward-slash-separated
130     // identifiers to uniquely identify resources within the API.
131     // Create useful helper objects for these.
132     this._pathTemplates = {
133       projectPathTemplate: new gax.PathTemplate('projects/{project}'),
134     };
135
136     // Some of the methods on this service return "paged" results,
137     // (e.g. 50 results at a time, with tokens to get subsequent
138     // pages). Denote the keys used for pagination and results.
139     this._descriptors.page = {
140       searchAgents: new gax.PageDescriptor(
141         'pageToken',
142         'nextPageToken',
143         'agents'
144       ),
145     };
146     let protoFilesRoot = new gax.GoogleProtoFilesRoot();
147     protoFilesRoot = protobuf.loadSync(
148       path.join(
149         __dirname,
150         '..',
151         '..',
152         'protos',
153         'google/cloud/dialogflow/v2beta1/agent.proto'
154       ),
155       protoFilesRoot
156     );
157
158     // This API contains "long-running operations", which return a
159     // an Operation object that allows for tracking of the operation,
160     // rather than holding a request open.
161     this.operationsClient = new gax.lro({
162       auth: gaxGrpc.auth,
163       grpc: gaxGrpc.grpc,
164     }).operationsClient(opts);
165
166     const trainAgentResponse = protoFilesRoot.lookup('google.protobuf.Empty');
167     const trainAgentMetadata = protoFilesRoot.lookup('google.protobuf.Struct');
168     const exportAgentResponse = protoFilesRoot.lookup(
169       'google.cloud.dialogflow.v2beta1.ExportAgentResponse'
170     );
171     const exportAgentMetadata = protoFilesRoot.lookup('google.protobuf.Struct');
172     const importAgentResponse = protoFilesRoot.lookup('google.protobuf.Empty');
173     const importAgentMetadata = protoFilesRoot.lookup('google.protobuf.Struct');
174     const restoreAgentResponse = protoFilesRoot.lookup('google.protobuf.Empty');
175     const restoreAgentMetadata = protoFilesRoot.lookup(
176       'google.protobuf.Struct'
177     );
178
179     this._descriptors.longrunning = {
180       trainAgent: new gax.LongrunningDescriptor(
181         this.operationsClient,
182         trainAgentResponse.decode.bind(trainAgentResponse),
183         trainAgentMetadata.decode.bind(trainAgentMetadata)
184       ),
185       exportAgent: new gax.LongrunningDescriptor(
186         this.operationsClient,
187         exportAgentResponse.decode.bind(exportAgentResponse),
188         exportAgentMetadata.decode.bind(exportAgentMetadata)
189       ),
190       importAgent: new gax.LongrunningDescriptor(
191         this.operationsClient,
192         importAgentResponse.decode.bind(importAgentResponse),
193         importAgentMetadata.decode.bind(importAgentMetadata)
194       ),
195       restoreAgent: new gax.LongrunningDescriptor(
196         this.operationsClient,
197         restoreAgentResponse.decode.bind(restoreAgentResponse),
198         restoreAgentMetadata.decode.bind(restoreAgentMetadata)
199       ),
200     };
201
202     // Put together the default options sent with requests.
203     const defaults = gaxGrpc.constructSettings(
204       'google.cloud.dialogflow.v2beta1.Agents',
205       gapicConfig,
206       opts.clientConfig,
207       {'x-goog-api-client': clientHeader.join(' ')}
208     );
209
210     // Set up a dictionary of "inner API calls"; the core implementation
211     // of calling the API is handled in `google-gax`, with this code
212     // merely providing the destination and request information.
213     this._innerApiCalls = {};
214
215     // Put together the "service stub" for
216     // google.cloud.dialogflow.v2beta1.Agents.
217     const agentsStub = gaxGrpc.createStub(
218       protos.google.cloud.dialogflow.v2beta1.Agents,
219       opts
220     );
221
222     // Iterate over each of the methods that the service provides
223     // and create an API call method for each.
224     const agentsStubMethods = [
225       'getAgent',
226       'searchAgents',
227       'trainAgent',
228       'exportAgent',
229       'importAgent',
230       'restoreAgent',
231     ];
232     for (const methodName of agentsStubMethods) {
233       this._innerApiCalls[methodName] = gax.createApiCall(
234         agentsStub.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    * Retrieves the specified agent.
289    *
290    * @param {Object} request
291    *   The request object that will be sent.
292    * @param {string} request.parent
293    *   Required. The project that the agent to fetch is associated with.
294    *   Format: `projects/<Project ID>`.
295    * @param {Object} [options]
296    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
297    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
298    * @param {function(?Error, ?Object)} [callback]
299    *   The function which will be called with the result of the API call.
300    *
301    *   The second parameter to the callback is an object representing [Agent]{@link google.cloud.dialogflow.v2beta1.Agent}.
302    * @returns {Promise} - The promise which resolves to an array.
303    *   The first element of the array is an object representing [Agent]{@link google.cloud.dialogflow.v2beta1.Agent}.
304    *   The promise has a method named "cancel" which cancels the ongoing API call.
305    *
306    * @example
307    *
308    * const dialogflow = require('dialogflow');
309    *
310    * const client = new dialogflow.v2beta1.AgentsClient({
311    *   // optional auth parameters.
312    * });
313    *
314    * const formattedParent = client.projectPath('[PROJECT]');
315    * client.getAgent({parent: formattedParent})
316    *   .then(responses => {
317    *     const response = responses[0];
318    *     // doThingsWith(response)
319    *   })
320    *   .catch(err => {
321    *     console.error(err);
322    *   });
323    */
324   getAgent(request, options, callback) {
325     if (options instanceof Function && callback === undefined) {
326       callback = options;
327       options = {};
328     }
329     options = options || {};
330
331     return this._innerApiCalls.getAgent(request, options, callback);
332   }
333
334   /**
335    * Returns the list of agents.
336    *
337    * Since there is at most one conversational agent per project, this method is
338    * useful primarily for listing all agents across projects the caller has
339    * access to. One can achieve that with a wildcard project collection id "-".
340    * Refer to [List
341    * Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
342    *
343    * @param {Object} request
344    *   The request object that will be sent.
345    * @param {string} request.parent
346    *   Required. The project to list agents from.
347    *   Format: `projects/<Project ID or '-'>`.
348    * @param {number} [request.pageSize]
349    *   The maximum number of resources contained in the underlying API
350    *   response. If page streaming is performed per-resource, this
351    *   parameter does not affect the return value. If page streaming is
352    *   performed per-page, this determines the maximum number of
353    *   resources in a page.
354    * @param {Object} [options]
355    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
356    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
357    * @param {function(?Error, ?Array, ?Object, ?Object)} [callback]
358    *   The function which will be called with the result of the API call.
359    *
360    *   The second parameter to the callback is Array of [Agent]{@link google.cloud.dialogflow.v2beta1.Agent}.
361    *
362    *   When autoPaginate: false is specified through options, it contains the result
363    *   in a single response. If the response indicates the next page exists, the third
364    *   parameter is set to be used for the next request object. The fourth parameter keeps
365    *   the raw response object of an object representing [SearchAgentsResponse]{@link google.cloud.dialogflow.v2beta1.SearchAgentsResponse}.
366    * @returns {Promise} - The promise which resolves to an array.
367    *   The first element of the array is Array of [Agent]{@link google.cloud.dialogflow.v2beta1.Agent}.
368    *
369    *   When autoPaginate: false is specified through options, the array has three elements.
370    *   The first element is Array of [Agent]{@link google.cloud.dialogflow.v2beta1.Agent} in a single response.
371    *   The second element is the next request object if the response
372    *   indicates the next page exists, or null. The third element is
373    *   an object representing [SearchAgentsResponse]{@link google.cloud.dialogflow.v2beta1.SearchAgentsResponse}.
374    *
375    *   The promise has a method named "cancel" which cancels the ongoing API call.
376    *
377    * @example
378    *
379    * const dialogflow = require('dialogflow');
380    *
381    * const client = new dialogflow.v2beta1.AgentsClient({
382    *   // optional auth parameters.
383    * });
384    *
385    * // Iterate over all elements.
386    * const formattedParent = client.projectPath('[PROJECT]');
387    *
388    * client.searchAgents({parent: formattedParent})
389    *   .then(responses => {
390    *     const resources = responses[0];
391    *     for (const resource of resources) {
392    *       // doThingsWith(resource)
393    *     }
394    *   })
395    *   .catch(err => {
396    *     console.error(err);
397    *   });
398    *
399    * // Or obtain the paged response.
400    * const formattedParent = client.projectPath('[PROJECT]');
401    *
402    *
403    * const options = {autoPaginate: false};
404    * const callback = responses => {
405    *   // The actual resources in a response.
406    *   const resources = responses[0];
407    *   // The next request if the response shows that there are more responses.
408    *   const nextRequest = responses[1];
409    *   // The actual response object, if necessary.
410    *   // const rawResponse = responses[2];
411    *   for (const resource of resources) {
412    *     // doThingsWith(resource);
413    *   }
414    *   if (nextRequest) {
415    *     // Fetch the next page.
416    *     return client.searchAgents(nextRequest, options).then(callback);
417    *   }
418    * }
419    * client.searchAgents({parent: formattedParent}, options)
420    *   .then(callback)
421    *   .catch(err => {
422    *     console.error(err);
423    *   });
424    */
425   searchAgents(request, options, callback) {
426     if (options instanceof Function && callback === undefined) {
427       callback = options;
428       options = {};
429     }
430     options = options || {};
431
432     return this._innerApiCalls.searchAgents(request, options, callback);
433   }
434
435   /**
436    * Equivalent to {@link searchAgents}, but returns a NodeJS Stream object.
437    *
438    * This fetches the paged responses for {@link searchAgents} continuously
439    * and invokes the callback registered for 'data' event for each element in the
440    * responses.
441    *
442    * The returned object has 'end' method when no more elements are required.
443    *
444    * autoPaginate option will be ignored.
445    *
446    * @see {@link https://nodejs.org/api/stream.html}
447    *
448    * @param {Object} request
449    *   The request object that will be sent.
450    * @param {string} request.parent
451    *   Required. The project to list agents from.
452    *   Format: `projects/<Project ID or '-'>`.
453    * @param {number} [request.pageSize]
454    *   The maximum number of resources contained in the underlying API
455    *   response. If page streaming is performed per-resource, this
456    *   parameter does not affect the return value. If page streaming is
457    *   performed per-page, this determines the maximum number of
458    *   resources in a page.
459    * @param {Object} [options]
460    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
461    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
462    * @returns {Stream}
463    *   An object stream which emits an object representing [Agent]{@link google.cloud.dialogflow.v2beta1.Agent} on 'data' event.
464    *
465    * @example
466    *
467    * const dialogflow = require('dialogflow');
468    *
469    * const client = new dialogflow.v2beta1.AgentsClient({
470    *   // optional auth parameters.
471    * });
472    *
473    * const formattedParent = client.projectPath('[PROJECT]');
474    * client.searchAgentsStream({parent: formattedParent})
475    *   .on('data', element => {
476    *     // doThingsWith(element)
477    *   }).on('error', err => {
478    *     console.log(err);
479    *   });
480    */
481   searchAgentsStream(request, options) {
482     options = options || {};
483
484     return this._descriptors.page.searchAgents.createStream(
485       this._innerApiCalls.searchAgents,
486       request,
487       options
488     );
489   }
490
491   /**
492    * Trains the specified agent.
493    *
494    *
495    * Operation <response: google.protobuf.Empty,
496    *            metadata: google.protobuf.Struct>
497    *
498    * @param {Object} request
499    *   The request object that will be sent.
500    * @param {string} request.parent
501    *   Required. The project that the agent to train is associated with.
502    *   Format: `projects/<Project ID>`.
503    * @param {Object} [options]
504    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
505    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
506    * @param {function(?Error, ?Object)} [callback]
507    *   The function which will be called with the result of the API call.
508    *
509    *   The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
510    * @returns {Promise} - The promise which resolves to an array.
511    *   The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
512    *   The promise has a method named "cancel" which cancels the ongoing API call.
513    *
514    * @example
515    *
516    * const dialogflow = require('dialogflow');
517    *
518    * const client = new dialogflow.v2beta1.AgentsClient({
519    *   // optional auth parameters.
520    * });
521    *
522    * const formattedParent = client.projectPath('[PROJECT]');
523    *
524    * // Handle the operation using the promise pattern.
525    * client.trainAgent({parent: formattedParent})
526    *   .then(responses => {
527    *     const [operation, initialApiResponse] = responses;
528    *
529    *     // Operation#promise starts polling for the completion of the LRO.
530    *     return operation.promise();
531    *   })
532    *   .then(responses => {
533    *     const result = responses[0];
534    *     const metadata = responses[1];
535    *     const finalApiResponse = responses[2];
536    *   })
537    *   .catch(err => {
538    *     console.error(err);
539    *   });
540    *
541    * const formattedParent = client.projectPath('[PROJECT]');
542    *
543    * // Handle the operation using the event emitter pattern.
544    * client.trainAgent({parent: formattedParent})
545    *   .then(responses => {
546    *     const [operation, initialApiResponse] = responses;
547    *
548    *     // Adding a listener for the "complete" event starts polling for the
549    *     // completion of the operation.
550    *     operation.on('complete', (result, metadata, finalApiResponse) => {
551    *       // doSomethingWith(result);
552    *     });
553    *
554    *     // Adding a listener for the "progress" event causes the callback to be
555    *     // called on any change in metadata when the operation is polled.
556    *     operation.on('progress', (metadata, apiResponse) => {
557    *       // doSomethingWith(metadata)
558    *     });
559    *
560    *     // Adding a listener for the "error" event handles any errors found during polling.
561    *     operation.on('error', err => {
562    *       // throw(err);
563    *     });
564    *   })
565    *   .catch(err => {
566    *     console.error(err);
567    *   });
568    *
569    * const formattedParent = client.projectPath('[PROJECT]');
570    *
571    * // Handle the operation using the await pattern.
572    * const [operation] = await client.trainAgent({parent: formattedParent});
573    *
574    * const [response] = await operation.promise();
575    */
576   trainAgent(request, options, callback) {
577     if (options instanceof Function && callback === undefined) {
578       callback = options;
579       options = {};
580     }
581     options = options || {};
582
583     return this._innerApiCalls.trainAgent(request, options, callback);
584   }
585
586   /**
587    * Exports the specified agent to a ZIP file.
588    *
589    *
590    * Operation <response:
591    * ExportAgentResponse,
592    *            metadata: google.protobuf.Struct>
593    *
594    * @param {Object} request
595    *   The request object that will be sent.
596    * @param {string} request.parent
597    *   Required. The project that the agent to export is associated with.
598    *   Format: `projects/<Project ID>`.
599    * @param {string} [request.agentUri]
600    *   Optional. The
601    *   [Google Cloud Storage](https://cloud.google.com/storage/docs/)
602    *   URI to export the agent to.
603    *   The format of this URI must be `gs://<bucket-name>/<object-name>`.
604    *   If left unspecified, the serialized agent is returned inline.
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 a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
612    * @returns {Promise} - The promise which resolves to an array.
613    *   The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
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.v2beta1.AgentsClient({
621    *   // optional auth parameters.
622    * });
623    *
624    * const formattedParent = client.projectPath('[PROJECT]');
625    *
626    * // Handle the operation using the promise pattern.
627    * client.exportAgent({parent: formattedParent})
628    *   .then(responses => {
629    *     const [operation, initialApiResponse] = responses;
630    *
631    *     // Operation#promise starts polling for the completion of the LRO.
632    *     return operation.promise();
633    *   })
634    *   .then(responses => {
635    *     const result = responses[0];
636    *     const metadata = responses[1];
637    *     const finalApiResponse = responses[2];
638    *   })
639    *   .catch(err => {
640    *     console.error(err);
641    *   });
642    *
643    * const formattedParent = client.projectPath('[PROJECT]');
644    *
645    * // Handle the operation using the event emitter pattern.
646    * client.exportAgent({parent: formattedParent})
647    *   .then(responses => {
648    *     const [operation, initialApiResponse] = responses;
649    *
650    *     // Adding a listener for the "complete" event starts polling for the
651    *     // completion of the operation.
652    *     operation.on('complete', (result, metadata, finalApiResponse) => {
653    *       // doSomethingWith(result);
654    *     });
655    *
656    *     // Adding a listener for the "progress" event causes the callback to be
657    *     // called on any change in metadata when the operation is polled.
658    *     operation.on('progress', (metadata, apiResponse) => {
659    *       // doSomethingWith(metadata)
660    *     });
661    *
662    *     // Adding a listener for the "error" event handles any errors found during polling.
663    *     operation.on('error', err => {
664    *       // throw(err);
665    *     });
666    *   })
667    *   .catch(err => {
668    *     console.error(err);
669    *   });
670    *
671    * const formattedParent = client.projectPath('[PROJECT]');
672    *
673    * // Handle the operation using the await pattern.
674    * const [operation] = await client.exportAgent({parent: formattedParent});
675    *
676    * const [response] = await operation.promise();
677    */
678   exportAgent(request, options, callback) {
679     if (options instanceof Function && callback === undefined) {
680       callback = options;
681       options = {};
682     }
683     options = options || {};
684
685     return this._innerApiCalls.exportAgent(request, options, callback);
686   }
687
688   /**
689    * Imports the specified agent from a ZIP file.
690    *
691    * Uploads new intents and entity types without deleting the existing ones.
692    * Intents and entity types with the same name are replaced with the new
693    * versions from ImportAgentRequest.
694    *
695    *
696    * Operation <response: google.protobuf.Empty,
697    *            metadata: google.protobuf.Struct>
698    *
699    * @param {Object} request
700    *   The request object that will be sent.
701    * @param {string} request.parent
702    *   Required. The project that the agent to import is associated with.
703    *   Format: `projects/<Project ID>`.
704    * @param {string} [request.agentUri]
705    *   The URI to a Google Cloud Storage file containing the agent to import.
706    *   Note: The URI must start with "gs://".
707    * @param {string} [request.agentContent]
708    *   The agent to import.
709    *
710    *   Example for how to import an agent via the command line:
711    *   <pre>curl \
712    *     'https://dialogflow.googleapis.com/v2beta1/projects/&lt;project_name&gt;/agent:import\
713    *      -X POST \
714    *      -H 'Authorization: Bearer '$(gcloud auth application-default
715    *      print-access-token) \
716    *      -H 'Accept: application/json' \
717    *      -H 'Content-Type: application/json' \
718    *      --compressed \
719    *      --data-binary "{
720    *         'agentContent': '$(cat &lt;agent zip file&gt; | base64 -w 0)'
721    *      }"</pre>
722    * @param {Object} [options]
723    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
724    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
725    * @param {function(?Error, ?Object)} [callback]
726    *   The function which will be called with the result of the API call.
727    *
728    *   The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
729    * @returns {Promise} - The promise which resolves to an array.
730    *   The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
731    *   The promise has a method named "cancel" which cancels the ongoing API call.
732    *
733    * @example
734    *
735    * const dialogflow = require('dialogflow');
736    *
737    * const client = new dialogflow.v2beta1.AgentsClient({
738    *   // optional auth parameters.
739    * });
740    *
741    * const formattedParent = client.projectPath('[PROJECT]');
742    *
743    * // Handle the operation using the promise pattern.
744    * client.importAgent({parent: formattedParent})
745    *   .then(responses => {
746    *     const [operation, initialApiResponse] = responses;
747    *
748    *     // Operation#promise starts polling for the completion of the LRO.
749    *     return operation.promise();
750    *   })
751    *   .then(responses => {
752    *     const result = responses[0];
753    *     const metadata = responses[1];
754    *     const finalApiResponse = responses[2];
755    *   })
756    *   .catch(err => {
757    *     console.error(err);
758    *   });
759    *
760    * const formattedParent = client.projectPath('[PROJECT]');
761    *
762    * // Handle the operation using the event emitter pattern.
763    * client.importAgent({parent: formattedParent})
764    *   .then(responses => {
765    *     const [operation, initialApiResponse] = responses;
766    *
767    *     // Adding a listener for the "complete" event starts polling for the
768    *     // completion of the operation.
769    *     operation.on('complete', (result, metadata, finalApiResponse) => {
770    *       // doSomethingWith(result);
771    *     });
772    *
773    *     // Adding a listener for the "progress" event causes the callback to be
774    *     // called on any change in metadata when the operation is polled.
775    *     operation.on('progress', (metadata, apiResponse) => {
776    *       // doSomethingWith(metadata)
777    *     });
778    *
779    *     // Adding a listener for the "error" event handles any errors found during polling.
780    *     operation.on('error', err => {
781    *       // throw(err);
782    *     });
783    *   })
784    *   .catch(err => {
785    *     console.error(err);
786    *   });
787    *
788    * const formattedParent = client.projectPath('[PROJECT]');
789    *
790    * // Handle the operation using the await pattern.
791    * const [operation] = await client.importAgent({parent: formattedParent});
792    *
793    * const [response] = await operation.promise();
794    */
795   importAgent(request, options, callback) {
796     if (options instanceof Function && callback === undefined) {
797       callback = options;
798       options = {};
799     }
800     options = options || {};
801
802     return this._innerApiCalls.importAgent(request, options, callback);
803   }
804
805   /**
806    * Restores the specified agent from a ZIP file.
807    *
808    * Replaces the current agent version with a new one. All the intents and
809    * entity types in the older version are deleted.
810    *
811    *
812    * Operation <response: google.protobuf.Empty,
813    *            metadata: google.protobuf.Struct>
814    *
815    * @param {Object} request
816    *   The request object that will be sent.
817    * @param {string} request.parent
818    *   Required. The project that the agent to restore is associated with.
819    *   Format: `projects/<Project ID>`.
820    * @param {string} [request.agentUri]
821    *   The URI to a Google Cloud Storage file containing the agent to restore.
822    *   Note: The URI must start with "gs://".
823    * @param {string} [request.agentContent]
824    *   The agent to restore.
825    *
826    *   Example for how to restore an agent via the command line:
827    *   <pre>curl \
828    *     'https://dialogflow.googleapis.com/v2beta1/projects/&lt;project_name&gt;/agent:restore\
829    *      -X POST \
830    *      -H 'Authorization: Bearer '$(gcloud auth application-default
831    *      print-access-token) \
832    *      -H 'Accept: application/json' \
833    *      -H 'Content-Type: application/json' \
834    *      --compressed \
835    *      --data-binary "{
836    *          'agentContent': '$(cat &lt;agent zip file&gt; | base64 -w 0)'
837    *      }"</pre>
838    * @param {Object} [options]
839    *   Optional parameters. You can override the default settings for this call, e.g, timeout,
840    *   retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
841    * @param {function(?Error, ?Object)} [callback]
842    *   The function which will be called with the result of the API call.
843    *
844    *   The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
845    * @returns {Promise} - The promise which resolves to an array.
846    *   The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
847    *   The promise has a method named "cancel" which cancels the ongoing API call.
848    *
849    * @example
850    *
851    * const dialogflow = require('dialogflow');
852    *
853    * const client = new dialogflow.v2beta1.AgentsClient({
854    *   // optional auth parameters.
855    * });
856    *
857    * const formattedParent = client.projectPath('[PROJECT]');
858    *
859    * // Handle the operation using the promise pattern.
860    * client.restoreAgent({parent: formattedParent})
861    *   .then(responses => {
862    *     const [operation, initialApiResponse] = responses;
863    *
864    *     // Operation#promise starts polling for the completion of the LRO.
865    *     return operation.promise();
866    *   })
867    *   .then(responses => {
868    *     const result = responses[0];
869    *     const metadata = responses[1];
870    *     const finalApiResponse = responses[2];
871    *   })
872    *   .catch(err => {
873    *     console.error(err);
874    *   });
875    *
876    * const formattedParent = client.projectPath('[PROJECT]');
877    *
878    * // Handle the operation using the event emitter pattern.
879    * client.restoreAgent({parent: formattedParent})
880    *   .then(responses => {
881    *     const [operation, initialApiResponse] = responses;
882    *
883    *     // Adding a listener for the "complete" event starts polling for the
884    *     // completion of the operation.
885    *     operation.on('complete', (result, metadata, finalApiResponse) => {
886    *       // doSomethingWith(result);
887    *     });
888    *
889    *     // Adding a listener for the "progress" event causes the callback to be
890    *     // called on any change in metadata when the operation is polled.
891    *     operation.on('progress', (metadata, apiResponse) => {
892    *       // doSomethingWith(metadata)
893    *     });
894    *
895    *     // Adding a listener for the "error" event handles any errors found during polling.
896    *     operation.on('error', err => {
897    *       // throw(err);
898    *     });
899    *   })
900    *   .catch(err => {
901    *     console.error(err);
902    *   });
903    *
904    * const formattedParent = client.projectPath('[PROJECT]');
905    *
906    * // Handle the operation using the await pattern.
907    * const [operation] = await client.restoreAgent({parent: formattedParent});
908    *
909    * const [response] = await operation.promise();
910    */
911   restoreAgent(request, options, callback) {
912     if (options instanceof Function && callback === undefined) {
913       callback = options;
914       options = {};
915     }
916     options = options || {};
917
918     return this._innerApiCalls.restoreAgent(request, options, callback);
919   }
920
921   // --------------------
922   // -- Path templates --
923   // --------------------
924
925   /**
926    * Return a fully-qualified project resource name string.
927    *
928    * @param {String} project
929    * @returns {String}
930    */
931   projectPath(project) {
932     return this._pathTemplates.projectPathTemplate.render({
933       project: project,
934     });
935   }
936
937   /**
938    * Parse the projectName from a project resource.
939    *
940    * @param {String} projectName
941    *   A fully-qualified path representing a project resources.
942    * @returns {String} - A string representing the project.
943    */
944   matchProjectFromProjectName(projectName) {
945     return this._pathTemplates.projectPathTemplate.match(projectName).project;
946   }
947 }
948
949 module.exports = AgentsClient;