twilio
Version:
A Twilio helper library
393 lines (392 loc) • 16 kB
JavaScript
"use strict";
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Sample/reference Twilio API.
* This is the reference API for the rest-proxy server.
*
* 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.OutboundPage = exports.OutboundInstance = exports.OutboundContextImpl = exports.ReportMetadata = exports.ReportFilter = exports.PhoneNumberReportFilter = exports.InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection = exports.InsightsV2InboundPhoneNumberReportCallStatePercentage = exports.InsightsV2CreatePhoneNumbersReportRequestTimeRange = exports.InsightsV2CreatePhoneNumbersReportRequest = exports.CountyCarrierValueCarriers = exports.CountyCarrierValue = void 0;
exports.OutboundListInstance = OutboundListInstance;
const util_1 = require("util");
const Page_1 = __importDefault(require("../../../base/Page"));
const deserialize = require("../../../base/deserialize");
const serialize = require("../../../base/serialize");
const utility_1 = require("../../../base/utility");
class CountyCarrierValue {
constructor(payload) {
this.country = payload["country"];
this.carriers = payload["carriers"];
}
}
exports.CountyCarrierValue = CountyCarrierValue;
class CountyCarrierValueCarriers {
constructor(payload) {
this.carrier = payload["carrier"];
this.totalCalls = payload["total_calls"];
this.blockedCalls = payload["blocked_calls"];
this.blockedCallsPercentage = payload["blocked_calls_percentage"];
}
}
exports.CountyCarrierValueCarriers = CountyCarrierValueCarriers;
class InsightsV2CreatePhoneNumbersReportRequest {
constructor(payload) {
this.timeRange = payload["time_range"];
this.filters = payload["filters"];
this.size = payload["size"];
}
}
exports.InsightsV2CreatePhoneNumbersReportRequest = InsightsV2CreatePhoneNumbersReportRequest;
class InsightsV2CreatePhoneNumbersReportRequestTimeRange {
constructor(payload) {
this.startDatetime = payload["start_datetime"];
this.endDatetime = payload["end_datetime"];
}
}
exports.InsightsV2CreatePhoneNumbersReportRequestTimeRange = InsightsV2CreatePhoneNumbersReportRequestTimeRange;
/**
* Percentage of calls made in each state.
*/
class InsightsV2InboundPhoneNumberReportCallStatePercentage {
constructor(payload) {
this.completed = payload["completed"];
this.fail = payload["fail"];
this.busy = payload["busy"];
this.noanswer = payload["noanswer"];
this.canceled = payload["canceled"];
}
}
exports.InsightsV2InboundPhoneNumberReportCallStatePercentage = InsightsV2InboundPhoneNumberReportCallStatePercentage;
/**
* Number of calls made in answering machine detection (AMD) enabled.
*/
class InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection {
constructor(payload) {
this.totalCalls = payload["total_calls"];
this.answeredByHumanPercentage = payload["answered_by_human_percentage"];
this.answeredByMachinePercentage =
payload["answered_by_machine_percentage"];
}
}
exports.InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection = InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection;
class PhoneNumberReportFilter {
constructor(payload) {
this.key = payload["key"];
this.values = payload["values"];
}
}
exports.PhoneNumberReportFilter = PhoneNumberReportFilter;
class ReportFilter {
constructor(payload) {
this.key = payload["key"];
this.values = payload["values"];
}
}
exports.ReportFilter = ReportFilter;
class ReportMetadata {
constructor(payload) {
this.startDatetime = payload["start_datetime"];
this.endDatetime = payload["end_datetime"];
this.filters = payload["filters"];
}
}
exports.ReportMetadata = ReportMetadata;
class OutboundContextImpl {
constructor(_version, reportId) {
this._version = _version;
if (!(0, utility_1.isValidPathParam)(reportId)) {
throw new Error("Parameter 'reportId' is not valid.");
}
this._solution = { reportId };
this._uri = `/Voice/Reports/PhoneNumbers/Outbound`;
}
create(params, headers, callback) {
if (params instanceof Function) {
callback = params;
params = {};
}
else {
params = params || {};
}
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.create({
uri: instance._uri,
method: "post",
data,
headers,
});
operationPromise = operationPromise.then((payload) => new OutboundInstance(operationVersion, payload, instance._solution.reportId));
operationPromise = instance._version.setPromiseCallback(operationPromise, callback);
return operationPromise;
}
createWithHttpInfo(params, headers, callback) {
if (params instanceof Function) {
callback = params;
params = {};
}
else {
params = params || {};
}
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
.createWithResponseInfo({
uri: instance._uri,
method: "post",
data,
headers,
})
.then((response) => ({
...response,
body: new OutboundInstance(operationVersion, response.body, instance._solution.reportId),
}));
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.OutboundContextImpl = OutboundContextImpl;
class OutboundInstance {
constructor(_version, payload, reportId) {
this._version = _version;
this.accountSid = payload.account_sid;
this.reportId = payload.report_id;
this.status = payload.status;
this.requestMeta =
payload.request_meta !== null && payload.request_meta !== undefined
? new ReportMetadata(payload.request_meta)
: null;
this.url = payload.url;
this.handle = payload.handle;
this.totalCalls = deserialize.integer(payload.total_calls);
this.callAnswerScore = payload.call_answer_score;
this.callStatePercentage =
payload.call_state_percentage !== null &&
payload.call_state_percentage !== undefined
? new InsightsV2InboundPhoneNumberReportCallStatePercentage(payload.call_state_percentage)
: null;
this.silentCallsPercentage = payload.silent_calls_percentage;
this.callsByDeviceType = payload.calls_by_device_type;
this.answerRateDeviceType = payload.answer_rate_device_type;
this.blockedCallsByCarrier =
payload.blocked_calls_by_carrier !== null &&
payload.blocked_calls_by_carrier !== undefined
? payload.blocked_calls_by_carrier.map((payload) => new CountyCarrierValue(payload))
: null;
this.shortDurationCallsPercentage = payload.short_duration_calls_percentage;
this.longDurationCallsPercentage = payload.long_duration_calls_percentage;
this.potentialRobocallsPercentage = payload.potential_robocalls_percentage;
this.answeringMachineDetection =
payload.answering_machine_detection !== null &&
payload.answering_machine_detection !== undefined
? new InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection(payload.answering_machine_detection)
: null;
this._solution = { reportId: reportId || this.reportId };
}
get _proxy() {
this._context =
this._context ||
new OutboundContextImpl(this._version, this._solution.reportId);
return this._context;
}
create(params, callback) {
return this._proxy.create(params, callback);
}
createWithHttpInfo(params, callback) {
return this._proxy.createWithHttpInfo(params, callback);
}
/**
* Provide a user-friendly representation
*
* @returns Object
*/
toJSON() {
return {
accountSid: this.accountSid,
reportId: this.reportId,
status: this.status,
requestMeta: this.requestMeta,
url: this.url,
handle: this.handle,
totalCalls: this.totalCalls,
callAnswerScore: this.callAnswerScore,
callStatePercentage: this.callStatePercentage,
silentCallsPercentage: this.silentCallsPercentage,
callsByDeviceType: this.callsByDeviceType,
answerRateDeviceType: this.answerRateDeviceType,
blockedCallsByCarrier: this.blockedCallsByCarrier,
shortDurationCallsPercentage: this.shortDurationCallsPercentage,
longDurationCallsPercentage: this.longDurationCallsPercentage,
potentialRobocallsPercentage: this.potentialRobocallsPercentage,
answeringMachineDetection: this.answeringMachineDetection,
};
}
[util_1.inspect.custom](_depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.OutboundInstance = OutboundInstance;
function OutboundListInstance(version, reportId) {
if (!(0, utility_1.isValidPathParam)(reportId)) {
throw new Error("Parameter 'reportId' is not valid.");
}
const instance = ((reportId) => instance.get(reportId));
instance.get = function get(reportId) {
return new OutboundContextImpl(version, reportId);
};
instance._version = version;
instance._solution = { reportId };
instance._uri = `/Voice/Reports/PhoneNumbers/Outbound/${reportId}`;
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.pageNumber !== undefined)
data["Page"] = params.pageNumber;
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 OutboundPage(operationVersion, payload, 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 OutboundPage(instance._version, payload, 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.pageNumber !== undefined)
data["Page"] = params.pageNumber;
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 OutboundPage(operationVersion, response, 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 OutboundPage(instance._version, response, 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 OutboundPage extends Page_1.default {
/**
* Initialize the OutboundPage
*
* @param version - Version of the resource
* @param response - Response from the API
* @param solution - Path solution
*/
constructor(version, response, solution) {
super(version, response, solution);
}
/**
* Build an instance of OutboundInstance
*
* @param payload - Payload response from the API
*/
getInstance(payload) {
return new OutboundInstance(this._version, payload, this._solution.reportId);
}
[util_1.inspect.custom](depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.OutboundPage = OutboundPage;