UNPKG

watson-developer-cloud

Version:

Client library to use the IBM Watson Services and AlchemyAPI

1,052 lines 132 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 = 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 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 base_service_1 = require("../lib/base_service"); var helper_1 = require("../lib/helper"); /** * The IBM Watson™ 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 {InputData} [params.input] - An input object that includes the input text. * @param {boolean} [params.alternate_intents] - Whether to return more than one intent. Set to `true` to return all * matching intents. * @param {Context} [params.context] - State information for the conversation. To maintain state, include the context * from the previous response. * @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 {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 {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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.message = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'input': _params.input, 'alternate_intents': _params.alternate_intents, 'context': _params.context, 'entities': _params.entities, 'intents': _params.intents, 'output': _params.output }; var query = { 'nodes_visited_details': _params.nodes_visited_details }; var path = { 'workspace_id': _params.workspace_id }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}/message', method: 'POST', json: true, body: body, qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {CreateIntent[]} [params.intents] - An array of objects defining the intents for the workspace. * @param {CreateEntity[]} [params.entities] - An array of objects defining the entities for the workspace. * @param {CreateDialogNode[]} [params.dialog_nodes] - An array of objects defining the nodes in the dialog. * @param {CreateCounterexample[]} [params.counterexamples] - An array of objects defining input examples that have * been marked as irrelevant input. * @param {Object} [params.metadata] - Any metadata related to the workspace. * @param {boolean} [params.learning_opt_out] - Whether training data from the workspace 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 {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {NodeJS.ReadableStream|void} */ AssistantV1.prototype.createWorkspace = function (params, callback) { var _params = (typeof params === 'function' && !callback) ? {} : extend({}, params); var _callback = (typeof params === 'function' && !callback) ? params : (callback) ? callback : function () { }; var body = { 'name': _params.name, 'description': _params.description, 'language': _params.language, 'intents': _params.intents, 'entities': _params.entities, 'dialog_nodes': _params.dialog_nodes, 'counterexamples': _params.counterexamples, 'metadata': _params.metadata, 'learning_opt_out': _params.learning_opt_out, 'system_settings': _params.system_settings }; var parameters = { options: { url: '/v1/workspaces', method: 'POST', json: true, body: body, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.deleteWorkspace = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var path = { 'workspace_id': _params.workspace_id }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.getWorkspace = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id']; var missingParams = helper_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 parameters = { options: { url: '/v1/workspaces/{workspace_id}', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.listWorkspaces = function (params, callback) { var _params = (typeof params === 'function' && !callback) ? {} : extend({}, params); var _callback = (typeof params === 'function' && !callback) ? params : (callback) ? callback : function () { }; var query = { 'page_limit': _params.page_limit, 'include_count': _params.include_count, 'sort': _params.sort, 'cursor': _params.cursor, 'include_audit': _params.include_audit }; var parameters = { options: { url: '/v1/workspaces', method: 'GET', qs: query, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {CreateIntent[]} [params.intents] - An array of objects defining the intents for the workspace. * @param {CreateEntity[]} [params.entities] - An array of objects defining the entities for the workspace. * @param {CreateDialogNode[]} [params.dialog_nodes] - An array of objects defining the nodes in the dialog. * @param {CreateCounterexample[]} [params.counterexamples] - An array of objects defining input examples that have * been marked as irrelevant input. * @param {Object} [params.metadata] - Any metadata related to the workspace. * @param {boolean} [params.learning_opt_out] - Whether training data from the workspace 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 {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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.updateWorkspace = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'name': _params.name, 'description': _params.description, 'language': _params.language, 'intents': _params.intents, 'entities': _params.entities, 'dialog_nodes': _params.dialog_nodes, 'counterexamples': _params.counterexamples, 'metadata': _params.metadata, 'learning_opt_out': _params.learning_opt_out, 'system_settings': _params.system_settings }; var query = { 'append': _params.append }; var path = { 'workspace_id': _params.workspace_id }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}', method: 'POST', json: true, body: body, qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {CreateExample[]} [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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.createIntent = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent']; var missingParams = helper_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 parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents', method: 'POST', json: true, body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.deleteIntent = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.getIntent = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent']; var missingParams = helper_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 parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.listIntents = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id']; var missingParams = helper_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 parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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. * @param {CreateExample[]} [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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.updateIntent = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent']; var missingParams = helper_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 parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}', method: 'POST', json: true, body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {Mentions[]} [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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.createExample = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent', 'text']; var missingParams = helper_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 parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples', method: 'POST', json: true, body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.deleteExample = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent', 'text']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent, 'text': _params.text }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.getExample = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent', 'text']; var missingParams = helper_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 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, { '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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.listExamples = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent']; var missingParams = helper_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 parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples', method: 'GET', qs: query, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { '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 {Mentions[]} [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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.updateExample = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'intent', 'text']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'text': _params.new_text, 'mentions': _params.new_mentions }; var path = { 'workspace_id': _params.workspace_id, 'intent': _params.intent, 'text': _params.text }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}', method: 'POST', json: true, body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /************************* * counterexamples ************************/ /** * Create counterexample. * * Add a new counterexample to a workspace. Counterexamples are examples that have been marked as irrelevant input. * * 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.text - The text of a user input marked as irrelevant input. 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 {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {NodeJS.ReadableStream|void} */ AssistantV1.prototype.createCounterexample = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'text']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var body = { 'text': _params.text }; var path = { 'workspace_id': _params.workspace_id }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}/counterexamples', method: 'POST', json: true, body: body, path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { 'Accept': 'application/json', 'Content-Type': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Delete counterexample. * * Delete a counterexample from a workspace. Counterexamples are examples that have been marked as irrelevant input. * * 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.text - The text of a user input counterexample (for example, `What are you wearing?`). * @param {Object} [params.headers] - Custom request headers * @param {Function} [callback] - The callback that handles the response. * @returns {NodeJS.ReadableStream|void} */ AssistantV1.prototype.deleteCounterexample = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'text']; var missingParams = helper_1.getMissingParams(_params, requiredParams); if (missingParams) { return _callback(missingParams); } var path = { 'workspace_id': _params.workspace_id, 'text': _params.text }; var parameters = { options: { url: '/v1/workspaces/{workspace_id}/counterexamples/{text}', method: 'DELETE', path: path, }, defaultOptions: extend(true, {}, this._options, { headers: extend(true, { 'Accept': 'application/json', }, _params.headers), }), }; return this.createRequest(parameters, _callback); }; ; /** * Get counterexample. * * Get information about a counterexample. Counterexamples are examples that have been marked as irrelevant input. * * 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.text - The text of a user input counterexample (for example, `What are you wearing?`). * @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 {NodeJS.ReadableStream|void} */ AssistantV1.prototype.getCounterexample = function (params, callback) { var _params = extend({}, params); var _callback = (callback) ? callback : function () { }; var requiredParams = ['workspace_id', 'text']; var mi