ibm-watson
Version:
Client library to use the IBM Watson Services
978 lines (977 loc) • 179 kB
JavaScript
"use strict";
/**
* (C) Copyright IBM Corp. 2018, 2024.
*
* 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* IBM OpenAPI SDK Code Generator Version: 3.96.1-5136e54a-20241108-203028
*/
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* The IBM Watson™ Assistant service combines machine learning, natural language understanding, and an integrated
* dialog editor to create conversation flows between your apps and your users.
*
* The Assistant v1 API provides authoring methods your application can use to create or update a workspace.
*
* API Version: 1.0
* See: https://cloud.ibm.com/docs/assistant
*/
var AssistantV1 = /** @class */ (function (_super) {
__extends(AssistantV1, _super);
/**
* Construct a AssistantV1 object.
*
* @param {Object} options - Options for the service.
* @param {string} options.version - Release date of the API version you want to use. Specify dates in YYYY-MM-DD
* format. The current version is `2021-11-27`.
* @param {string} [options.serviceUrl] - The base URL for the service
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
* @param {string} [options.serviceName] - The name of the service to configure
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service. Defaults to environment if not set
* @constructor
* @returns {AssistantV1}
*/
function AssistantV1(options) {
var _this = this;
options = options || {};
var _requiredParams = ['version'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(options, _requiredParams, null);
if (_validationErrors) {
throw _validationErrors;
}
if (!options.serviceName) {
options.serviceName = AssistantV1.DEFAULT_SERVICE_NAME;
}
// If the caller didn't supply an authenticator, construct one from external configuration.
if (!options.authenticator) {
options.authenticator = (0, ibm_cloud_sdk_core_1.getAuthenticatorFromEnvironment)(options.serviceName);
}
_this = _super.call(this, options) || this;
_this.configureService(options.serviceName);
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
_this.version = options.version;
return _this;
}
/*************************
* message
************************/
/**
* Get response to user input.
*
* Send user input to a workspace and receive a response.
*
* **Important:** This method has been superseded by the new v2 runtime API. The v2 API offers significant advantages,
* including ease of deployment, automatic state management, versioning, and search capabilities. For more
* information, see the [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-api-overview).
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - 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.alternateIntents] - 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 {string} [params.userId] - A string value that identifies the user who is interacting with the workspace.
* The client must provide a unique identifier for each individual end user who accesses the application. For
* user-based plans, this user ID is used to identify unique users for billing purposes. This string cannot contain
* carriage return, newline, or tab characters. If no value is specified in the input, **user_id** is automatically
* set to the value of **context.conversation_id**.
*
* **Note:** This property is the same as the **user_id** property in the context metadata. If **user_id** is
* specified in both locations in a message request, the value specified at the root is used.
* @param {boolean} [params.nodesVisitedDetails] - Whether to include additional diagnostic information about the
* dialog nodes that were visited during processing of the message.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.MessageResponse>>}
*/
AssistantV1.prototype.message = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', 'input', 'intents', 'entities', 'alternateIntents', 'context', 'output', 'userId', 'nodesVisitedDetails', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'input': _params.input,
'intents': _params.intents,
'entities': _params.entities,
'alternate_intents': _params.alternateIntents,
'context': _params.context,
'output': _params.output,
'user_id': _params.userId,
};
var query = {
'version': this.version,
'nodes_visited_details': _params.nodesVisitedDetails,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'message');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/message',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* bulkClassify
************************/
/**
* Identify intents and entities in multiple user utterances.
*
* Send multiple user inputs to a workspace in a single request and receive information about the intents and entities
* recognized in each input. This method is useful for testing and comparing the performance of different workspaces.
*
* This method is available only with Enterprise with Data Isolation plans.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - Unique identifier of the workspace.
* @param {BulkClassifyUtterance[]} [params.input] - An array of input utterances to classify.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.BulkClassifyResponse>>}
*/
AssistantV1.prototype.bulkClassify = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', 'input', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'input': _params.input,
};
var query = {
'version': this.version,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'bulkClassify');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/bulk_classify',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* workspaces
************************/
/**
* List workspaces.
*
* List the workspaces associated with a Watson Assistant service instance.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {number} [params.pageLimit] - The number of records to return in each page of results.
* @param {boolean} [params.includeCount] - Whether to include information about the number of records that satisfy
* the request, regardless of the page limit. If this parameter is `true`, the `pagination` object in the response
* includes the `total` property.
* @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.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.WorkspaceCollection>>}
*/
AssistantV1.prototype.listWorkspaces = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['pageLimit', 'includeCount', 'sort', 'cursor', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'page_limit': _params.pageLimit,
'include_count': _params.includeCount,
'sort': _params.sort,
'cursor': _params.cursor,
'include_audit': _params.includeAudit,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'listWorkspaces');
var parameters = {
options: {
url: '/v1/workspaces',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create workspace.
*
* Create a workspace based on component objects. You must provide workspace components defining the content of the
* new workspace.
*
* **Note:** The new workspace data cannot be larger than 1.5 MB. For larger requests, use the **Create workspace
* asynchronously** method.
*
* @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.
* @param {string} [params.description] - The description of the workspace. This string cannot contain carriage
* return, newline, or tab characters.
* @param {string} [params.language] - The language of the workspace.
* @param {DialogNode[]} [params.dialogNodes] - 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 {JsonObject} [params.metadata] - Any metadata related to the workspace.
* @param {boolean} [params.learningOptOut] - 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.systemSettings] - Global settings for the workspace.
* @param {Webhook[]} [params.webhooks] -
* @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 {boolean} [params.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Workspace>>}
*/
AssistantV1.prototype.createWorkspace = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['name', 'description', 'language', 'dialogNodes', 'counterexamples', 'metadata', 'learningOptOut', 'systemSettings', 'webhooks', 'intents', 'entities', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'description': _params.description,
'language': _params.language,
'dialog_nodes': _params.dialogNodes,
'counterexamples': _params.counterexamples,
'metadata': _params.metadata,
'learning_opt_out': _params.learningOptOut,
'system_settings': _params.systemSettings,
'webhooks': _params.webhooks,
'intents': _params.intents,
'entities': _params.entities,
};
var query = {
'version': this.version,
'include_audit': _params.includeAudit,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'createWorkspace');
var parameters = {
options: {
url: '/v1/workspaces',
method: 'POST',
body: body,
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get information about a workspace.
*
* Get information about a workspace, optionally including all workspace content.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - 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.includeAudit] - 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 {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Workspace>>}
*/
AssistantV1.prototype.getWorkspace = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', '_export', 'includeAudit', 'sort', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'export': _params._export,
'include_audit': _params.includeAudit,
'sort': _params.sort,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'getWorkspace');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update workspace.
*
* Update an existing workspace with new or modified data. You must provide component objects defining the content of
* the updated workspace.
*
* **Note:** The new workspace data cannot be larger than 1.5 MB. For larger requests, use the **Update workspace
* asynchronously** method.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - Unique identifier of the workspace.
* @param {string} [params.name] - The name of the workspace. This string cannot contain carriage return, newline, or
* tab characters.
* @param {string} [params.description] - The description of the workspace. This string cannot contain carriage
* return, newline, or tab characters.
* @param {string} [params.language] - The language of the workspace.
* @param {DialogNode[]} [params.dialogNodes] - 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 {JsonObject} [params.metadata] - Any metadata related to the workspace.
* @param {boolean} [params.learningOptOut] - 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.systemSettings] - Global settings for the workspace.
* @param {Webhook[]} [params.webhooks] -
* @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 {boolean} [params.append] - Whether the new data is to be appended to the existing data in the object. If
* **append**=`false`, elements included in the new data completely replace the corresponding existing elements,
* including all subelements. For example, if the new data for a workspace 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 {boolean} [params.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Workspace>>}
*/
AssistantV1.prototype.updateWorkspace = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', 'name', 'description', 'language', 'dialogNodes', 'counterexamples', 'metadata', 'learningOptOut', 'systemSettings', 'webhooks', 'intents', 'entities', 'append', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'description': _params.description,
'language': _params.language,
'dialog_nodes': _params.dialogNodes,
'counterexamples': _params.counterexamples,
'metadata': _params.metadata,
'learning_opt_out': _params.learningOptOut,
'system_settings': _params.systemSettings,
'webhooks': _params.webhooks,
'intents': _params.intents,
'entities': _params.entities,
};
var query = {
'version': this.version,
'append': _params.append,
'include_audit': _params.includeAudit,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'updateWorkspace');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Delete workspace.
*
* Delete a workspace from the service instance.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - Unique identifier of the workspace.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.EmptyObject>>}
*/
AssistantV1.prototype.deleteWorkspace = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'deleteWorkspace');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}',
method: 'DELETE',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create workspace asynchronously.
*
* Create a workspace asynchronously based on component objects. You must provide workspace components defining the
* content of the new workspace.
*
* A successful call to this method only initiates asynchronous creation of the workspace. The new workspace is not
* available until processing completes. To check the status of the asynchronous operation, use the **Get information
* about a workspace** method.
*
* @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.
* @param {string} [params.description] - The description of the workspace. This string cannot contain carriage
* return, newline, or tab characters.
* @param {string} [params.language] - The language of the workspace.
* @param {DialogNode[]} [params.dialogNodes] - 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 {JsonObject} [params.metadata] - Any metadata related to the workspace.
* @param {boolean} [params.learningOptOut] - 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.systemSettings] - Global settings for the workspace.
* @param {Webhook[]} [params.webhooks] -
* @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 {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Workspace>>}
*/
AssistantV1.prototype.createWorkspaceAsync = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['name', 'description', 'language', 'dialogNodes', 'counterexamples', 'metadata', 'learningOptOut', 'systemSettings', 'webhooks', 'intents', 'entities', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'description': _params.description,
'language': _params.language,
'dialog_nodes': _params.dialogNodes,
'counterexamples': _params.counterexamples,
'metadata': _params.metadata,
'learning_opt_out': _params.learningOptOut,
'system_settings': _params.systemSettings,
'webhooks': _params.webhooks,
'intents': _params.intents,
'entities': _params.entities,
};
var query = {
'version': this.version,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'createWorkspaceAsync');
var parameters = {
options: {
url: '/v1/workspaces_async',
method: 'POST',
body: body,
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update workspace asynchronously.
*
* Update an existing workspace asynchronously with new or modified data. You must provide component objects defining
* the content of the updated workspace.
*
* A successful call to this method only initiates an asynchronous update of the workspace. The updated workspace is
* not available until processing completes. To check the status of the asynchronous operation, use the **Get
* information about a workspace** method.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - Unique identifier of the workspace.
* @param {string} [params.name] - The name of the workspace. This string cannot contain carriage return, newline, or
* tab characters.
* @param {string} [params.description] - The description of the workspace. This string cannot contain carriage
* return, newline, or tab characters.
* @param {string} [params.language] - The language of the workspace.
* @param {DialogNode[]} [params.dialogNodes] - 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 {JsonObject} [params.metadata] - Any metadata related to the workspace.
* @param {boolean} [params.learningOptOut] - 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.systemSettings] - Global settings for the workspace.
* @param {Webhook[]} [params.webhooks] -
* @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 {boolean} [params.append] - Whether the new data is to be appended to the existing data in the object. If
* **append**=`false`, elements included in the new data completely replace the corresponding existing elements,
* including all subelements. For example, if the new data for a workspace 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 {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Workspace>>}
*/
AssistantV1.prototype.updateWorkspaceAsync = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', 'name', 'description', 'language', 'dialogNodes', 'counterexamples', 'metadata', 'learningOptOut', 'systemSettings', 'webhooks', 'intents', 'entities', 'append', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'description': _params.description,
'language': _params.language,
'dialog_nodes': _params.dialogNodes,
'counterexamples': _params.counterexamples,
'metadata': _params.metadata,
'learning_opt_out': _params.learningOptOut,
'system_settings': _params.systemSettings,
'webhooks': _params.webhooks,
'intents': _params.intents,
'entities': _params.entities,
};
var query = {
'version': this.version,
'append': _params.append,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'updateWorkspaceAsync');
var parameters = {
options: {
url: '/v1/workspaces_async/{workspace_id}',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Export workspace asynchronously.
*
* Export the entire workspace asynchronously, including all workspace content.
*
* A successful call to this method only initiates an asynchronous export. The exported JSON data is not available
* until processing completes. After the initial request is submitted, you can continue to poll by calling the same
* request again and checking the value of the **status** property. When processing has completed, the request returns
* the exported JSON data. Remember that the usual rate limits apply.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - Unique identifier of the workspace.
* @param {boolean} [params.includeAudit] - 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. Specify `sort=stable` to
* sort all workspace objects by unique identifier, in ascending alphabetical order.
* @param {boolean} [params.verbose] - Whether the response should include the `counts` property, which indicates how
* many of each component (such as intents and entities) the workspace contains.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Workspace>>}
*/
AssistantV1.prototype.exportWorkspaceAsync = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', 'includeAudit', 'sort', 'verbose', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'include_audit': _params.includeAudit,
'sort': _params.sort,
'verbose': _params.verbose,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'exportWorkspaceAsync');
var parameters = {
options: {
url: '/v1/workspaces_async/{workspace_id}/export',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* intents
************************/
/**
* List intents.
*
* List the intents for a workspace.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - 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.pageLimit] - The number of records to return in each page of results.
* @param {boolean} [params.includeCount] - Whether to include information about the number of records that satisfy
* the request, regardless of the page limit. If this parameter is `true`, the `pagination` object in the response
* includes the `total` property.
* @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.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.IntentCollection>>}
*/
AssistantV1.prototype.listIntents = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId'];
var _validParams = ['workspaceId', '_export', 'pageLimit', 'includeCount', 'sort', 'cursor', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'export': _params._export,
'page_limit': _params.pageLimit,
'include_count': _params.includeCount,
'sort': _params.sort,
'cursor': _params.cursor,
'include_audit': _params.includeAudit,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'listIntents');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/intents',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create intent.
*
* Create a new intent.
*
* If you want to create multiple intents with a single API call, consider using the **[Update
* workspace](#update-workspace)** method instead.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - 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-`.
* @param {string} [params.description] - The description of the intent. This string cannot contain carriage return,
* newline, or tab characters.
* @param {Example[]} [params.examples] - An array of user input examples for the intent.
* @param {boolean} [params.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Intent>>}
*/
AssistantV1.prototype.createIntent = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId', 'intent'];
var _validParams = ['workspaceId', 'intent', 'description', 'examples', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'intent': _params.intent,
'description': _params.description,
'examples': _params.examples,
};
var query = {
'version': this.version,
'include_audit': _params.includeAudit,
};
var path = {
'workspace_id': _params.workspaceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'createIntent');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/intents',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get intent.
*
* Get information about an intent, optionally including all intent content.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - 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.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Intent>>}
*/
AssistantV1.prototype.getIntent = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId', 'intent'];
var _validParams = ['workspaceId', 'intent', '_export', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'export': _params._export,
'include_audit': _params.includeAudit,
};
var path = {
'workspace_id': _params.workspaceId,
'intent': _params.intent,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'getIntent');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/intents/{intent}',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update intent.
*
* Update an existing intent with new or modified data. You must provide component objects defining the content of the
* updated intent.
*
* If you want to update multiple intents with a single API call, consider using the **[Update
* workspace](#update-workspace)** method instead.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.workspaceId - Unique identifier of the workspace.
* @param {string} params.intent - The intent name.
* @param {string} [params.newIntent] - 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-`.
* @param {string} [params.newDescription] - The description of the intent. This string cannot contain carriage
* return, newline, or tab characters.
* @param {Example[]} [params.newExamples] - An array of user input examples for the intent.
* @param {boolean} [params.append] - Whether the new data is to be appended to the existing data in the object. If
* **append**=`false`, elements included in the new data completely replace the corresponding existing elements,
* including all subelements. For example, if the new data for the intent includes **examples** and
* **append**=`false`, all existing examples for the intent are discarded and replaced with the new examples.
*
* 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 {boolean} [params.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV1.Response<AssistantV1.Intent>>}
*/
AssistantV1.prototype.updateIntent = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['workspaceId', 'intent'];
var _validParams = ['workspaceId', 'intent', 'newIntent', 'newDescription', 'newExamples', 'append', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'intent': _params.newIntent,
'description': _params.newDescription,
'examples': _params.newExamples,
};
var query = {
'version': this.version,
'append': _params.append,
'include_audit': _params.includeAudit,
};
var path = {
'workspace_id': _params.workspaceId,
'intent': _params.intent,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV1.DEFAULT_SERVICE_NAME, 'v1', 'updateIntent');
var parameters = {
options: {
url: '/v1/workspaces/{workspace_id}/intents/{intent}',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);