@vonage/voice
Version:
The Voice API lets you create outbound calls, control in-progress calls and get information about historical calls.
160 lines • 5.49 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Connect = void 0;
const enums_1 = require("../../enums");
/**
* Represents a Connect action in the Nexmo Call Control Object (NCCO) for making voice calls.
*/
class Connect {
/**
* The action type, which is always 'connect'.
*/
action = enums_1.NCCOActions.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: enums_1.NCCOActions.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;
}
}
exports.Connect = Connect;
//# sourceMappingURL=Connect.js.map