UNPKG

@vonage/voice

Version:

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

97 lines (95 loc) 2.35 kB
// lib/classes/NCCO/Input.ts var Input = class { /** * The action type, which is always 'input'. */ action = "input" /* INPUT */; /** * An array of input types ('dtmf' and/or 'speech'). */ type = []; /** * DTMF input settings. */ dtmf; /** * Speech input settings. */ speech; /** * An array of URLs to send events to asynchronously. */ eventUrl = []; /** * The HTTP method used to send events (e.g., 'POST' or 'GET'). */ eventMethod; /** * Input processing mode, currently only applicable to DTMF. Valid values are * synchronous (the default) and asynchronous. If set to asynchronous, all * DTMF settings must be left blank. In asynchronous mode, digits are sent one * at a time to the event webhook in real time. In the default synchronous * mode, this is controlled by the DTMF settings instead and the inputs are * sent in batch. */ mode; /** * Create a new Input instance. * * @param {DTMFSettings} dtmf - DTMF input settings. * @param {SpeechSettings} speech - Speech input settings. * @param {string} eventUrl - URL to send events to asynchronously. * @param {string} eventMethod - The HTTP method used to send events. */ constructor(dtmf, speech, eventUrl, eventMethod, mode) { if (dtmf) { this.type.push("dtmf"); this.dtmf = dtmf; } if (speech) { this.type.push("speech"); this.speech = speech; } if (eventUrl) { this.eventUrl = [eventUrl]; } if (eventMethod) { this.eventMethod = eventMethod; } if (mode) { this.mode = mode; } if (this.type.length === 0) { throw new TypeError( "Input action must have at least either DTMF or Speech settings" ); } } /** * Serialize the Input action to a Nexmo Call Control Object (NCCO) format. * * @return {InputAction} - The serialized Input action. */ serializeToNCCO() { const data = { action: "input" /* INPUT */, type: this.type }; if (this.dtmf) { data.dtmf = this.dtmf; } if (this.speech) { data.speech = this.speech; } if (this.eventUrl) { data.eventUrl = this.eventUrl; } if (this.eventMethod) { data.eventMethod = this.eventMethod; } return data; } }; export { Input };