1 // Copyright 2019 Google LLC
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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.
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');
23 const VERSION = require('../../package.json').version;
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.
31 * After you create an agent, you can add
35 * Webhooks, and so on to
36 * manage the flow of a conversation and match user input to predefined intents
39 * You can create an agent using both Dialogflow Standard Edition and
40 * Dialogflow Enterprise Edition. For details, see
42 * Editions](https://cloud.google.com/dialogflow-enterprise/docs/editions).
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
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.
54 * For more information about agents, see the
55 * [Dialogflow documentation](https://dialogflow.com/docs/agents).
62 * Construct an instance of AgentsClient.
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
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
85 * @param {string} [options.servicePath] - The domain name of the
89 this._descriptors = {};
91 // Ensure that options include the service address and port.
95 port: this.constructor.port,
96 servicePath: this.constructor.servicePath,
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);
106 // Save the auth object to the client, for use by other methods.
107 this.auth = gaxGrpc.auth;
109 // Determine the client header string.
110 const clientHeader = [
111 `gl-node/${process.version}`,
112 `grpc/${gaxGrpc.grpcVersion}`,
113 `gax/${gax.version}`,
116 if (opts.libName && opts.libVersion) {
117 clientHeader.push(`${opts.libName}/${opts.libVersion}`);
120 // Load the applicable protos.
121 const protos = merge(
124 path.join(__dirname, '..', '..', 'protos'),
125 'google/cloud/dialogflow/v2beta1/agent.proto'
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}'),
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(
146 let protoFilesRoot = new gax.GoogleProtoFilesRoot();
147 protoFilesRoot = protobuf.loadSync(
153 'google/cloud/dialogflow/v2beta1/agent.proto'
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({
164 }).operationsClient(opts);
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'
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'
179 this._descriptors.longrunning = {
180 trainAgent: new gax.LongrunningDescriptor(
181 this.operationsClient,
182 trainAgentResponse.decode.bind(trainAgentResponse),
183 trainAgentMetadata.decode.bind(trainAgentMetadata)
185 exportAgent: new gax.LongrunningDescriptor(
186 this.operationsClient,
187 exportAgentResponse.decode.bind(exportAgentResponse),
188 exportAgentMetadata.decode.bind(exportAgentMetadata)
190 importAgent: new gax.LongrunningDescriptor(
191 this.operationsClient,
192 importAgentResponse.decode.bind(importAgentResponse),
193 importAgentMetadata.decode.bind(importAgentMetadata)
195 restoreAgent: new gax.LongrunningDescriptor(
196 this.operationsClient,
197 restoreAgentResponse.decode.bind(restoreAgentResponse),
198 restoreAgentMetadata.decode.bind(restoreAgentMetadata)
202 // Put together the default options sent with requests.
203 const defaults = gaxGrpc.constructSettings(
204 'google.cloud.dialogflow.v2beta1.Agents',
207 {'x-goog-api-client': clientHeader.join(' ')}
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 = {};
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,
222 // Iterate over each of the methods that the service provides
223 // and create an API call method for each.
224 const agentsStubMethods = [
232 for (const methodName of agentsStubMethods) {
233 this._innerApiCalls[methodName] = gax.createApiCall(
237 const args = Array.prototype.slice.call(arguments, 0);
238 return stub[methodName].apply(stub, args);
245 defaults[methodName],
246 this._descriptors.page[methodName] ||
247 this._descriptors.longrunning[methodName]
253 * The DNS address for this API service.
255 static get servicePath() {
256 return 'dialogflow.googleapis.com';
260 * The port for this API service.
267 * The scopes needed to make gRPC calls for every method defined
270 static get scopes() {
271 return ['https://www.googleapis.com/auth/cloud-platform'];
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.
279 getProjectId(callback) {
280 return this.auth.getProjectId(callback);
283 // -------------------
284 // -- Service calls --
285 // -------------------
288 * Retrieves the specified agent.
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.
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.
308 * const dialogflow = require('dialogflow');
310 * const client = new dialogflow.v2beta1.AgentsClient({
311 * // optional auth parameters.
314 * const formattedParent = client.projectPath('[PROJECT]');
315 * client.getAgent({parent: formattedParent})
316 * .then(responses => {
317 * const response = responses[0];
318 * // doThingsWith(response)
321 * console.error(err);
324 getAgent(request, options, callback) {
325 if (options instanceof Function && callback === undefined) {
329 options = options || {};
331 return this._innerApiCalls.getAgent(request, options, callback);
335 * Returns the list of agents.
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 "-".
341 * Sub-Collections](https://cloud.google.com/apis/design/design_patterns#list_sub-collections).
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.
360 * The second parameter to the callback is Array of [Agent]{@link google.cloud.dialogflow.v2beta1.Agent}.
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}.
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}.
375 * The promise has a method named "cancel" which cancels the ongoing API call.
379 * const dialogflow = require('dialogflow');
381 * const client = new dialogflow.v2beta1.AgentsClient({
382 * // optional auth parameters.
385 * // Iterate over all elements.
386 * const formattedParent = client.projectPath('[PROJECT]');
388 * client.searchAgents({parent: formattedParent})
389 * .then(responses => {
390 * const resources = responses[0];
391 * for (const resource of resources) {
392 * // doThingsWith(resource)
396 * console.error(err);
399 * // Or obtain the paged response.
400 * const formattedParent = client.projectPath('[PROJECT]');
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);
415 * // Fetch the next page.
416 * return client.searchAgents(nextRequest, options).then(callback);
419 * client.searchAgents({parent: formattedParent}, options)
422 * console.error(err);
425 searchAgents(request, options, callback) {
426 if (options instanceof Function && callback === undefined) {
430 options = options || {};
432 return this._innerApiCalls.searchAgents(request, options, callback);
436 * Equivalent to {@link searchAgents}, but returns a NodeJS Stream object.
438 * This fetches the paged responses for {@link searchAgents} continuously
439 * and invokes the callback registered for 'data' event for each element in the
442 * The returned object has 'end' method when no more elements are required.
444 * autoPaginate option will be ignored.
446 * @see {@link https://nodejs.org/api/stream.html}
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.
463 * An object stream which emits an object representing [Agent]{@link google.cloud.dialogflow.v2beta1.Agent} on 'data' event.
467 * const dialogflow = require('dialogflow');
469 * const client = new dialogflow.v2beta1.AgentsClient({
470 * // optional auth parameters.
473 * const formattedParent = client.projectPath('[PROJECT]');
474 * client.searchAgentsStream({parent: formattedParent})
475 * .on('data', element => {
476 * // doThingsWith(element)
477 * }).on('error', err => {
481 searchAgentsStream(request, options) {
482 options = options || {};
484 return this._descriptors.page.searchAgents.createStream(
485 this._innerApiCalls.searchAgents,
492 * Trains the specified agent.
495 * Operation <response: google.protobuf.Empty,
496 * metadata: google.protobuf.Struct>
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.
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.
516 * const dialogflow = require('dialogflow');
518 * const client = new dialogflow.v2beta1.AgentsClient({
519 * // optional auth parameters.
522 * const formattedParent = client.projectPath('[PROJECT]');
524 * // Handle the operation using the promise pattern.
525 * client.trainAgent({parent: formattedParent})
526 * .then(responses => {
527 * const [operation, initialApiResponse] = responses;
529 * // Operation#promise starts polling for the completion of the LRO.
530 * return operation.promise();
532 * .then(responses => {
533 * const result = responses[0];
534 * const metadata = responses[1];
535 * const finalApiResponse = responses[2];
538 * console.error(err);
541 * const formattedParent = client.projectPath('[PROJECT]');
543 * // Handle the operation using the event emitter pattern.
544 * client.trainAgent({parent: formattedParent})
545 * .then(responses => {
546 * const [operation, initialApiResponse] = responses;
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);
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)
560 * // Adding a listener for the "error" event handles any errors found during polling.
561 * operation.on('error', err => {
566 * console.error(err);
569 * const formattedParent = client.projectPath('[PROJECT]');
571 * // Handle the operation using the await pattern.
572 * const [operation] = await client.trainAgent({parent: formattedParent});
574 * const [response] = await operation.promise();
576 trainAgent(request, options, callback) {
577 if (options instanceof Function && callback === undefined) {
581 options = options || {};
583 return this._innerApiCalls.trainAgent(request, options, callback);
587 * Exports the specified agent to a ZIP file.
590 * Operation <response:
591 * ExportAgentResponse,
592 * metadata: google.protobuf.Struct>
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]
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.
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.
618 * const dialogflow = require('dialogflow');
620 * const client = new dialogflow.v2beta1.AgentsClient({
621 * // optional auth parameters.
624 * const formattedParent = client.projectPath('[PROJECT]');
626 * // Handle the operation using the promise pattern.
627 * client.exportAgent({parent: formattedParent})
628 * .then(responses => {
629 * const [operation, initialApiResponse] = responses;
631 * // Operation#promise starts polling for the completion of the LRO.
632 * return operation.promise();
634 * .then(responses => {
635 * const result = responses[0];
636 * const metadata = responses[1];
637 * const finalApiResponse = responses[2];
640 * console.error(err);
643 * const formattedParent = client.projectPath('[PROJECT]');
645 * // Handle the operation using the event emitter pattern.
646 * client.exportAgent({parent: formattedParent})
647 * .then(responses => {
648 * const [operation, initialApiResponse] = responses;
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);
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)
662 * // Adding a listener for the "error" event handles any errors found during polling.
663 * operation.on('error', err => {
668 * console.error(err);
671 * const formattedParent = client.projectPath('[PROJECT]');
673 * // Handle the operation using the await pattern.
674 * const [operation] = await client.exportAgent({parent: formattedParent});
676 * const [response] = await operation.promise();
678 exportAgent(request, options, callback) {
679 if (options instanceof Function && callback === undefined) {
683 options = options || {};
685 return this._innerApiCalls.exportAgent(request, options, callback);
689 * Imports the specified agent from a ZIP file.
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.
696 * Operation <response: google.protobuf.Empty,
697 * metadata: google.protobuf.Struct>
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.
710 * Example for how to import an agent via the command line:
712 * 'https://dialogflow.googleapis.com/v2beta1/projects/<project_name>/agent:import\
714 * -H 'Authorization: Bearer '$(gcloud auth application-default
715 * print-access-token) \
716 * -H 'Accept: application/json' \
717 * -H 'Content-Type: application/json' \
720 * 'agentContent': '$(cat <agent zip file> | base64 -w 0)'
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.
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.
735 * const dialogflow = require('dialogflow');
737 * const client = new dialogflow.v2beta1.AgentsClient({
738 * // optional auth parameters.
741 * const formattedParent = client.projectPath('[PROJECT]');
743 * // Handle the operation using the promise pattern.
744 * client.importAgent({parent: formattedParent})
745 * .then(responses => {
746 * const [operation, initialApiResponse] = responses;
748 * // Operation#promise starts polling for the completion of the LRO.
749 * return operation.promise();
751 * .then(responses => {
752 * const result = responses[0];
753 * const metadata = responses[1];
754 * const finalApiResponse = responses[2];
757 * console.error(err);
760 * const formattedParent = client.projectPath('[PROJECT]');
762 * // Handle the operation using the event emitter pattern.
763 * client.importAgent({parent: formattedParent})
764 * .then(responses => {
765 * const [operation, initialApiResponse] = responses;
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);
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)
779 * // Adding a listener for the "error" event handles any errors found during polling.
780 * operation.on('error', err => {
785 * console.error(err);
788 * const formattedParent = client.projectPath('[PROJECT]');
790 * // Handle the operation using the await pattern.
791 * const [operation] = await client.importAgent({parent: formattedParent});
793 * const [response] = await operation.promise();
795 importAgent(request, options, callback) {
796 if (options instanceof Function && callback === undefined) {
800 options = options || {};
802 return this._innerApiCalls.importAgent(request, options, callback);
806 * Restores the specified agent from a ZIP file.
808 * Replaces the current agent version with a new one. All the intents and
809 * entity types in the older version are deleted.
812 * Operation <response: google.protobuf.Empty,
813 * metadata: google.protobuf.Struct>
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.
826 * Example for how to restore an agent via the command line:
828 * 'https://dialogflow.googleapis.com/v2beta1/projects/<project_name>/agent:restore\
830 * -H 'Authorization: Bearer '$(gcloud auth application-default
831 * print-access-token) \
832 * -H 'Accept: application/json' \
833 * -H 'Content-Type: application/json' \
836 * 'agentContent': '$(cat <agent zip file> | base64 -w 0)'
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.
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.
851 * const dialogflow = require('dialogflow');
853 * const client = new dialogflow.v2beta1.AgentsClient({
854 * // optional auth parameters.
857 * const formattedParent = client.projectPath('[PROJECT]');
859 * // Handle the operation using the promise pattern.
860 * client.restoreAgent({parent: formattedParent})
861 * .then(responses => {
862 * const [operation, initialApiResponse] = responses;
864 * // Operation#promise starts polling for the completion of the LRO.
865 * return operation.promise();
867 * .then(responses => {
868 * const result = responses[0];
869 * const metadata = responses[1];
870 * const finalApiResponse = responses[2];
873 * console.error(err);
876 * const formattedParent = client.projectPath('[PROJECT]');
878 * // Handle the operation using the event emitter pattern.
879 * client.restoreAgent({parent: formattedParent})
880 * .then(responses => {
881 * const [operation, initialApiResponse] = responses;
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);
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)
895 * // Adding a listener for the "error" event handles any errors found during polling.
896 * operation.on('error', err => {
901 * console.error(err);
904 * const formattedParent = client.projectPath('[PROJECT]');
906 * // Handle the operation using the await pattern.
907 * const [operation] = await client.restoreAgent({parent: formattedParent});
909 * const [response] = await operation.promise();
911 restoreAgent(request, options, callback) {
912 if (options instanceof Function && callback === undefined) {
916 options = options || {};
918 return this._innerApiCalls.restoreAgent(request, options, callback);
921 // --------------------
922 // -- Path templates --
923 // --------------------
926 * Return a fully-qualified project resource name string.
928 * @param {String} project
931 projectPath(project) {
932 return this._pathTemplates.projectPathTemplate.render({
938 * Parse the projectName from a project resource.
940 * @param {String} projectName
941 * A fully-qualified path representing a project resources.
942 * @returns {String} - A string representing the project.
944 matchProjectFromProjectName(projectName) {
945 return this._pathTemplates.projectPathTemplate.match(projectName).project;
949 module.exports = AgentsClient;