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/v2/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}'
140 agentPathTemplate: new gax.PathTemplate(
141 'projects/{project}/agents/{agent}'
145 // Some of the methods on this service return "paged" results,
146 // (e.g. 50 results at a time, with tokens to get subsequent
147 // pages). Denote the keys used for pagination and results.
148 this._descriptors.page = {
149 listIntents: new gax.PageDescriptor(
155 let protoFilesRoot = new gax.GoogleProtoFilesRoot();
156 protoFilesRoot = protobuf.loadSync(
162 'google/cloud/dialogflow/v2/intent.proto'
167 // This API contains "long-running operations", which return a
168 // an Operation object that allows for tracking of the operation,
169 // rather than holding a request open.
170 this.operationsClient = new gax.lro({
173 }).operationsClient(opts);
175 const batchUpdateIntentsResponse = protoFilesRoot.lookup(
176 'google.cloud.dialogflow.v2.BatchUpdateIntentsResponse'
178 const batchUpdateIntentsMetadata = protoFilesRoot.lookup(
179 'google.protobuf.Struct'
181 const batchDeleteIntentsResponse = protoFilesRoot.lookup(
182 'google.protobuf.Empty'
184 const batchDeleteIntentsMetadata = protoFilesRoot.lookup(
185 'google.protobuf.Struct'
188 this._descriptors.longrunning = {
189 batchUpdateIntents: new gax.LongrunningDescriptor(
190 this.operationsClient,
191 batchUpdateIntentsResponse.decode.bind(batchUpdateIntentsResponse),
192 batchUpdateIntentsMetadata.decode.bind(batchUpdateIntentsMetadata)
194 batchDeleteIntents: new gax.LongrunningDescriptor(
195 this.operationsClient,
196 batchDeleteIntentsResponse.decode.bind(batchDeleteIntentsResponse),
197 batchDeleteIntentsMetadata.decode.bind(batchDeleteIntentsMetadata)
201 // Put together the default options sent with requests.
202 const defaults = gaxGrpc.constructSettings(
203 'google.cloud.dialogflow.v2.Intents',
206 {'x-goog-api-client': clientHeader.join(' ')}
209 // Set up a dictionary of "inner API calls"; the core implementation
210 // of calling the API is handled in `google-gax`, with this code
211 // merely providing the destination and request information.
212 this._innerApiCalls = {};
214 // Put together the "service stub" for
215 // google.cloud.dialogflow.v2.Intents.
216 const intentsStub = gaxGrpc.createStub(
217 protos.google.cloud.dialogflow.v2.Intents,
221 // Iterate over each of the methods that the service provides
222 // and create an API call method for each.
223 const intentsStubMethods = [
229 'batchUpdateIntents',
230 'batchDeleteIntents',
232 for (const methodName of intentsStubMethods) {
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 * Returns the list of all intents in the specified agent.
290 * @param {Object} request
291 * The request object that will be sent.
292 * @param {string} request.parent
293 * Required. The agent to list all intents from.
294 * Format: `projects/<Project ID>/agent`.
295 * @param {string} [request.languageCode]
296 * Optional. The language to list training phrases, parameters and rich
297 * messages for. If not specified, the agent's default language is used.
299 * languages](https://dialogflow.com/docs/reference/language) are supported.
300 * Note: languages must be enabled in the agent before they can be used.
301 * @param {number} [request.intentView]
302 * Optional. The resource view to apply to the returned intent.
304 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2.IntentView}
305 * @param {number} [request.pageSize]
306 * The maximum number of resources contained in the underlying API
307 * response. If page streaming is performed per-resource, this
308 * parameter does not affect the return value. If page streaming is
309 * performed per-page, this determines the maximum number of
310 * resources in a page.
311 * @param {Object} [options]
312 * Optional parameters. You can override the default settings for this call, e.g, timeout,
313 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
314 * @param {function(?Error, ?Array, ?Object, ?Object)} [callback]
315 * The function which will be called with the result of the API call.
317 * The second parameter to the callback is Array of [Intent]{@link google.cloud.dialogflow.v2.Intent}.
319 * When autoPaginate: false is specified through options, it contains the result
320 * in a single response. If the response indicates the next page exists, the third
321 * parameter is set to be used for the next request object. The fourth parameter keeps
322 * the raw response object of an object representing [ListIntentsResponse]{@link google.cloud.dialogflow.v2.ListIntentsResponse}.
323 * @returns {Promise} - The promise which resolves to an array.
324 * The first element of the array is Array of [Intent]{@link google.cloud.dialogflow.v2.Intent}.
326 * When autoPaginate: false is specified through options, the array has three elements.
327 * The first element is Array of [Intent]{@link google.cloud.dialogflow.v2.Intent} in a single response.
328 * The second element is the next request object if the response
329 * indicates the next page exists, or null. The third element is
330 * an object representing [ListIntentsResponse]{@link google.cloud.dialogflow.v2.ListIntentsResponse}.
332 * The promise has a method named "cancel" which cancels the ongoing API call.
336 * const dialogflow = require('dialogflow');
338 * const client = new dialogflow.v2.IntentsClient({
339 * // optional auth parameters.
342 * // Iterate over all elements.
343 * const formattedParent = client.projectAgentPath('[PROJECT]');
345 * client.listIntents({parent: formattedParent})
346 * .then(responses => {
347 * const resources = responses[0];
348 * for (const resource of resources) {
349 * // doThingsWith(resource)
353 * console.error(err);
356 * // Or obtain the paged response.
357 * const formattedParent = client.projectAgentPath('[PROJECT]');
360 * const options = {autoPaginate: false};
361 * const callback = responses => {
362 * // The actual resources in a response.
363 * const resources = responses[0];
364 * // The next request if the response shows that there are more responses.
365 * const nextRequest = responses[1];
366 * // The actual response object, if necessary.
367 * // const rawResponse = responses[2];
368 * for (const resource of resources) {
369 * // doThingsWith(resource);
372 * // Fetch the next page.
373 * return client.listIntents(nextRequest, options).then(callback);
376 * client.listIntents({parent: formattedParent}, options)
379 * console.error(err);
382 listIntents(request, options, callback) {
383 if (options instanceof Function && callback === undefined) {
387 options = options || {};
389 return this._innerApiCalls.listIntents(request, options, callback);
393 * Equivalent to {@link listIntents}, but returns a NodeJS Stream object.
395 * This fetches the paged responses for {@link listIntents} continuously
396 * and invokes the callback registered for 'data' event for each element in the
399 * The returned object has 'end' method when no more elements are required.
401 * autoPaginate option will be ignored.
403 * @see {@link https://nodejs.org/api/stream.html}
405 * @param {Object} request
406 * The request object that will be sent.
407 * @param {string} request.parent
408 * Required. The agent to list all intents from.
409 * Format: `projects/<Project ID>/agent`.
410 * @param {string} [request.languageCode]
411 * Optional. The language to list training phrases, parameters and rich
412 * messages for. If not specified, the agent's default language is used.
414 * languages](https://dialogflow.com/docs/reference/language) are supported.
415 * Note: languages must be enabled in the agent before they can be used.
416 * @param {number} [request.intentView]
417 * Optional. The resource view to apply to the returned intent.
419 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2.IntentView}
420 * @param {number} [request.pageSize]
421 * The maximum number of resources contained in the underlying API
422 * response. If page streaming is performed per-resource, this
423 * parameter does not affect the return value. If page streaming is
424 * performed per-page, this determines the maximum number of
425 * resources in a page.
426 * @param {Object} [options]
427 * Optional parameters. You can override the default settings for this call, e.g, timeout,
428 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
430 * An object stream which emits an object representing [Intent]{@link google.cloud.dialogflow.v2.Intent} on 'data' event.
434 * const dialogflow = require('dialogflow');
436 * const client = new dialogflow.v2.IntentsClient({
437 * // optional auth parameters.
440 * const formattedParent = client.projectAgentPath('[PROJECT]');
441 * client.listIntentsStream({parent: formattedParent})
442 * .on('data', element => {
443 * // doThingsWith(element)
444 * }).on('error', err => {
448 listIntentsStream(request, options) {
449 options = options || {};
451 return this._descriptors.page.listIntents.createStream(
452 this._innerApiCalls.listIntents,
459 * Retrieves the specified intent.
461 * @param {Object} request
462 * The request object that will be sent.
463 * @param {string} request.name
464 * Required. The name of the intent.
465 * Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
466 * @param {string} [request.languageCode]
467 * Optional. The language to retrieve training phrases, parameters and rich
468 * messages for. If not specified, the agent's default language is used.
470 * languages](https://dialogflow.com/docs/reference/language) are supported.
471 * Note: languages must be enabled in the agent, before they can be used.
472 * @param {number} [request.intentView]
473 * Optional. The resource view to apply to the returned intent.
475 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2.IntentView}
476 * @param {Object} [options]
477 * Optional parameters. You can override the default settings for this call, e.g, timeout,
478 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
479 * @param {function(?Error, ?Object)} [callback]
480 * The function which will be called with the result of the API call.
482 * The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2.Intent}.
483 * @returns {Promise} - The promise which resolves to an array.
484 * The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2.Intent}.
485 * The promise has a method named "cancel" which cancels the ongoing API call.
489 * const dialogflow = require('dialogflow');
491 * const client = new dialogflow.v2.IntentsClient({
492 * // optional auth parameters.
495 * const formattedName = client.intentPath('[PROJECT]', '[INTENT]');
496 * client.getIntent({name: formattedName})
497 * .then(responses => {
498 * const response = responses[0];
499 * // doThingsWith(response)
502 * console.error(err);
505 getIntent(request, options, callback) {
506 if (options instanceof Function && callback === undefined) {
510 options = options || {};
512 return this._innerApiCalls.getIntent(request, options, callback);
516 * Creates an intent in the specified agent.
518 * @param {Object} request
519 * The request object that will be sent.
520 * @param {string} request.parent
521 * Required. The agent to create a intent for.
522 * Format: `projects/<Project ID>/agent`.
523 * @param {Object} request.intent
524 * Required. The intent to create.
526 * This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2.Intent}
527 * @param {string} [request.languageCode]
528 * Optional. The language of training phrases, parameters and rich messages
529 * defined in `intent`. If not specified, the agent's default language is
530 * used. [More than a dozen
531 * languages](https://dialogflow.com/docs/reference/language) are supported.
532 * Note: languages must be enabled in the agent, before they can be used.
533 * @param {number} [request.intentView]
534 * Optional. The resource view to apply to the returned intent.
536 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2.IntentView}
537 * @param {Object} [options]
538 * Optional parameters. You can override the default settings for this call, e.g, timeout,
539 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
540 * @param {function(?Error, ?Object)} [callback]
541 * The function which will be called with the result of the API call.
543 * The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2.Intent}.
544 * @returns {Promise} - The promise which resolves to an array.
545 * The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2.Intent}.
546 * The promise has a method named "cancel" which cancels the ongoing API call.
550 * const dialogflow = require('dialogflow');
552 * const client = new dialogflow.v2.IntentsClient({
553 * // optional auth parameters.
556 * const formattedParent = client.projectAgentPath('[PROJECT]');
559 * parent: formattedParent,
562 * client.createIntent(request)
563 * .then(responses => {
564 * const response = responses[0];
565 * // doThingsWith(response)
568 * console.error(err);
571 createIntent(request, options, callback) {
572 if (options instanceof Function && callback === undefined) {
576 options = options || {};
578 return this._innerApiCalls.createIntent(request, options, callback);
582 * Updates the specified intent.
584 * @param {Object} request
585 * The request object that will be sent.
586 * @param {Object} request.intent
587 * Required. The intent to update.
588 * Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
590 * This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2.Intent}
591 * @param {string} request.languageCode
592 * Optional. The language of training phrases, parameters and rich messages
593 * defined in `intent`. If not specified, the agent's default language is
594 * used. [More than a dozen
595 * languages](https://dialogflow.com/docs/reference/language) are supported.
596 * Note: languages must be enabled in the agent, before they can be used.
597 * @param {Object} [request.updateMask]
598 * Optional. The mask to control which fields get updated.
600 * This object should have the same structure as [FieldMask]{@link google.protobuf.FieldMask}
601 * @param {number} [request.intentView]
602 * Optional. The resource view to apply to the returned intent.
604 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2.IntentView}
605 * @param {Object} [options]
606 * Optional parameters. You can override the default settings for this call, e.g, timeout,
607 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
608 * @param {function(?Error, ?Object)} [callback]
609 * The function which will be called with the result of the API call.
611 * The second parameter to the callback is an object representing [Intent]{@link google.cloud.dialogflow.v2.Intent}.
612 * @returns {Promise} - The promise which resolves to an array.
613 * The first element of the array is an object representing [Intent]{@link google.cloud.dialogflow.v2.Intent}.
614 * The promise has a method named "cancel" which cancels the ongoing API call.
618 * const dialogflow = require('dialogflow');
620 * const client = new dialogflow.v2.IntentsClient({
621 * // optional auth parameters.
625 * const languageCode = '';
628 * languageCode: languageCode,
630 * client.updateIntent(request)
631 * .then(responses => {
632 * const response = responses[0];
633 * // doThingsWith(response)
636 * console.error(err);
639 updateIntent(request, options, callback) {
640 if (options instanceof Function && callback === undefined) {
644 options = options || {};
646 return this._innerApiCalls.updateIntent(request, options, callback);
650 * Deletes the specified intent.
652 * @param {Object} request
653 * The request object that will be sent.
654 * @param {string} request.name
655 * Required. The name of the intent to delete.
656 * Format: `projects/<Project ID>/agent/intents/<Intent ID>`.
657 * @param {Object} [options]
658 * Optional parameters. You can override the default settings for this call, e.g, timeout,
659 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
660 * @param {function(?Error)} [callback]
661 * The function which will be called with the result of the API call.
662 * @returns {Promise} - The promise which resolves when API call finishes.
663 * The promise has a method named "cancel" which cancels the ongoing API call.
667 * const dialogflow = require('dialogflow');
669 * const client = new dialogflow.v2.IntentsClient({
670 * // optional auth parameters.
673 * const formattedName = client.intentPath('[PROJECT]', '[INTENT]');
674 * client.deleteIntent({name: formattedName}).catch(err => {
675 * console.error(err);
678 deleteIntent(request, options, callback) {
679 if (options instanceof Function && callback === undefined) {
683 options = options || {};
685 return this._innerApiCalls.deleteIntent(request, options, callback);
689 * Updates/Creates multiple intents in the specified agent.
691 * Operation <response:
692 * BatchUpdateIntentsResponse>
694 * @param {Object} request
695 * The request object that will be sent.
696 * @param {string} request.parent
697 * Required. The name of the agent to update or create intents in.
698 * Format: `projects/<Project ID>/agent`.
699 * @param {string} request.languageCode
700 * Optional. The language of training phrases, parameters and rich messages
701 * defined in `intents`. If not specified, the agent's default language is
702 * used. [More than a dozen
703 * languages](https://dialogflow.com/docs/reference/language) are supported.
704 * Note: languages must be enabled in the agent, before they can be used.
705 * @param {string} [request.intentBatchUri]
706 * The URI to a Google Cloud Storage file containing intents to update or
707 * create. The file format can either be a serialized proto (of IntentBatch
708 * type) or JSON object. Note: The URI must start with "gs://".
709 * @param {Object} [request.intentBatchInline]
710 * The collection of intents to update or create.
712 * This object should have the same structure as [IntentBatch]{@link google.cloud.dialogflow.v2.IntentBatch}
713 * @param {Object} [request.updateMask]
714 * Optional. The mask to control which fields get updated.
716 * This object should have the same structure as [FieldMask]{@link google.protobuf.FieldMask}
717 * @param {number} [request.intentView]
718 * Optional. The resource view to apply to the returned intent.
720 * The number should be among the values of [IntentView]{@link google.cloud.dialogflow.v2.IntentView}
721 * @param {Object} [options]
722 * Optional parameters. You can override the default settings for this call, e.g, timeout,
723 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
724 * @param {function(?Error, ?Object)} [callback]
725 * The function which will be called with the result of the API call.
727 * The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
728 * @returns {Promise} - The promise which resolves to an array.
729 * The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
730 * The promise has a method named "cancel" which cancels the ongoing API call.
734 * const dialogflow = require('dialogflow');
736 * const client = new dialogflow.v2.IntentsClient({
737 * // optional auth parameters.
740 * const formattedParent = client.projectAgentPath('[PROJECT]');
741 * const languageCode = '';
743 * parent: formattedParent,
744 * languageCode: languageCode,
747 * // Handle the operation using the promise pattern.
748 * client.batchUpdateIntents(request)
749 * .then(responses => {
750 * const [operation, initialApiResponse] = responses;
752 * // Operation#promise starts polling for the completion of the LRO.
753 * return operation.promise();
755 * .then(responses => {
756 * const result = responses[0];
757 * const metadata = responses[1];
758 * const finalApiResponse = responses[2];
761 * console.error(err);
764 * const formattedParent = client.projectAgentPath('[PROJECT]');
765 * const languageCode = '';
767 * parent: formattedParent,
768 * languageCode: languageCode,
771 * // Handle the operation using the event emitter pattern.
772 * client.batchUpdateIntents(request)
773 * .then(responses => {
774 * const [operation, initialApiResponse] = responses;
776 * // Adding a listener for the "complete" event starts polling for the
777 * // completion of the operation.
778 * operation.on('complete', (result, metadata, finalApiResponse) => {
779 * // doSomethingWith(result);
782 * // Adding a listener for the "progress" event causes the callback to be
783 * // called on any change in metadata when the operation is polled.
784 * operation.on('progress', (metadata, apiResponse) => {
785 * // doSomethingWith(metadata)
788 * // Adding a listener for the "error" event handles any errors found during polling.
789 * operation.on('error', err => {
794 * console.error(err);
797 * const formattedParent = client.projectAgentPath('[PROJECT]');
798 * const languageCode = '';
800 * parent: formattedParent,
801 * languageCode: languageCode,
804 * // Handle the operation using the await pattern.
805 * const [operation] = await client.batchUpdateIntents(request);
807 * const [response] = await operation.promise();
809 batchUpdateIntents(request, options, callback) {
810 if (options instanceof Function && callback === undefined) {
814 options = options || {};
816 return this._innerApiCalls.batchUpdateIntents(request, options, callback);
820 * Deletes intents in the specified agent.
822 * Operation <response: google.protobuf.Empty>
824 * @param {Object} request
825 * The request object that will be sent.
826 * @param {string} request.parent
827 * Required. The name of the agent to delete all entities types for. Format:
828 * `projects/<Project ID>/agent`.
829 * @param {Object[]} request.intents
830 * Required. The collection of intents to delete. Only intent `name` must be
833 * This object should have the same structure as [Intent]{@link google.cloud.dialogflow.v2.Intent}
834 * @param {Object} [options]
835 * Optional parameters. You can override the default settings for this call, e.g, timeout,
836 * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
837 * @param {function(?Error, ?Object)} [callback]
838 * The function which will be called with the result of the API call.
840 * The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
841 * @returns {Promise} - The promise which resolves to an array.
842 * The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
843 * The promise has a method named "cancel" which cancels the ongoing API call.
847 * const dialogflow = require('dialogflow');
849 * const client = new dialogflow.v2.IntentsClient({
850 * // optional auth parameters.
853 * const formattedParent = client.projectAgentPath('[PROJECT]');
854 * const intents = [];
856 * parent: formattedParent,
860 * // Handle the operation using the promise pattern.
861 * client.batchDeleteIntents(request)
862 * .then(responses => {
863 * const [operation, initialApiResponse] = responses;
865 * // Operation#promise starts polling for the completion of the LRO.
866 * return operation.promise();
868 * .then(responses => {
869 * const result = responses[0];
870 * const metadata = responses[1];
871 * const finalApiResponse = responses[2];
874 * console.error(err);
877 * const formattedParent = client.projectAgentPath('[PROJECT]');
878 * const intents = [];
880 * parent: formattedParent,
884 * // Handle the operation using the event emitter pattern.
885 * client.batchDeleteIntents(request)
886 * .then(responses => {
887 * const [operation, initialApiResponse] = responses;
889 * // Adding a listener for the "complete" event starts polling for the
890 * // completion of the operation.
891 * operation.on('complete', (result, metadata, finalApiResponse) => {
892 * // doSomethingWith(result);
895 * // Adding a listener for the "progress" event causes the callback to be
896 * // called on any change in metadata when the operation is polled.
897 * operation.on('progress', (metadata, apiResponse) => {
898 * // doSomethingWith(metadata)
901 * // Adding a listener for the "error" event handles any errors found during polling.
902 * operation.on('error', err => {
907 * console.error(err);
910 * const formattedParent = client.projectAgentPath('[PROJECT]');
911 * const intents = [];
913 * parent: formattedParent,
917 * // Handle the operation using the await pattern.
918 * const [operation] = await client.batchDeleteIntents(request);
920 * const [response] = await operation.promise();
922 batchDeleteIntents(request, options, callback) {
923 if (options instanceof Function && callback === undefined) {
927 options = options || {};
929 return this._innerApiCalls.batchDeleteIntents(request, options, callback);
932 // --------------------
933 // -- Path templates --
934 // --------------------
937 * Return a fully-qualified project_agent resource name string.
939 * @param {String} project
942 projectAgentPath(project) {
943 return this._pathTemplates.projectAgentPathTemplate.render({
949 * Return a fully-qualified intent resource name string.
951 * @param {String} project
952 * @param {String} intent
955 intentPath(project, intent) {
956 return this._pathTemplates.intentPathTemplate.render({
963 * Return a fully-qualified agent resource name string.
965 * @param {String} project
966 * @param {String} agent
969 agentPath(project, agent) {
970 return this._pathTemplates.agentPathTemplate.render({
977 * Parse the projectAgentName from a project_agent resource.
979 * @param {String} projectAgentName
980 * A fully-qualified path representing a project_agent resources.
981 * @returns {String} - A string representing the project.
983 matchProjectFromProjectAgentName(projectAgentName) {
984 return this._pathTemplates.projectAgentPathTemplate.match(projectAgentName)
989 * Parse the intentName from a intent resource.
991 * @param {String} intentName
992 * A fully-qualified path representing a intent resources.
993 * @returns {String} - A string representing the project.
995 matchProjectFromIntentName(intentName) {
996 return this._pathTemplates.intentPathTemplate.match(intentName).project;
1000 * Parse the intentName from a intent resource.
1002 * @param {String} intentName
1003 * A fully-qualified path representing a intent resources.
1004 * @returns {String} - A string representing the intent.
1006 matchIntentFromIntentName(intentName) {
1007 return this._pathTemplates.intentPathTemplate.match(intentName).intent;
1011 * Parse the agentName from a agent resource.
1013 * @param {String} agentName
1014 * A fully-qualified path representing a agent resources.
1015 * @returns {String} - A string representing the project.
1017 matchProjectFromAgentName(agentName) {
1018 return this._pathTemplates.agentPathTemplate.match(agentName).project;
1022 * Parse the agentName from a agent resource.
1024 * @param {String} agentName
1025 * A fully-qualified path representing a agent resources.
1026 * @returns {String} - A string representing the agent.
1028 matchAgentFromAgentName(agentName) {
1029 return this._pathTemplates.agentPathTemplate.match(agentName).agent;
1033 module.exports = IntentsClient;