UNPKG

@onereach/step-voice

Version:
83 lines (82 loc) 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const joi_1 = tslib_1.__importDefault(require("joi")); const voice_1 = tslib_1.__importDefault(require("./voice")); const schema = joi_1.default.object().keys({ dtmf: joi_1.default .string() .required() .replace(/\s+/, '') .pattern(/^[0-9A-DwW*#]+$/, 'symbols') .messages({ 'string.pattern.symbols': '{{#label}} should only contain symbols like: 0-9, *, #, A-D, W, w' }), tonesDuration: joi_1.default.number().required().min(200).max(5000).messages({ 'number.min': '{{#label}} should be between 200 and 5000 milliseconds', 'number.max': '{{#label}} should be between 200 and 5000 milliseconds' }), beforeDelay: joi_1.default.number().required().min(0).max(5000).messages({ 'number.min': '{{#label}} should be between 0 and 5000 milliseconds', 'number.max': '{{#label}} should be between 0 and 5000 milliseconds' }), afterDelay: joi_1.default.number().required().min(0).max(5000).messages({ 'number.min': '{{#label}} should be between 0 and 5000 milliseconds', 'number.max': '{{#label}} should be between 0 and 5000 milliseconds' }) }); class SendDTMF extends voice_1.default { async runStep() { const call = await this.fetchData(); const { dtmf, tonesDuration, beforeDelay, afterDelay } = this.data; const { error: validationError } = await schema.validateAsync({ dtmf, tonesDuration, beforeDelay, afterDelay }); if (validationError != null) throw new Error(validationError.message); const command = { name: 'send-dtmf', params: { dtmf, tonesDuration: +tonesDuration, beforeDelay: +beforeDelay, afterDelay: +afterDelay } }; this.triggers.local(`in/voice/${call.id}`, async (event) => { // if (channel.callback.id) // await this.mergeFields[_conversation].set( // this.takeCallback(), // "callback" // ); switch (event.params.type) { case 'hangup': await this.handleHangup(call); return await this.waitConvEnd(); case 'dtmf-sent': return this.exitStep('next'); case 'error': return this.throwError(event.params.error); case 'cancel': return this.handleCancel(); default: return this.exitFlow(); } }); this.triggers.otherwise(async () => { await this.transcript(call, { reportingSettingsKey: 'transcript', action: 'Send DTMF', actionFromBot: true, keyPress: dtmf, message: dtmf }); await this.sendCommands(call, [command]); return this.exitFlow(); }); } } exports.default = SendDTMF;