UNPKG

watson-developer-cloud

Version:
1,045 lines (1,044 loc) 150 kB
"use strict"; /** * Copyright 2018 IBM All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var extend = require("extend"); var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core"); var common_1 = require("../lib/common"); /** * The IBM Watson&trade; Assistant service combines machine learning, natural language understanding, and integrated dialog tools to create conversation flows between your apps and your users. */ var AssistantV1 = /** @class */ (function (_super) { __extends(AssistantV1, _super); /** * Construct a AssistantV1 object. * * @param {Object} options - Options for the service. * @param {string} options.version - The API version date to use with the service, in "YYYY-MM-DD" format. Whenever the API is changed in a backwards incompatible way, a new minor version of the API is released. The service uses the API version for the date you specify, or the most recent version before that date. Note that you should not programmatically specify the current date at runtime, in case the API has been updated since your application's release. Instead, specify a version date that is compatible with your application, and don't change it until your application is ready for a later version. * @param {string} [options.url] - The base url to use when contacting the service (e.g. 'https://gateway.watsonplatform.net/assistant/api'). The base url may differ between Bluemix regions. * @param {string} [options.username] - The username used to authenticate with the service. Username and password credentials are only required to run your application locally or outside of Bluemix. When running on Bluemix, the credentials will be automatically loaded from the `VCAP_SERVICES` environment variable. * @param {string} [options.password] - The password used to authenticate with the service. Username and password credentials are only required to run your application locally or outside of Bluemix. When running on Bluemix, the credentials will be automatically loaded from the `VCAP_SERVICES` environment variable. * @param {string} [options.iam_access_token] - An IAM access token fully managed by the application. Responsibility falls on the application to refresh the token, either before it expires or reactively upon receiving a 401 from the service, as any requests made with an expired token will fail. * @param {string} [options.iam_apikey] - An API key that can be used to request IAM tokens. If this API key is provided, the SDK will manage the token and handle the refreshing. * @param {string} [options.iam_url] - An optional URL for the IAM service API. Defaults to 'https://iam.bluemix.net/identity/token'. * @param {boolean} [options.use_unauthenticated] - Set to `true` to avoid including an authorization header. This option may be useful for requests that are proxied. * @param {Object} [options.headers] - Default headers that shall be included with every request to the service. * @param {boolean} [options.headers.X-Watson-Learning-Opt-Out] - Set to `true` to opt-out of data collection. By default, all IBM Watson services log requests and their results. Logging is done only to improve the services for future users. The logged data is not shared or made public. If you are concerned with protecting the privacy of users' personal information or otherwise do not want your requests to be logged, you can opt out of logging. * @constructor * @returns {AssistantV1} * @throws {Error} */ function AssistantV1(options) { var _this = _super.call(this, options) || this; // check if 'version' was provided if (typeof _this._options.version === 'undefined') { throw new Error('Argument error: version was not specified'); } _this._options.qs.version = options.version; return _this; } /************************* * message ************************/ /** * Get response to user input. * * Send user input to a workspace and receive a response. * * There is no rate limit for this operation. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {MessageInput} [params.input] - An input object that includes the input text. * @param {RuntimeIntent[]} [params.intents] - Intents to use when evaluating the user input. Include intents from the * previous response to continue using those intents rather than trying to recognize intents in the new input. * @param {RuntimeEntity[]} [params.entities] - Entities to use when evaluating the message. Include entities from the * previous response to continue using those entities rather than detecting entities in the new input. * @param {boolean} [params.alternate_intents] - Whether to return more than one intent. A value of `true` indicates * that all matching intents are returned. * @param {Context} [params.context] - State information for the conversation. To maintain state, include the context * from the previous response. * @param {OutputData} [params.output] - An output object that includes the response to the user, the dialog nodes * that were triggered, and messages from the log. * @param {boolean} [params.nodes_visited_details] - Whether to include additional diagnostic information about the * dialog nodes that were visited during processing of the message. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.message = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id']; if (!_callback) { return new Promise(function (resolve, reject) { _this.message(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'input': _params.input, 'intents': _params.intents, 'entities': _params.entities, 'alternate_intents': _params.alternate_intents, 'context': _params.context, 'output': _params.output }; var query = { 'nodes_visited_details': _params.nodes_visited_details }; var path = { 'workspace_id': _params.workspace_id }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'message'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/message', method: 'POST', body: body, qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /************************* * workspaces ************************/ /** * Create workspace. * * Create a workspace based on component objects. You must provide workspace components defining the content of the * new workspace. * * This operation is limited to 30 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} [params] - The parameters to send to the service. * @param {string} [params.name] - The name of the workspace. This string cannot contain carriage return, newline, or * tab characters, and it must be no longer than 64 characters. * @param {string} [params.description] - The description of the workspace. This string cannot contain carriage * return, newline, or tab characters, and it must be no longer than 128 characters. * @param {string} [params.language] - The language of the workspace. * @param {Object} [params.metadata] - Any metadata related to the workspace. * @param {boolean} [params.learning_opt_out] - Whether training data from the workspace (including artifacts such as * intents and entities) can be used by IBM for general service improvements. `true` indicates that workspace training * data is not to be used. * @param {WorkspaceSystemSettings} [params.system_settings] - Global settings for the workspace. * @param {CreateIntent[]} [params.intents] - An array of objects defining the intents for the workspace. * @param {CreateEntity[]} [params.entities] - An array of objects describing the entities for the workspace. * @param {DialogNode[]} [params.dialog_nodes] - An array of objects describing the dialog nodes in the workspace. * @param {Counterexample[]} [params.counterexamples] - An array of objects defining input examples that have been * marked as irrelevant input. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.createWorkspace = function (params, callback) { var _this = this; var _params = (typeof params === 'function' && !callback) ? {} : extend({}, params); var _callback = (typeof params === 'function' && !callback) ? params : callback; if (!_callback) { return new Promise(function (resolve, reject) { _this.createWorkspace(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var body = { 'name': _params.name, 'description': _params.description, 'language': _params.language, 'metadata': _params.metadata, 'learning_opt_out': _params.learning_opt_out, 'system_settings': _params.system_settings, 'intents': _params.intents, 'entities': _params.entities, 'dialog_nodes': _params.dialog_nodes, 'counterexamples': _params.counterexamples }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'createWorkspace'); var parameters = { options: { url: '/v1/workspaces', method: 'POST', body: body, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Delete workspace. * * Delete a workspace from the service instance. * * This operation is limited to 30 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.deleteWorkspace = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id']; if (!_callback) { return new Promise(function (resolve, reject) { _this.deleteWorkspace(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var path = { 'workspace_id': _params.workspace_id }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'deleteWorkspace'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Get information about a workspace. * * Get information about a workspace, optionally including all workspace content. * * With **export**=`false`, this operation is limited to 6000 requests per 5 minutes. With **export**=`true`, the * limit is 20 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {boolean} [params._export] - Whether to include all element content in the returned data. If * **export**=`false`, the returned data includes only information about the element itself. If **export**=`true`, all * content, including subelements, is included. * @param {boolean} [params.include_audit] - Whether to include the audit properties (`created` and `updated` * timestamps) in the response. * @param {string} [params.sort] - Indicates how the returned workspace data will be sorted. This parameter is valid * only if **export**=`true`. Specify `sort=stable` to sort all workspace objects by unique identifier, in ascending * alphabetical order. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.getWorkspace = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id']; if (!_callback) { return new Promise(function (resolve, reject) { _this.getWorkspace(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var query = { 'export': _params._export, 'include_audit': _params.include_audit, 'sort': _params.sort }; var path = { 'workspace_id': _params.workspace_id }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'getWorkspace'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * List workspaces. * * List the workspaces associated with a Watson Assistant service instance. * * This operation is limited to 500 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} [params] - The parameters to send to the service. * @param {number} [params.page_limit] - The number of records to return in each page of results. * @param {boolean} [params.include_count] - Whether to include information about the number of records returned. * @param {string} [params.sort] - The attribute by which returned workspaces will be sorted. To reverse the sort * order, prefix the value with a minus sign (`-`). * @param {string} [params.cursor] - A token identifying the page of results to retrieve. * @param {boolean} [params.include_audit] - Whether to include the audit properties (`created` and `updated` * timestamps) in the response. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.listWorkspaces = function (params, callback) { var _this = this; var _params = (typeof params === 'function' && !callback) ? {} : extend({}, params); var _callback = (typeof params === 'function' && !callback) ? params : callback; if (!_callback) { return new Promise(function (resolve, reject) { _this.listWorkspaces(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var query = { 'page_limit': _params.page_limit, 'include_count': _params.include_count, 'sort': _params.sort, 'cursor': _params.cursor, 'include_audit': _params.include_audit }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'listWorkspaces'); var parameters = { options: { url: '/v1/workspaces', method: 'GET', qs: query, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Update workspace. * * Update an existing workspace with new or modified data. You must provide component objects defining the content of * the updated workspace. * * This operation is limited to 30 request per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} [params.name] - The name of the workspace. This string cannot contain carriage return, newline, or * tab characters, and it must be no longer than 64 characters. * @param {string} [params.description] - The description of the workspace. This string cannot contain carriage * return, newline, or tab characters, and it must be no longer than 128 characters. * @param {string} [params.language] - The language of the workspace. * @param {Object} [params.metadata] - Any metadata related to the workspace. * @param {boolean} [params.learning_opt_out] - Whether training data from the workspace (including artifacts such as * intents and entities) can be used by IBM for general service improvements. `true` indicates that workspace training * data is not to be used. * @param {WorkspaceSystemSettings} [params.system_settings] - Global settings for the workspace. * @param {CreateIntent[]} [params.intents] - An array of objects defining the intents for the workspace. * @param {CreateEntity[]} [params.entities] - An array of objects describing the entities for the workspace. * @param {DialogNode[]} [params.dialog_nodes] - An array of objects describing the dialog nodes in the workspace. * @param {Counterexample[]} [params.counterexamples] - An array of objects defining input examples that have been * marked as irrelevant input. * @param {boolean} [params.append] - Whether the new data is to be appended to the existing data in the workspace. If * **append**=`false`, elements included in the new data completely replace the corresponding existing elements, * including all subelements. For example, if the new data includes **entities** and **append**=`false`, all existing * entities in the workspace are discarded and replaced with the new entities. * * If **append**=`true`, existing elements are preserved, and the new elements are added. If any elements in the new * data collide with existing elements, the update request fails. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.updateWorkspace = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id']; if (!_callback) { return new Promise(function (resolve, reject) { _this.updateWorkspace(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'name': _params.name, 'description': _params.description, 'language': _params.language, 'metadata': _params.metadata, 'learning_opt_out': _params.learning_opt_out, 'system_settings': _params.system_settings, 'intents': _params.intents, 'entities': _params.entities, 'dialog_nodes': _params.dialog_nodes, 'counterexamples': _params.counterexamples }; var query = { 'append': _params.append }; var path = { 'workspace_id': _params.workspace_id }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'updateWorkspace'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}', method: 'POST', body: body, qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /************************* * intents ************************/ /** * Create intent. * * Create a new intent. * * This operation is limited to 2000 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The name of the intent. This string must conform to the following restrictions: * - It can contain only Unicode alphanumeric, underscore, hyphen, and dot characters. * - It cannot begin with the reserved prefix `sys-`. * - It must be no longer than 128 characters. * @param {string} [params.description] - The description of the intent. This string cannot contain carriage return, * newline, or tab characters, and it must be no longer than 128 characters. * @param {Example[]} [params.examples] - An array of user input examples for the intent. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.createIntent = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent']; if (!_callback) { return new Promise(function (resolve, reject) { _this.createIntent(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'intent': _params.intent, 'description': _params.description, 'examples': _params.examples }; var path = { 'workspace_id': _params.workspace_id }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'createIntent'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents', method: 'POST', body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Delete intent. * * Delete an intent from a workspace. * * This operation is limited to 2000 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.deleteIntent = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent']; if (!_callback) { return new Promise(function (resolve, reject) { _this.deleteIntent(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'deleteIntent'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Get intent. * * Get information about an intent, optionally including all intent content. * * With **export**=`false`, this operation is limited to 6000 requests per 5 minutes. With **export**=`true`, the * limit is 400 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {boolean} [params._export] - Whether to include all element content in the returned data. If * **export**=`false`, the returned data includes only information about the element itself. If **export**=`true`, all * content, including subelements, is included. * @param {boolean} [params.include_audit] - Whether to include the audit properties (`created` and `updated` * timestamps) in the response. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.getIntent = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent']; if (!_callback) { return new Promise(function (resolve, reject) { _this.getIntent(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var query = { 'export': _params._export, 'include_audit': _params.include_audit }; var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'getIntent'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * List intents. * * List the intents for a workspace. * * With **export**=`false`, this operation is limited to 2000 requests per 30 minutes. With **export**=`true`, the * limit is 400 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {boolean} [params._export] - Whether to include all element content in the returned data. If * **export**=`false`, the returned data includes only information about the element itself. If **export**=`true`, all * content, including subelements, is included. * @param {number} [params.page_limit] - The number of records to return in each page of results. * @param {boolean} [params.include_count] - Whether to include information about the number of records returned. * @param {string} [params.sort] - The attribute by which returned intents will be sorted. To reverse the sort order, * prefix the value with a minus sign (`-`). * @param {string} [params.cursor] - A token identifying the page of results to retrieve. * @param {boolean} [params.include_audit] - Whether to include the audit properties (`created` and `updated` * timestamps) in the response. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.listIntents = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id']; if (!_callback) { return new Promise(function (resolve, reject) { _this.listIntents(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var query = { 'export': _params._export, 'page_limit': _params.page_limit, 'include_count': _params.include_count, 'sort': _params.sort, 'cursor': _params.cursor, 'include_audit': _params.include_audit }; var path = { 'workspace_id': _params.workspace_id }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'listIntents'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Update intent. * * Update an existing intent with new or modified data. You must provide component objects defining the content of the * updated intent. * * This operation is limited to 2000 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {string} [params.new_intent] - The name of the intent. This string must conform to the following * restrictions: * - It can contain only Unicode alphanumeric, underscore, hyphen, and dot characters. * - It cannot begin with the reserved prefix `sys-`. * - It must be no longer than 128 characters. * @param {string} [params.new_description] - The description of the intent. This string cannot contain carriage * return, newline, or tab characters, and it must be no longer than 128 characters. * @param {Example[]} [params.new_examples] - An array of user input examples for the intent. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.updateIntent = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent']; if (!_callback) { return new Promise(function (resolve, reject) { _this.updateIntent(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'intent': _params.new_intent, 'description': _params.new_description, 'examples': _params.new_examples }; var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'updateIntent'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}', method: 'POST', body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /************************* * examples ************************/ /** * Create user input example. * * Add a new user input example to an intent. * * This operation is limited to 1000 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {string} params.text - The text of a user input example. This string must conform to the following * restrictions: * - It cannot contain carriage return, newline, or tab characters. * - It cannot consist of only whitespace characters. * - It must be no longer than 1024 characters. * @param {Mention[]} [params.mentions] - An array of contextual entity mentions. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.createExample = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent', 'text']; if (!_callback) { return new Promise(function (resolve, reject) { _this.createExample(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'text': _params.text, 'mentions': _params.mentions }; var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'createExample'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples', method: 'POST', body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Delete user input example. * * Delete a user input example from an intent. * * This operation is limited to 1000 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {string} params.text - The text of the user input example. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.deleteExample = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent', 'text']; if (!_callback) { return new Promise(function (resolve, reject) { _this.deleteExample(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent, 'text': _params.text }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'deleteExample'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Get user input example. * * Get information about a user input example. * * This operation is limited to 6000 requests per 5 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {string} params.text - The text of the user input example. * @param {boolean} [params.include_audit] - Whether to include the audit properties (`created` and `updated` * timestamps) in the response. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.getExample = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent', 'text']; if (!_callback) { return new Promise(function (resolve, reject) { _this.getExample(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var query = { 'include_audit': _params.include_audit }; var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent, 'text': _params.text }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'getExample'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * List user input examples. * * List the user input examples for an intent, optionally including contextual entity mentions. * * This operation is limited to 2500 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {number} [params.page_limit] - The number of records to return in each page of results. * @param {boolean} [params.include_count] - Whether to include information about the number of records returned. * @param {string} [params.sort] - The attribute by which returned examples will be sorted. To reverse the sort order, * prefix the value with a minus sign (`-`). * @param {string} [params.cursor] - A token identifying the page of results to retrieve. * @param {boolean} [params.include_audit] - Whether to include the audit properties (`created` and `updated` * timestamps) in the response. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.listExamples = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent']; if (!_callback) { return new Promise(function (resolve, reject) { _this.listExamples(params, function (err, bod, res) { err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod); }); }); } var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var query = { 'page_limit': _params.page_limit, 'include_count': _params.include_count, 'sort': _params.sort, 'cursor': _params.cursor, 'include_audit': _params.include_audit }; var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent }; var sdkHeaders = common_1.getSdkHeaders('conversation', 'v1', 'listExamples'); var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, sdkHeaders, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Update user input example. * * Update the text of a user input example. * * This operation is limited to 1000 requests per 30 minutes. For more information, see **Rate limiting**. * * @param {Object} params - The parameters to send to the service. * @param {string} params.workspace_id - Unique identifier of the workspace. * @param {string} params.intent - The intent name. * @param {string} params.text - The text of the user input example. * @param {string} [params.new_text] - The text of the user input example. This string must conform to the following * restrictions: * - It cannot contain carriage return, newline, or tab characters. * - It cannot consist of only whitespace characters. * - It must be no longer than 1024 characters. * @param {Mention[]} [params.new_mentions] - An array of contextual entity mentions. * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {Promise<any>|void} */ AssistantV1.prototype.updateExample = function (params, callback) { var _this = this; var _params = extend({}, params); var _callback = callback; var requiredParams = ['workspace_id', 'intent', 'text']; if (!_callback) { return new Promise(function (resolve, reject) {