@vonage/voice
Version:
The Voice API lets you create outbound calls, control in-progress calls and get information about historical calls.
181 lines (179 loc) • 5.79 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// lib/classes/NCCO/Connect.ts
var Connect_exports = {};
__export(Connect_exports, {
Connect: () => Connect
});
module.exports = __toCommonJS(Connect_exports);
var Connect = class {
/**
* The action type, which is always 'connect'.
*/
action = "connect" /* CONNECT */;
/**
* An array of CallEndpoint objects representing the endpoints to connect to in the call.
*
* @param {CallEndpoint} endpoint - An array of CallEndpoint objects
* representing the endpoints to connect to in the call.
*/
endpoint;
/**
* The caller's phone number to display as the caller ID.
*
* @param {string} from - The caller's phone number to display as the caller ID.
*/
from;
/**
* Set to true to use a random phone number as the caller ID from the list of
* numbers assigned to the current application.
*
* @param {boolean} randomFromNumber - Set to true to use a random phone number as the caller ID.
*/
randomFromNumber;
/**
* The event type for call progress events sent to the specified event URL.
*
* @param {ConnectEventType} eventType - The event type for call progress events.
*/
eventType;
/**
* The time in seconds that Vonage waits for the call to be answered before timing out.
*
* @param {number} timeout - The timeout value in seconds.
*/
timeout;
/**
* The maximum number of concurrent calls that can be handled by your application.
*
* @param {number} limit - The maximum number of concurrent calls.
*/
limit;
/**
* Configure the behavior when Vonage detects that the call is answered by voicemail.
*
* @param {MachineDetection} machineDetection - The behavior when voicemail is detected.
*/
machineDetection;
/**
* An array of event URLs where call progress events are sent to. Multiple URLs can be specified.
*
* @param {string} eventUrl - An array of event URLs.
*/
eventUrl;
/**
* The HTTP method used to send event information to the event URL(s).
*
* @param {string} eventMethod - The HTTP method used for event callbacks.
*/
eventMethod;
/**
* The URL of a ringback tone to play to the caller while waiting for the call to be answered.
*
* @param {string} ringbackTone - The URL of the ringback tone audio file.
*/
ringbackTone;
/**
* Create a new Connect instance.
*
* @param {CallEndpoint} endpoint - An array of CallEndpoint objects representing the endpoints to connect to in the call.
* @param {string} from - The caller's phone number to display as the caller ID.
* @param {boolean} randomFromNumber - Set to true to use a random phone number as the caller ID.
* @param {ConnectEventType} eventType - The event type for call progress events.
* @param {number} timeout - The timeout value in seconds.
* @param {number} limit - The maximum number of concurrent calls.
* @param {MachineDetection} machineDetection - The behavior when voicemail is detected.
* @param {string} eventUrl - An array of event URLs.
* @param {string} eventMethod - The HTTP method used for event callbacks.
* @param {string} ringbackTone - The URL of the ringback tone audio file.
*/
constructor(endpoint, from, randomFromNumber, eventType, timeout, limit, machineDetection, eventUrl, eventMethod, ringbackTone) {
this.endpoint = [endpoint];
if (from) {
this.from = from;
}
if (randomFromNumber) {
this.randomFromNumber = randomFromNumber;
}
if (eventType) {
this.eventType = eventType;
}
if (timeout) {
this.timeout = timeout;
}
if (limit) {
this.limit = limit;
}
if (machineDetection) {
this.machineDetection = machineDetection;
}
if (eventUrl) {
this.eventUrl = [eventUrl];
}
if (eventMethod) {
this.eventMethod = eventMethod;
}
if (ringbackTone) {
this.ringbackTone = ringbackTone;
}
}
/**
* Serialize the Connect action to a Nexmo Call Control Object (NCCO) format.
*
* @return {ConnectAction} - The serialized Connect action.
*/
serializeToNCCO() {
const data = {
action: "connect" /* CONNECT */,
endpoint: this.endpoint
};
if (this.from) {
data.from = this.from;
}
if (this.randomFromNumber) {
data.randomFromNumber = this.randomFromNumber;
}
if (this.eventType) {
data.eventType = this.eventType;
}
if (this.timeout) {
data.timeout = this.timeout;
}
if (this.limit) {
data.limit = this.limit;
}
if (this.machineDetection) {
data.machineDetection = this.machineDetection;
}
if (this.eventUrl) {
data.eventUrl = this.eventUrl;
}
if (this.eventMethod) {
data.eventMethod = this.eventMethod;
}
if (this.ringbackTone) {
data.ringbackTone = this.ringbackTone;
}
return data;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Connect
});