twilio
Version:
A Twilio helper library
551 lines (550 loc) • 21.6 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportInstance = exports.ReportContextImpl = exports.VoiceIntegrityCallsPerBundle = exports.VoiceIntegrity = exports.StirShakenPercentage = exports.StirShakenCallCount = exports.StirShakenAnswerRate = exports.StirShaken = exports.ReportMetadata = exports.ReportFilter = exports.InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection = exports.InsightsV2InboundPhoneNumberReportCallStatePercentage = exports.InsightsV2CreateAccountReportRequestTimeRange = exports.InsightsV2CreateAccountReportRequest = exports.CountyCarrierValueCarriers = exports.CountyCarrierValue = exports.BrandedUseCaseDetail = exports.BrandedCalling = exports.AccountReportNetworkIssuesTwilioGateway = exports.AccountReportNetworkIssuesSdk = exports.AccountReportNetworkIssues = exports.AccountReportKYTOutboundCarrierCalling = exports.AccountReportKYT = exports.AccountReportCallType = exports.AccountReportCallState = exports.AccountReportCallDirection = exports.AccountReportAnsweringMachineDetection = exports.AccountReport = void 0;
exports.ReportListInstance = ReportListInstance;
const util_1 = require("util");
const deserialize = require("../../../base/deserialize");
const serialize = require("../../../base/serialize");
const utility_1 = require("../../../base/utility");
class AccountReport {
constructor(payload) {
this.callDeliverabilityScore = payload["call_deliverability_score"];
this.callAnswerScore = payload["call_answer_score"];
this.totalCalls = payload["total_calls"];
this.callDirection = payload["call_direction"];
this.callState = payload["call_state"];
this.callType = payload["call_type"];
this.aloc = payload["aloc"];
this.twilioEdgeLocation = payload["twilio_edge_location"];
this.callerCountryCode = payload["caller_country_code"];
this.calleeCountryCode = payload["callee_country_code"];
this.averageQueueTimeMs = payload["average_queue_time_ms"];
this.silentCallsPercentage = payload["silent_calls_percentage"];
this.networkIssues = payload["network_issues"];
this.kYT = payload["KYT"];
this.answeringMachineDetection = payload["answering_machine_detection"];
}
}
exports.AccountReport = AccountReport;
/**
* Number of calls made in each answering machine detection.
*/
class AccountReportAnsweringMachineDetection {
constructor(payload) {
this.totalCalls = payload["total_calls"];
this.answeredByHumanPercentage = payload["answered_by_human_percentage"];
this.answeredByMachinePercentage =
payload["answered_by_machine_percentage"];
}
}
exports.AccountReportAnsweringMachineDetection = AccountReportAnsweringMachineDetection;
/**
* Number of calls made in each direction.
*/
class AccountReportCallDirection {
constructor(payload) {
this.outbound = payload["outbound"];
this.inbound = payload["inbound"];
}
}
exports.AccountReportCallDirection = AccountReportCallDirection;
/**
* Number of calls made in each state.
*/
class AccountReportCallState {
constructor(payload) {
this.completed = payload["completed"];
this.fail = payload["fail"];
this.busy = payload["busy"];
this.noanswer = payload["noanswer"];
this.canceled = payload["canceled"];
}
}
exports.AccountReportCallState = AccountReportCallState;
/**
* Number of calls made in each type. `carrier`, `sip`, `trunking`, `client`, `whatsapp`
*/
class AccountReportCallType {
constructor(payload) {
this.carrier = payload["carrier"];
this.sip = payload["sip"];
this.trunking = payload["trunking"];
this.client = payload["client"];
this.whatsapp = payload["whatsapp"];
}
}
exports.AccountReportCallType = AccountReportCallType;
/**
* Know Your Traffic (KYT) metrics focused on outbound carrier performance and trust signals for the report period.
*/
class AccountReportKYT {
constructor(payload) {
this.outboundCarrierCalling = payload["outbound_carrier_calling"];
}
}
exports.AccountReportKYT = AccountReportKYT;
/**
* KYT metrics for outbound carrier calling.
*/
class AccountReportKYTOutboundCarrierCalling {
constructor(payload) {
this.uniqueCallingNumbers = payload["unique_calling_numbers"];
this.uniqueCalledNumbers = payload["unique_called_numbers"];
this.blockedCallsByCarrier = payload["blocked_calls_by_carrier"];
this.shortDurationCallsPercentage =
payload["short_duration_calls_percentage"];
this.longDurationCallsPercentage =
payload["long_duration_calls_percentage"];
this.potentialRobocallsPercentage =
payload["potential_robocalls_percentage"];
this.brandedCalling = payload["branded_calling"];
this.voiceIntegrity = payload["voice_integrity"];
this.stirShaken = payload["stir_shaken"];
}
}
exports.AccountReportKYTOutboundCarrierCalling = AccountReportKYTOutboundCarrierCalling;
/**
* Network-quality indicators for SDK and Twilio Gateway traffic during the report period.
*/
class AccountReportNetworkIssues {
constructor(payload) {
this.sdk = payload["sdk"];
this.twilioGateway = payload["twilio_gateway"];
}
}
exports.AccountReportNetworkIssues = AccountReportNetworkIssues;
/**
* Network issues of calls for client type. This is indicative of local network issues.
*/
class AccountReportNetworkIssuesSdk {
constructor(payload) {
this.iceFailuresPercentage = payload["ice_failures_percentage"];
this.highLatencyPercentage = payload["high_latency_percentage"];
this.highPacketLossPercentage = payload["high_packet_loss_percentage"];
this.highJitterPercentage = payload["high_jitter_percentage"];
}
}
exports.AccountReportNetworkIssuesSdk = AccountReportNetworkIssuesSdk;
/**
* Network related metrics for Twilio Gateway calls only.
*/
class AccountReportNetworkIssuesTwilioGateway {
constructor(payload) {
this.highLatencyPercentage = payload["high_latency_percentage"];
this.highPacketLossPercentage = payload["high_packet_loss_percentage"];
this.highJitterPercentage = payload["high_jitter_percentage"];
}
}
exports.AccountReportNetworkIssuesTwilioGateway = AccountReportNetworkIssuesTwilioGateway;
/**
* Metrics related to Branded Calling bundled calls including CTIA for the report period.
*/
class BrandedCalling {
constructor(payload) {
this.totalBrandedCalls = payload["total_branded_calls"];
this.percentBrandedCalls = payload["percent_branded_calls"];
this.answerRate = payload["answer_rate"];
this.humanAnswerRate = payload["human_answer_rate"];
this.engagementRate = payload["engagement_rate"];
this.byUseCase = payload["by_use_case"];
}
}
exports.BrandedCalling = BrandedCalling;
/**
* Associated metrics for Branded calls grouped by each use case.
*/
class BrandedUseCaseDetail {
constructor(payload) {
this.useCase = payload["use_case"];
this.enabledPhonenumbers = payload["enabled_phonenumbers"];
this.totalCalls = payload["total_calls"];
this.answerRate = payload["answer_rate"];
this.humanAnswerRate = payload["human_answer_rate"];
this.engagementRate = payload["engagement_rate"];
}
}
exports.BrandedUseCaseDetail = BrandedUseCaseDetail;
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 InsightsV2CreateAccountReportRequest {
constructor(payload) {
this.timeRange = payload["time_range"];
this.filters = payload["filters"];
}
}
exports.InsightsV2CreateAccountReportRequest = InsightsV2CreateAccountReportRequest;
/**
* Optional start and end date time for the report window. Defaults to the most recent 7 days when omitted.
*/
class InsightsV2CreateAccountReportRequestTimeRange {
constructor(payload) {
this.startTime = payload["start_time"];
this.endTime = payload["end_time"];
}
}
exports.InsightsV2CreateAccountReportRequestTimeRange = InsightsV2CreateAccountReportRequestTimeRange;
/**
* 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 ReportFilter {
constructor(payload) {
this.key = payload["key"];
this.values = payload["values"];
}
}
exports.ReportFilter = ReportFilter;
class ReportMetadata {
constructor(payload) {
this.startTime = payload["start_time"];
this.endTime = payload["end_time"];
this.filters = payload["filters"];
}
}
exports.ReportMetadata = ReportMetadata;
/**
* Metrics related to STIR/SHAKEN attestation A, B, and C for the report period.
*/
class StirShaken {
constructor(payload) {
this.callCount = payload["call_count"];
this.percentage = payload["percentage"];
this.answerRate = payload["answer_rate"];
}
}
exports.StirShaken = StirShaken;
/**
* Answer rate for each STIR/SHAKEN attestation category.
*/
class StirShakenAnswerRate {
constructor(payload) {
this.stshA = payload["stsh_a"];
this.stshB = payload["stsh_b"];
this.stshC = payload["stsh_c"];
}
}
exports.StirShakenAnswerRate = StirShakenAnswerRate;
/**
* Total number of calls for each STIR/SHAKEN attestation category.
*/
class StirShakenCallCount {
constructor(payload) {
this.stshA = payload["stsh_a"];
this.stshB = payload["stsh_b"];
this.stshC = payload["stsh_c"];
}
}
exports.StirShakenCallCount = StirShakenCallCount;
/**
* Percentage of calls for each STIR/SHAKEN attestation category.
*/
class StirShakenPercentage {
constructor(payload) {
this.stshA = payload["stsh_a"];
this.stshB = payload["stsh_b"];
this.stshC = payload["stsh_c"];
}
}
exports.StirShakenPercentage = StirShakenPercentage;
/**
* Metrics related to Voice Integrity enabled calls for the report period.
*/
class VoiceIntegrity {
constructor(payload) {
this.enabledCalls = payload["enabled_calls"];
this.enabledPercentage = payload["enabled_percentage"];
this.callsPerBundle = payload["calls_per_bundle"];
}
}
exports.VoiceIntegrity = VoiceIntegrity;
class VoiceIntegrityCallsPerBundle {
constructor(payload) {
this.bundleSid = payload["bundle_sid"];
this.enabledPhonenumbers = payload["enabled_phonenumbers"];
this.totalCalls = payload["total_calls"];
this.answerRate = payload["answer_rate"];
this.humanAnswerRate = payload["human_answer_rate"];
}
}
exports.VoiceIntegrityCallsPerBundle = VoiceIntegrityCallsPerBundle;
class ReportContextImpl {
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/${reportId}`;
}
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 ReportInstance(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 ReportInstance(operationVersion, response.body, instance._solution.reportId),
}));
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 ReportInstance(operationVersion, payload, instance._solution.reportId));
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 ReportInstance(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.ReportContextImpl = ReportContextImpl;
class ReportInstance {
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.report =
payload.report !== null && payload.report !== undefined
? new AccountReport(payload.report)
: null;
this._solution = { reportId: reportId || this.reportId };
}
get _proxy() {
this._context =
this._context ||
new ReportContextImpl(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);
}
/**
* Fetch a ReportInstance
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed ReportInstance
*/
fetch(callback) {
return this._proxy.fetch(callback);
}
/**
* Fetch a ReportInstance and return HTTP info
*
* @param callback - Callback to handle processed record
*
* @returns Resolves to processed ReportInstance with HTTP metadata
*/
fetchWithHttpInfo(callback) {
return this._proxy.fetchWithHttpInfo(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,
report: this.report,
};
}
[util_1.inspect.custom](_depth, options) {
return (0, util_1.inspect)(this.toJSON(), options);
}
}
exports.ReportInstance = ReportInstance;
function ReportListInstance(version) {
const instance = ((reportId) => instance.get(reportId));
instance.get = function get(reportId) {
return new ReportContextImpl(version, reportId);
};
instance._version = version;
instance._solution = {};
instance._uri = ``;
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;
}