UNPKG

@vonage/voice

Version:

The Voice API lets you create outbound calls, control in-progress calls and get information about historical calls.

262 lines (260 loc) 7.78 kB
"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/Record.ts var Record_exports = {}; __export(Record_exports, { Record: () => Record }); module.exports = __toCommonJS(Record_exports); var Record = class { /** * The action type for the Record action. */ action = "record" /* RECORD */; /** * The recording format (e.g., "mp3", "wav"). */ format; /** * The split type for recording (always "conversation"). */ wrappedSplit; /** * The number of audio channels (1 to 32). */ wrappedChannels; /** * The duration of silence (in seconds) to end the recording (3 to 10 seconds). */ wrappedEndOnSilence; /** * The DTMF key that ends the recording (e.g., "0", "*", "#"). */ wrappedEndOnKey; /** * The maximum recording duration in seconds (3 to 7200 seconds). */ wrappedTimeOut; /** * Whether to play a beep before recording starts. */ beepStart; /** * The URL where recording events will be sent. */ eventUrl; /** * The HTTP method for sending recording events (e.g., "POST"). */ eventMethod; /** * Creates a new Record action. * * @param {RecordingFormat} format - The recording format (e.g., "mp3", "wav"). * @param {string} split - The split type for recording (should be "conversation"). * @param {number} channels - The number of audio channels (1 to 32). * @param {number} endOnSilence - The duration of silence (in seconds) to end the recording (3 to 10 seconds). * @param {string} endOnKey - The DTMF key that ends the recording (e.g., "0", "*", "#"). * @param {number} timeout - The maximum recording duration in seconds (3 to 7200 seconds). * @param {boolean} beepStart - Whether to play a beep before recording starts. * @param {string} eventUrl - The URL where recording events will be sent. * @param {string} eventMethod - The HTTP method for sending recording events (e.g., "POST"). */ constructor(format, split, channels, endOnSilence, endOnKey, timeout, beepStart, eventUrl, eventMethod) { if (format) { this.format = format; } if (split) { this.split = split; } if (channels) { this.channels = channels; } if (endOnSilence) { this.endOnSilence = endOnSilence; } if (endOnKey) { this.endOnKey = endOnKey; } if (timeout) { this.timeout = timeout; } if (beepStart) { this.beepStart = beepStart; } if (eventUrl) { this.eventUrl = [eventUrl]; } if (eventMethod) { this.eventMethod = eventMethod; } } /** * Getter for the number of audio channels. * * @return {number | undefined} - The current number of audio channels. */ get channels() { return this.wrappedChannels; } /** * Setter for the number of audio channels. * * @param {number} channels - The number of audio channels (1 to 32). * @throws {Error} - If the channel value is invalid or split is not set to "conversation." */ set channels(channels) { if (channels < 1 || channels > 32) { throw new Error("Channels must be between 1 and 32, inclusive"); } if (this.wrappedSplit !== "conversation") { throw new Error( "Channels must have split set to 'conversation' before changing channel numbers" ); } this.wrappedChannels = channels; } /** * Getter for the character that signals the end of recording. * * @return {string | undefined} - The character that signals the end of recording. */ get endOnKey() { return this.wrappedEndOnKey; } /** * Setter for the DTMF key that ends the recording. * * @param {string} character - The DTMF key that ends the recording (e.g., "0", "*", "#"). * @throws {Error} - If the character is not a valid DTMF key. */ set endOnKey(character) { const re = /^[0-9*#]$/; if (!re.test(character)) { throw new Error("Valid characters are 0-9, *, and # only"); } this.wrappedEndOnKey = character; } /** * Getter for the duration of silence (in seconds) that signals the end of recording. * * @return {number | undefined} - The duration of silence (in seconds) that signals the end of recording. */ get endOnSilence() { return this.wrappedEndOnSilence; } /** * Setter for the duration of silence to end the recording. * * @param {number} numSeconds - The duration of silence in seconds (3 to 10 seconds). * @throws {Error} - If the duration value is out of the valid range. */ set endOnSilence(numSeconds) { if (numSeconds < 3 || numSeconds > 10) { throw new Error( "End on Silence must be between 3 and 10 seconds, inclusive" ); } this.wrappedEndOnSilence = numSeconds; } /** * Getter for the recording split type. * * @return {string} - The recording split type, which is always 'conversation'. */ get split() { return "conversation"; } /** * Setter for the recording split type. * * @param {string} splitType - The recording split type. Must be set to 'conversation'. * @throws {Error} - Throws an error if the splitType is not 'conversation'. */ set split(splitType) { if (splitType !== "conversation") { throw new Error("Recording can only be split to 'conversation'"); } this.wrappedSplit = splitType; } /** * Getter for the recording timeout duration in seconds. * * @return {number | undefined } - The recording timeout duration in seconds. */ get timeout() { return this.wrappedTimeOut; } /** * Setter for the recording timeout. * * @param {number} seconds - The maximum recording duration in seconds (3 to 7200 seconds). * @throws {Error} - If the timeout value is out of the valid range. */ set timeout(seconds) { if (seconds < 3 || seconds > 7200) { throw new Error( "Recording timeout must be between 3 and 7200 seconds, inclusive" ); } this.wrappedTimeOut = seconds; } /** * Serializes the Record action to NCCO format. * * @return {RecordAction} - The serialized Record action. */ serializeToNCCO() { const data = { action: "record" /* RECORD */ }; if (this.format) { data.format = this.format; } if (this.wrappedSplit) { data.split = this.split; } if (this.wrappedChannels) { data.channels = this.wrappedChannels; } if (this.wrappedEndOnKey) { data.endOnKey = this.endOnKey; } if (this.wrappedEndOnSilence) { data.endOnSilence = this.endOnSilence; } if (this.wrappedTimeOut) { data.timeOut = this.wrappedTimeOut; } if (this.beepStart) { data.beepStart = this.beepStart; } if (this.eventUrl) { data.eventUrl = this.eventUrl; } if (this.eventMethod) { data.eventMethod = this.eventMethod; } return data; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Record });