twilio
Version:
A Twilio helper library
494 lines (493 loc) • 19.5 kB
JavaScript
"use strict";
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio Conversational Intelligence API
* The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperatorPage = exports.OperatorInstance = exports.OperatorContextImpl = exports.OperatorTrainingExample = exports.OperatorParameter = exports.OperatorContextMemory = exports.OperatorContextKnowledge = exports.OperatorContext = exports.LanguageOperator = void 0;
exports.OperatorListInstance = OperatorListInstance;
const util_1 = require("util");
const TokenPage_1 = __importDefault(require("../../../base/TokenPage"));
const deserialize = require("../../../base/deserialize");
const serialize = require("../../../base/serialize");
const utility_1 = require("../../../base/utility");
/**
* A Language Operator resource.
*/
class LanguageOperator {
constructor(payload) {
this.id = payload["id"];
this.displayName = payload["displayName"];
this.description = payload["description"];
this.version = payload["version"];
this.author = payload["author"];
this.prompt = payload["prompt"];
this.outputFormat = payload["outputFormat"];
this.outputSchema = payload["outputSchema"];
this.trainingExamples = payload["trainingExamples"];
this.context = payload["context"];
this.parameters = payload["parameters"];
}
}
exports.LanguageOperator = LanguageOperator;
/**
* Optionally specifies which contextual data sources (Memory, Knowledge) the operator can access during execution. Context objects will be passed in by the Intelligence Configuration Rule at runtime. **Note**: this simply gives the LLM access to these context objects – ultimately the LLM will determine whether to actually call for context at runtime.
*/
class OperatorContext {
constructor(payload) {
this.memory = payload["memory"];
this.knowledge = payload["knowledge"];
}
}
exports.OperatorContext = OperatorContext;
/**
* Defines whether the Operator has access to organizational Knowledge Sources (e.g., policies, FAQs, scripts) at runtime.
*/
class OperatorContextKnowledge {
constructor(payload) {
this.enabled = payload["enabled"];
}
}
exports.OperatorContextKnowledge = OperatorContextKnowledge;
/**
* Defines whether the Operator has access to Memory (past conversational memories and profile traits).
*/
class OperatorContextMemory {
constructor(payload) {
this.enabled = payload["enabled"];
}
}
exports.OperatorContextMemory = OperatorContextMemory;
class OperatorParameter {
constructor(payload) {
this.type = payload["type"];
this._default = payload["default"];
this.required = payload["required"];
this.description = payload["description"];
}
}
exports.OperatorParameter = OperatorParameter;
class OperatorTrainingExample {
constructor(payload) {
this.input = payload["input"];
this.output = payload["output"];
}
}
exports.OperatorTrainingExample = OperatorTrainingExample;
class OperatorContextImpl {
constructor(_version, id) {
this._version = _version;
if (!(0, utility_1.isValidPathParam)(id)) {
throw new Error("Parameter 'id' is not valid.");
}
this._solution = { id };
this._uri = `/ControlPlane/Operators/${id}`;
}
remove(callback) {
const headers = {};
const instance = this;
let operationVersion = instance._version, operationPromise = operationVersion.remove({
uri: instance._uri,
method: "delete",
headers,
});
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
removeWithHttpInfo(callback) {
const headers = {};
const instance = this;
let operationVersion = instance._version;
// DELETE operation - returns boolean based on status code
let operationPromise = operationVersion
.removeWithResponseInfo({ uri: instance._uri, method: "delete", headers })
.then((response) => ({
...response,
body: response.statusCode === 204,
}));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
fetch(callback) {
const headers = {};
headers["Accept"] = "application/json";
const instance = this;
let operationVersion = instance._version, operationPromise = operationVersion.fetch({
uri: instance._uri,
method: "get",
headers,
});
operationPromise = operationPromise.then((payload) => new OperatorInstance(operationVersion, payload, instance._solution.id));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
fetchWithHttpInfo(callback) {
const headers = {};
headers["Accept"] = "application/json";
const instance = this;
let operationVersion = instance._version;
// CREATE, FETCH, UPDATE operations
let operationPromise = operationVersion
.fetchWithResponseInfo({
uri: instance._uri,
method: "get",
headers,
})
.then((response) => ({
...response,
body: new OperatorInstance(operationVersion, response.body, instance._solution.id),
}));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
update(params, headers, callback) {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
}
let data = {};
data = params;
if (headers === null || headers === undefined) {
headers = {};
}
headers["Content-Type"] = "application/json";
headers["Accept"] = "application/json";
const instance = this;
let operationVersion = instance._version, operationPromise = operationVersion.update({
uri: instance._uri,
method: "put",
data,
headers,
});
operationPromise = operationPromise.then((payload) => new OperatorInstance(operationVersion, payload, instance._solution.id));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
updateWithHttpInfo(params, headers, callback) {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
}
let data = {};
data = params;
if (headers === null || headers === undefined) {
headers = {};
}
headers["Content-Type"] = "application/json";
headers["Accept"] = "application/json";
const instance = this;
let operationVersion = instance._version;
// CREATE, FETCH, UPDATE operations
let operationPromise = operationVersion
.updateWithResponseInfo({
uri: instance._uri,
method: "put",
data,
headers,
})
.then((response) => ({
...response,
body: new OperatorInstance(operationVersion, response.body, instance._solution.id),
}));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
/**
* Provide a user-friendly representation
*
* @returns Object
*/
toJSON() {
return this._solution;
}
[util_1.inspect.custom](_depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.OperatorContextImpl = OperatorContextImpl;
/**
* A Language Operator resource.
*/
class OperatorInstance {
constructor(_version, _payload, id) {
this._version = _version;
const payload = _payload;
this.id = payload.id;
this.displayName = payload.displayName;
this.description = payload.description;
this.version = deserialize.integer(payload.version);
this.author = payload.author;
this.prompt = payload.prompt;
this.outputFormat = payload.outputFormat;
this.outputSchema = payload.outputSchema;
this.trainingExamples =
payload.trainingExamples !== null &&
payload.trainingExamples !== undefined
? payload.trainingExamples.map((payload) => new OperatorTrainingExample(payload))
: null;
this.context =
payload.context !== null && payload.context !== undefined
? new OperatorContext(payload.context)
: null;
this.parameters = payload.parameters;
this._solution = { id: id };
}
get _proxy() {
this._context =
this._context ||
new OperatorContextImpl(this._version, this._solution.id);
return this._context;
}
/**
* Remove a OperatorInstance
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed boolean
*/
remove(callback) {
return this._proxy.remove(callback);
}
/**
* Remove a OperatorInstance and return HTTP info
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed boolean with HTTP metadata
*/
removeWithHttpInfo(callback) {
return this._proxy.removeWithHttpInfo(callback);
}
/**
* Fetch a OperatorInstance
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed OperatorInstance
*/
fetch(callback) {
return this._proxy.fetch(callback);
}
/**
* Fetch a OperatorInstance and return HTTP info
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed OperatorInstance with HTTP metadata
*/
fetchWithHttpInfo(callback) {
return this._proxy.fetchWithHttpInfo(callback);
}
update(params, callback) {
return this._proxy.update(params, callback);
}
updateWithHttpInfo(params, callback) {
return this._proxy.updateWithHttpInfo(params, callback);
}
/**
* Provide a user-friendly representation
*
* @returns Object
*/
toJSON() {
return {
id: this.id,
displayName: this.displayName,
description: this.description,
version: this.version,
author: this.author,
prompt: this.prompt,
outputFormat: this.outputFormat,
outputSchema: this.outputSchema,
trainingExamples: this.trainingExamples,
context: this.context,
parameters: this.parameters,
};
}
[util_1.inspect.custom](_depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.OperatorInstance = OperatorInstance;
function OperatorListInstance(version) {
const instance = ((id) => instance.get(id));
instance.get = function get(id) {
return new OperatorContextImpl(version, id);
};
instance._version = version;
instance._solution = {};
instance._uri = `/ControlPlane/Operators`;
instance.create = function create(params, headers, callback) {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
}
let data = {};
data = params;
if (headers === null || headers === undefined) {
headers = {};
}
headers["Content-Type"] = "application/json";
headers["Accept"] = "application/json";
let operationVersion = version, operationPromise = operationVersion.create({
uri: instance._uri,
method: "post",
data,
headers,
});
operationPromise = operationPromise.then((payload) => new OperatorInstance(operationVersion, payload));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
};
instance.createWithHttpInfo = function createWithHttpInfo(params, headers, callback) {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
}
let data = {};
data = params;
if (headers === null || headers === undefined) {
headers = {};
}
headers["Content-Type"] = "application/json";
headers["Accept"] = "application/json";
let operationVersion = version;
// CREATE, FETCH, UPDATE operations
let operationPromise = operationVersion
.createWithResponseInfo({
uri: instance._uri,
method: "post",
data,
headers,
})
.then((response) => ({
...response,
body: new OperatorInstance(operationVersion, response.body),
}));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
};
instance.page = function page(params, callback) {
if (params instanceof Function) {
callback = params;
params = {};
}
else {
params = params || {};
}
let data = {};
if (params["pageSize"] !== undefined)
data["pageSize"] = params["pageSize"];
if (params["pageToken"] !== undefined)
data["pageToken"] = params["pageToken"];
const headers = {};
headers["Accept"] = "application/json";
let operationVersion = version, operationPromise = operationVersion.page({
uri: instance._uri,
method: "get",
params: data,
headers,
});
operationPromise = operationPromise.then((payload) => new OperatorPage(operationVersion, payload, instance._uri, data, instance._solution));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
};
instance.each = instance._version.each;
instance.list = instance._version.list;
instance.getPage = function getPage(targetUrl, callback) {
const operationPromise = instance._version._domain.twilio.request({
method: "get",
uri: targetUrl,
});
let pagePromise = operationPromise.then((payload) => new OperatorPage(instance._version, payload, instance._uri, {}, instance._solution));
pagePromise = instance._version.setPromiseCallback(pagePromise, callback);
return pagePromise;
};
instance.pageWithHttpInfo = function pageWithHttpInfo(params, callback) {
if (params instanceof Function) {
callback = params;
params = {};
}
else {
params = params || {};
}
let data = {};
if (params["pageSize"] !== undefined)
data["pageSize"] = params["pageSize"];
if (params["pageToken"] !== undefined)
data["pageToken"] = params["pageToken"];
const headers = {};
headers["Accept"] = "application/json";
let operationVersion = version;
// For page operations, use page() directly as it already returns { statusCode, body, headers }
// IMPORTANT: Pass full response to Page constructor, not response.body
let operationPromise = operationVersion
.page({ uri: instance._uri, method: "get", params: data, headers })
.then((response) => ({
statusCode: response.statusCode,
headers: response.headers,
body: new OperatorPage(operationVersion, response, instance._uri, data, instance._solution),
}));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
};
instance.each = instance._version.each;
instance.eachWithHttpInfo = instance._version.eachWithHttpInfo;
instance.list = instance._version.list;
instance.listWithHttpInfo = instance._version.listWithHttpInfo;
instance.getPageWithHttpInfo = function getPageWithHttpInfo(targetUrl, callback) {
// Use request() directly as it already returns { statusCode, body, headers }
const operationPromise = instance._version._domain.twilio.request({
method: "get",
uri: targetUrl,
});
let pagePromise = operationPromise.then((response) => ({
statusCode: response.statusCode,
headers: response.headers,
body: new OperatorPage(instance._version, response, instance._uri, {}, instance._solution),
}));
pagePromise = instance._version.setPromiseCallback(pagePromise, callback);
return pagePromise;
};
instance.toJSON = function toJSON() {
return instance._solution;
};
instance[util_1.inspect.custom] = function inspectImpl(_depth, options) {
return (0, util_1.inspect)(instance.toJSON(), options);
};
return instance;
}
class OperatorPage extends TokenPage_1.default {
/**
* Initialize the OperatorPage
*
* @param version - Version of the resource
* @param response - Response from the API
* @param uri - URI of the resource
* @param params - Query parameters
* @param solution - Path solution
*/
constructor(version, response, uri, params, solution) {
super(version, response, uri, params, solution);
}
/**
* Build an instance of OperatorInstance
*
* @param payload - Payload response from the API
*/
getInstance(payload) {
return new OperatorInstance(this._version, payload);
}
[util_1.inspect.custom](depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.OperatorPage = OperatorPage;