diff --git a/bin/k8s-pre-stop-hook.js b/bin/k8s-pre-stop-hook.js old mode 100755 new mode 100644 diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 52377366..5783f196 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -1187,6 +1187,38 @@ class CallSession extends Emitter { } } + /** + * perform live call control - send RFC 2833 DTMF + * @param {obj} opts + * @param {string} opts.dtmf.digit - DTMF digit + * @param {string} opts.dtmf.duration - Optional, Duration + */ + async _lccDtmf(opts, callSid) { + const {dtmf} = opts; + const {digit, duration = 250} = dtmf; + if (!this.hasStableDialog) { + this.logger.info('CallSession:_lccDtmf - invalid command as we do not have a stable call'); + return; + } + try { + const dlg = callSid === this.callSid ? this.dlg : this.currentTask.dlg; + const res = await dlg.request({ + method: 'INFO', + headers: { + 'Content-Type': 'application/dtmf', + 'X-Reason': 'Dtmf' + }, + body: `Signal=${digit} +Duration=${duration} ` + }); + this.logger.debug({res}, `CallSession:_lccDtmf + got response to INFO DTMF digit=${digit} and duration=${duration}`); + return res; + } catch (err) { + this.logger.error({err}, 'CallSession:_lccDtmf - error sending INFO RFC 2833 DTMF'); + } + } + /** * perform live call control -- whisper to one party or the other on a call * @param {array} opts - array of play or say tasks @@ -1270,6 +1302,8 @@ class CallSession extends Emitter { else if (opts.sip_request) { const res = await this._lccSipRequest(opts, callSid); return {status: res.status, reason: res.reason}; + } else if (opts.dtmf) { + await this._lccDtmf(opts, callSid); } else if (opts.record) { await this.notifyRecordOptions(opts.record); @@ -1452,6 +1486,13 @@ class CallSession extends Emitter { }); break; + case 'dtmf': + this._lccDtmf(data, call_sid) + .catch((err) => { + this.logger.info({err, data}, `CallSession:_onCommand - error sending RFC 2833 DTMF ${data}`); + }); + break; + default: this.logger.info(`CallSession:_onCommand - invalid command ${command}`); }