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('./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');
23 const VERSION = require('../../package.json').version;
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
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).
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.
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".
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.
52 * * **Training phrases** - provide examples of user input to train the
53 * Dialogflow API agent to better match intents.
55 * For more information about intents, see the
56 * [Dialogflow documentation](https://dialogflow.com/docs/intents).
63 * Construct an instance of IntentsClient.
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
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
86 * @param {string} [options.servicePath] - The domain name of the
90 this._descriptors = {};
92 // Ensure that options include the service address and port.
96 port: this.constructor.port,
97 servicePath: this.constructor.servicePath,
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);
107 // Save the auth object to the client, for use by other methods.
108 this.auth = gaxGrpc.auth;
110 // Determine the client header string.
111 const clientHeader = [
112 `gl-node/${process.version}`,
113 `grpc/${gaxGrpc.grpcVersion}`,
114 `gax/${gax.version}`,
117 if (opts.libName && opts.libVersion) {
118 clientHeader.push(`${opts.libName}/${opts.libVersion}`);
121 // Load the applicable protos.
122 const protos = merge(
125 path.join(__dirname, '..', '..', 'protos'),
126 'google/cloud/dialogflow/v2beta1/intent.proto'
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'
137 intentPathTemplate: new gax.PathTemplate(
138 'projects/{project}/agent/intents/{intent}'
142 // Some of the methods on this service return "paged" results,
143 // (e.g. 50 results at a time, with tokens to get subsequent
144 // pages). Denote the keys used for pagination and results.
145 this._descriptors.page = {
146 listIntents: new gax.PageDescriptor(
152 let protoFilesRoot = new gax.GoogleProtoFilesRoot();
153 protoFilesRoot = protobuf.loadSync(
159 'google/cloud/dialogflow/v2beta1/intent.proto'
164 // This API contains "long-running operations", which return a
165 // an Operation object that allows for tracking of the operation,
166 // rather than holding a request open.
167 this.operationsClient = new gax.lro({
170 }).operationsClient(opts);
172 const batchUpdateIntentsResponse = protoFilesRoot.lookup(
173 'google.cloud.dialogflow.v2beta1.BatchUpdateIntentsResponse'
175 const batchUpdateIntentsMetadata = protoFilesRoot.lookup(
176 'google.protobuf.Struct'
178 const batchDeleteIntentsResponse = protoFilesRoot.lookup(
179 'google.protobuf.Empty'
181 const batchDeleteIntentsMetadata = protoFilesRoot.lookup(
182 'google.protobuf.Struct'
185 this._descriptors.longrunning = {
186 batchUpdateIntents: new gax.LongrunningDescriptor(
187 this.operationsClient,
188 batchUpdateIntentsResponse.decode.bind(batchUpdateIntentsResponse),
189 batchUpdateIntentsMetadata.decode.bind(batchUpdateIntentsMetadata)
191 batchDeleteIntents: new gax.LongrunningDescriptor(
192 this.operationsClient,
193 batchDeleteIntentsResponse.decode.bind(batchDeleteIntentsResponse),
194 batchDeleteIntentsMetadata.decode.bind(batchDeleteIntentsMetadata)
198 // Put together the default options sent with requests.
199 const defaults = gaxGrpc.constructSettings(
200 'google.cloud.dialogflow.v2beta1.Intents',
203 {'x-goog-api-client': clientHeader.join(' ')}
206 // Set up a dictionary of "inner API calls"; the core implementation
207 // of calling the API is handled in `google-gax`, with this code
208 // merely providing the destination and request information.
209 this._innerApiCalls = {};
211 // Put together the "service stub" for
212 // google.cloud.dialogflow.v2beta1.Intents.
213 const intentsStub = gaxGrpc.createStub(
214 protos.google.cloud.dialogflow.v2beta1.Intents,
218 // Iterate over each of the methods that the service provides
219 // and create an API call method for each.
220 const intentsStubMethods = [
226 'batchUpdateIntents',
227 'batchDeleteIntents',
229 for (const methodName of intentsStubMethods) {
230 this._innerApiCalls[methodName] = gax.createApiCall(
234 const args = Array.prototype.slice.call(arguments, 0);
235 return stub[methodName].apply(stub, args);
242 defaults[methodName],
243 this._descriptors.page[methodName] ||
244 this._descriptors.longrunning[methodName]
250 * The DNS address for this API service.
252 static get servicePath() {
253 return 'dialogflow.googleapis.com';
257 * The port for this API service.
264 * The scopes needed to make gRPC calls for every method defined
267 static get scopes() {
268 return ['https://www.googleapis.com/auth/cloud-platform'];
272 * Return the project ID used by this class.
273 * @param {function(Error, string)} callback - the callback to
274 * be called with the current project Id.
276 getProjectId(callback) {
277 return this.auth.getProjectId(callback);
280 // -------------------
281 // -- Service calls --
282 // -------------------
285 * Returns the list of all intents in the specified agent.
287 * @param {Object} request
288 * The request object that will be sent.
289 * @param {string} request.parent
290 * Required. The agent to list all intents from.
291 * Format: `projects/<Project ID>/agent`.
292 * @param {string} [request.languageCode]
293 * Optional. The language to list training phrases, parameters and rich
294 * messages for. If not specified, the agent's default language is used.
296 * languages](https://dialogflow.com/docs/reference/language) are supported.
297 * Note: languages must be enabled in the agent before they can be used.
298 * @param {number} [request.intentView]
299 * Optional. The resource view to apply to the returned intent.
301 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
302 * @param {number} [request.pageSize]
303 * The maximum number of resources contained in the underlying API
304 * response. If page streaming is performed per-resource, this
305 * parameter does not affect the return value. If page streaming is
306 * performed per-page, this determines the maximum number of
307 * resources in a page.
308 * @param {Object} [options]
309 * Optional parameters. You can override the default settings for this call, e.g, timeout,
310 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
311 * @param {function(?Error, ?Array, ?Object, ?Object)} [callback]
312 * The function which will be called with the result of the API call.
314 * The second parameter to the callback is Array of [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
316 * When autoPaginate: false is specified through options, it contains the result
317 * in a single response. If the response indicates the next page exists, the third
318 * parameter is set to be used for the next request object. The fourth parameter keeps
319 * the raw response object of an object representing [ListIntentsResponse]{@link google.cloud.dialogflow.v2beta1.ListIntentsResponse}.
320 * @returns {Promise} - The promise which resolves to an array.
321 * The first element of the array is Array of [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
323 * When autoPaginate: false is specified through options, the array has three elements.
324 * The first element is Array of [Intent]{@link google.cloud.dialogflow.v2beta1.Intent} in a single response.
325 * The second element is the next request object if the response
326 * indicates the next page exists, or null. The third element is
327 * an object representing [ListIntentsResponse]{@link google.cloud.dialogflow.v2beta1.ListIntentsResponse}.
329 * The promise has a method named "cancel" which cancels the ongoing API call.
333 * const dialogflow = require('dialogflow');
335 * const client = new dialogflow.v2beta1.IntentsClient({
336 * // optional auth parameters.
339 * // Iterate over all elements.
340 * const formattedParent = client.projectAgentPath('[PROJECT]');
342 * client.listIntents({parent: formattedParent})
343 * .then(responses => {
344 * const resources = responses[0];
345 * for (const resource of resources) {
346 * // doThingsWith(resource)
350 * console.error(err);
353 * // Or obtain the paged response.
354 * const formattedParent = client.projectAgentPath('[PROJECT]');
357 * const options = {autoPaginate: false};
358 * const callback = responses => {
359 * // The actual resources in a response.
360 * const resources = responses[0];
361 * // The next request if the response shows that there are more responses.
362 * const nextRequest = responses[1];
363 * // The actual response object, if necessary.
364 * // const rawResponse = responses[2];
365 * for (const resource of resources) {
366 * // doThingsWith(resource);
369 * // Fetch the next page.
370 * return client.listIntents(nextRequest, options).then(callback);
373 * client.listIntents({parent: formattedParent}, options)
376 * console.error(err);
379 listIntents(request, options, callback) {
380 if (options instanceof Function && callback === undefined) {
384 options = options || {};
386 return this._innerApiCalls.listIntents(request, options, callback);
390 * Equivalent to {@link listIntents}, but returns a NodeJS Stream object.
392 * This fetches the paged responses for {@link listIntents} continuously
393 * and invokes the callback registered for 'data' event for each element in the
396 * The returned object has 'end' method when no more elements are required.
398 * autoPaginate option will be ignored.
400 * @see {@link https://nodejs.org/api/stream.html}
402 * @param {Object} request
403 * The request object that will be sent.
404 * @param {string} request.parent
405 * Required. The agent to list all intents from.
406 * Format: `projects/<Project ID>/agent`.
407 * @param {string} [request.languageCode]
408 * Optional. The language to list training phrases, parameters and rich
409 * messages for. If not specified, the agent's default language is used.
411 * languages](https://dialogflow.com/docs/reference/language) are supported.
412 * Note: languages must be enabled in the agent before they can be used.
413 * @param {number} [request.intentView]
414 * Optional. The resource view to apply to the returned intent.
416 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
417 * @param {number} [request.pageSize]
418 * The maximum number of resources contained in the underlying API
419 * response. If page streaming is performed per-resource, this
420 * parameter does not affect the return value. If page streaming is
421 * performed per-page, this determines the maximum number of
422 * resources in a page.
423 * @param {Object} [options]
424 * Optional parameters. You can override the default settings for this call, e.g, timeout,
425 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
427 * An object stream which emits an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent} on 'data' event.
431 * const dialogflow = require('dialogflow');
433 * const client = new dialogflow.v2beta1.IntentsClient({
434 * // optional auth parameters.
437 * const formattedParent = client.projectAgentPath('[PROJECT]');
438 * client.listIntentsStream({parent: formattedParent})
439 * .on('data', element => {
440 * // doThingsWith(element)
441 * }).on('error', err => {
445 listIntentsStream(request, options) {
446 options = options || {};
448 return this._descriptors.page.listIntents.createStream(
449 this._innerApiCalls.listIntents,
456 * Retrieves the specified intent.
458 * @param {Object} request
459 * The request object that will be sent.
460 * @param {string} request.name
461 * Required. The name of the intent.
462 * Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
463 * @param {string} [request.languageCode]
464 * Optional. The language to retrieve training phrases, parameters and rich
465 * messages for. If not specified, the agent's default language is used.
467 * languages](https://dialogflow.com/docs/reference/language) are supported.
468 * Note: languages must be enabled in the agent, before they can be used.
469 * @param {number} [request.intentView]
470 * Optional. The resource view to apply to the returned intent.
472 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
473 * @param {Object} [options]
474 * Optional parameters. You can override the default settings for this call, e.g, timeout,
475 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
476 * @param {function(?Error, ?Object)} [callback]
477 * The function which will be called with the result of the API call.
479 * The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
480 * @returns {Promise} - The promise which resolves to an array.
481 * The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
482 * The promise has a method named "cancel" which cancels the ongoing API call.
486 * const dialogflow = require('dialogflow');
488 * const client = new dialogflow.v2beta1.IntentsClient({
489 * // optional auth parameters.
492 * const formattedName = client.intentPath('[PROJECT]', '[INTENT]');
493 * client.getIntent({name: formattedName})
494 * .then(responses => {
495 * const response = responses[0];
496 * // doThingsWith(response)
499 * console.error(err);
502 getIntent(request, options, callback) {
503 if (options instanceof Function && callback === undefined) {
507 options = options || {};
509 return this._innerApiCalls.getIntent(request, options, callback);
513 * Creates an intent in the specified agent.
515 * @param {Object} request
516 * The request object that will be sent.
517 * @param {string} request.parent
518 * Required. The agent to create a intent for.
519 * Format: `projects/<Project ID>/agent`.
520 * @param {Object} request.intent
521 * Required. The intent to create.
523 * This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}
524 * @param {string} [request.languageCode]
525 * Optional. The language of training phrases, parameters and rich messages
526 * defined in `intent`. If not specified, the agent's default language is
527 * used. [More than a dozen
528 * languages](https://dialogflow.com/docs/reference/language) are supported.
529 * Note: languages must be enabled in the agent, before they can be used.
530 * @param {number} [request.intentView]
531 * Optional. The resource view to apply to the returned intent.
533 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
534 * @param {Object} [options]
535 * Optional parameters. You can override the default settings for this call, e.g, timeout,
536 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
537 * @param {function(?Error, ?Object)} [callback]
538 * The function which will be called with the result of the API call.
540 * The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
541 * @returns {Promise} - The promise which resolves to an array.
542 * The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
543 * The promise has a method named "cancel" which cancels the ongoing API call.
547 * const dialogflow = require('dialogflow');
549 * const client = new dialogflow.v2beta1.IntentsClient({
550 * // optional auth parameters.
553 * const formattedParent = client.projectAgentPath('[PROJECT]');
556 * parent: formattedParent,
559 * client.createIntent(request)
560 * .then(responses => {
561 * const response = responses[0];
562 * // doThingsWith(response)
565 * console.error(err);
568 createIntent(request, options, callback) {
569 if (options instanceof Function && callback === undefined) {
573 options = options || {};
575 return this._innerApiCalls.createIntent(request, options, callback);
579 * Updates the specified intent.
581 * @param {Object} request
582 * The request object that will be sent.
583 * @param {Object} request.intent
584 * Required. The intent to update.
585 * Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
587 * This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}
588 * @param {string} request.languageCode
589 * Optional. The language of training phrases, parameters and rich messages
590 * defined in `intent`. If not specified, the agent's default language is
591 * used. [More than a dozen
592 * languages](https://dialogflow.com/docs/reference/language) are supported.
593 * Note: languages must be enabled in the agent, before they can be used.
594 * @param {Object} [request.updateMask]
595 * Optional. The mask to control which fields get updated.
597 * This object should have the same structure as [FieldMask]{@link google.protobuf.FieldMask}
598 * @param {number} [request.intentView]
599 * Optional. The resource view to apply to the returned intent.
601 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
602 * @param {Object} [options]
603 * Optional parameters. You can override the default settings for this call, e.g, timeout,
604 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
605 * @param {function(?Error, ?Object)} [callback]
606 * The function which will be called with the result of the API call.
608 * The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
609 * @returns {Promise} - The promise which resolves to an array.
610 * The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}.
611 * The promise has a method named "cancel" which cancels the ongoing API call.
615 * const dialogflow = require('dialogflow');
617 * const client = new dialogflow.v2beta1.IntentsClient({
618 * // optional auth parameters.
622 * const languageCode = '';
625 * languageCode: languageCode,
627 * client.updateIntent(request)
628 * .then(responses => {
629 * const response = responses[0];
630 * // doThingsWith(response)
633 * console.error(err);
636 updateIntent(request, options, callback) {
637 if (options instanceof Function && callback === undefined) {
641 options = options || {};
643 return this._innerApiCalls.updateIntent(request, options, callback);
647 * Deletes the specified intent.
649 * @param {Object} request
650 * The request object that will be sent.
651 * @param {string} request.name
652 * Required. The name of the intent to delete.
653 * Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
654 * @param {Object} [options]
655 * Optional parameters. You can override the default settings for this call, e.g, timeout,
656 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
657 * @param {function(?Error)} [callback]
658 * The function which will be called with the result of the API call.
659 * @returns {Promise} - The promise which resolves when API call finishes.
660 * The promise has a method named "cancel" which cancels the ongoing API call.
664 * const dialogflow = require('dialogflow');
666 * const client = new dialogflow.v2beta1.IntentsClient({
667 * // optional auth parameters.
670 * const formattedName = client.intentPath('[PROJECT]', '[INTENT]');
671 * client.deleteIntent({name: formattedName}).catch(err => {
672 * console.error(err);
675 deleteIntent(request, options, callback) {
676 if (options instanceof Function && callback === undefined) {
680 options = options || {};
682 return this._innerApiCalls.deleteIntent(request, options, callback);
686 * Updates/Creates multiple intents in the specified agent.
688 * Operation <response:
689 * BatchUpdateIntentsResponse>
691 * @param {Object} request
692 * The request object that will be sent.
693 * @param {string} request.parent
694 * Required. The name of the agent to update or create intents in.
695 * Format: `projects/<Project ID>/agent`.
696 * @param {string} request.languageCode
697 * Optional. The language of training phrases, parameters and rich messages
698 * defined in `intents`. If not specified, the agent's default language is
699 * used. [More than a dozen
700 * languages](https://dialogflow.com/docs/reference/language) are supported.
701 * Note: languages must be enabled in the agent, before they can be used.
702 * @param {string} [request.intentBatchUri]
703 * The URI to a Google Cloud Storage file containing intents to update or
704 * create. The file format can either be a serialized proto (of IntentBatch
705 * type) or JSON object. Note: The URI must start with "gs://".
706 * @param {Object} [request.intentBatchInline]
707 * The collection of intents to update or create.
709 * This object should have the same structure as [IntentBatch]{@link google.cloud.dialogflow.v2beta1.IntentBatch}
710 * @param {Object} [request.updateMask]
711 * Optional. The mask to control which fields get updated.
713 * This object should have the same structure as [FieldMask]{@link google.protobuf.FieldMask}
714 * @param {number} [request.intentView]
715 * Optional. The resource view to apply to the returned intent.
717 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2beta1.IntentView}
718 * @param {Object} [options]
719 * Optional parameters. You can override the default settings for this call, e.g, timeout,
720 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
721 * @param {function(?Error, ?Object)} [callback]
722 * The function which will be called with the result of the API call.
724 * The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
725 * @returns {Promise} - The promise which resolves to an array.
726 * The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
727 * The promise has a method named "cancel" which cancels the ongoing API call.
731 * const dialogflow = require('dialogflow');
733 * const client = new dialogflow.v2beta1.IntentsClient({
734 * // optional auth parameters.
737 * const formattedParent = client.projectAgentPath('[PROJECT]');
738 * const languageCode = '';
740 * parent: formattedParent,
741 * languageCode: languageCode,
744 * // Handle the operation using the promise pattern.
745 * client.batchUpdateIntents(request)
746 * .then(responses => {
747 * const [operation, initialApiResponse] = responses;
749 * // Operation#promise starts polling for the completion of the LRO.
750 * return operation.promise();
752 * .then(responses => {
753 * const result = responses[0];
754 * const metadata = responses[1];
755 * const finalApiResponse = responses[2];
758 * console.error(err);
761 * const formattedParent = client.projectAgentPath('[PROJECT]');
762 * const languageCode = '';
764 * parent: formattedParent,
765 * languageCode: languageCode,
768 * // Handle the operation using the event emitter pattern.
769 * client.batchUpdateIntents(request)
770 * .then(responses => {
771 * const [operation, initialApiResponse] = responses;
773 * // Adding a listener for the "complete" event starts polling for the
774 * // completion of the operation.
775 * operation.on('complete', (result, metadata, finalApiResponse) => {
776 * // doSomethingWith(result);
779 * // Adding a listener for the "progress" event causes the callback to be
780 * // called on any change in metadata when the operation is polled.
781 * operation.on('progress', (metadata, apiResponse) => {
782 * // doSomethingWith(metadata)
785 * // Adding a listener for the "error" event handles any errors found during polling.
786 * operation.on('error', err => {
791 * console.error(err);
794 * const formattedParent = client.projectAgentPath('[PROJECT]');
795 * const languageCode = '';
797 * parent: formattedParent,
798 * languageCode: languageCode,
801 * // Handle the operation using the await pattern.
802 * const [operation] = await client.batchUpdateIntents(request);
804 * const [response] = await operation.promise();
806 batchUpdateIntents(request, options, callback) {
807 if (options instanceof Function && callback === undefined) {
811 options = options || {};
813 return this._innerApiCalls.batchUpdateIntents(request, options, callback);
817 * Deletes intents in the specified agent.
819 * Operation <response: google.protobuf.Empty>
821 * @param {Object} request
822 * The request object that will be sent.
823 * @param {string} request.parent
824 * Required. The name of the agent to delete all entities types for. Format:
825 * `projects/<Project ID>/agent`.
826 * @param {Object[]} request.intents
827 * Required. The collection of intents to delete. Only intent `name` must be
830 * This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2beta1.Intent}
831 * @param {Object} [options]
832 * Optional parameters. You can override the default settings for this call, e.g, timeout,
833 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
834 * @param {function(?Error, ?Object)} [callback]
835 * The function which will be called with the result of the API call.
837 * The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
838 * @returns {Promise} - The promise which resolves to an array.
839 * The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
840 * The promise has a method named "cancel" which cancels the ongoing API call.
844 * const dialogflow = require('dialogflow');
846 * const client = new dialogflow.v2beta1.IntentsClient({
847 * // optional auth parameters.
850 * const formattedParent = client.projectAgentPath('[PROJECT]');
851 * const intents = [];
853 * parent: formattedParent,
857 * // Handle the operation using the promise pattern.
858 * client.batchDeleteIntents(request)
859 * .then(responses => {
860 * const [operation, initialApiResponse] = responses;
862 * // Operation#promise starts polling for the completion of the LRO.
863 * return operation.promise();
865 * .then(responses => {
866 * const result = responses[0];
867 * const metadata = responses[1];
868 * const finalApiResponse = responses[2];
871 * console.error(err);
874 * const formattedParent = client.projectAgentPath('[PROJECT]');
875 * const intents = [];
877 * parent: formattedParent,
881 * // Handle the operation using the event emitter pattern.
882 * client.batchDeleteIntents(request)
883 * .then(responses => {
884 * const [operation, initialApiResponse] = responses;
886 * // Adding a listener for the "complete" event starts polling for the
887 * // completion of the operation.
888 * operation.on('complete', (result, metadata, finalApiResponse) => {
889 * // doSomethingWith(result);
892 * // Adding a listener for the "progress" event causes the callback to be
893 * // called on any change in metadata when the operation is polled.
894 * operation.on('progress', (metadata, apiResponse) => {
895 * // doSomethingWith(metadata)
898 * // Adding a listener for the "error" event handles any errors found during polling.
899 * operation.on('error', err => {
904 * console.error(err);
907 * const formattedParent = client.projectAgentPath('[PROJECT]');
908 * const intents = [];
910 * parent: formattedParent,
914 * // Handle the operation using the await pattern.
915 * const [operation] = await client.batchDeleteIntents(request);
917 * const [response] = await operation.promise();
919 batchDeleteIntents(request, options, callback) {
920 if (options instanceof Function && callback === undefined) {
924 options = options || {};
926 return this._innerApiCalls.batchDeleteIntents(request, options, callback);
929 // --------------------
930 // -- Path templates --
931 // --------------------
934 * Return a fully-qualified project_agent resource name string.
936 * @param {String} project
939 projectAgentPath(project) {
940 return this._pathTemplates.projectAgentPathTemplate.render({
946 * Return a fully-qualified intent resource name string.
948 * @param {String} project
949 * @param {String} intent
952 intentPath(project, intent) {
953 return this._pathTemplates.intentPathTemplate.render({
960 * Parse the projectAgentName from a project_agent resource.
962 * @param {String} projectAgentName
963 * A fully-qualified path representing a project_agent resources.
964 * @returns {String} - A string representing the project.
966 matchProjectFromProjectAgentName(projectAgentName) {
967 return this._pathTemplates.projectAgentPathTemplate.match(projectAgentName)
972 * Parse the intentName from a intent resource.
974 * @param {String} intentName
975 * A fully-qualified path representing a intent resources.
976 * @returns {String} - A string representing the project.
978 matchProjectFromIntentName(intentName) {
979 return this._pathTemplates.intentPathTemplate.match(intentName).project;
983 * Parse the intentName from a intent resource.
985 * @param {String} intentName
986 * A fully-qualified path representing a intent resources.
987 * @returns {String} - A string representing the intent.
989 matchIntentFromIntentName(intentName) {
990 return this._pathTemplates.intentPathTemplate.match(intentName).intent;
994 module.exports = IntentsClient;