UNPKG

ivr-tester

Version:

An automated testing framework for IVR call flows

42 lines (41 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TwilioCaller = void 0; const twilio_1 = require("twilio"); const Debugger_1 = require("../Debugger"); class TwilioCaller { constructor(twilioClient) { this.twilioClient = twilioClient; } static addParameters(stream, call) { // TODO Adding parameters throws a warning, but is even done here https://www.twilio.com/blog/media-streams-public-beta stream.parameter({ name: "from", value: call.from }); stream.parameter({ name: "to", value: call.to }); } static extractParameters(event) { var _a, _b, _c, _d; const from = (_b = (_a = event === null || event === void 0 ? void 0 : event.start) === null || _a === void 0 ? void 0 : _a.customParameters) === null || _b === void 0 ? void 0 : _b.from; const to = (_d = (_c = event === null || event === void 0 ? void 0 : event.start) === null || _c === void 0 ? void 0 : _c.customParameters) === null || _d === void 0 ? void 0 : _d.to; if (!from || !to) { throw new Error("Start Media event does not contain from/to custom parameters"); } return { from, to }; } async call(call, streamUrl) { const response = new twilio_1.twiml.VoiceResponse(); const connect = response.connect(); const stream = connect.stream({ url: streamUrl.toString(), }); TwilioCaller.addParameters(stream, call); const callOptions = { twiml: response.toString(), ...call, }; TwilioCaller.debug("Making call %O", callOptions); await this.twilioClient.calls.create(callOptions); return { type: "telephony", call }; } } exports.TwilioCaller = TwilioCaller; TwilioCaller.debug = Debugger_1.Debugger.getTwilioDebugger();