From 2f8efb80d02d593a554339b1addf9cf600db08cf Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 19 Jan 2023 09:29:17 -0500 Subject: [PATCH] bugfix #220 (config w/ bargein enable followed later in flow w bargein disable) --- lib/middleware.js | 4 +++- lib/session/call-session.js | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 738e860a..fae43e09 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -245,7 +245,9 @@ module.exports = function(srf, logger) { // eslint-disable-next-line no-unused-vars const {call_hook, call_status_hook, ...appInfo} = app; // mask sensitive data like user/pass on webhook - logger.info({app: appInfo}, `retrieved application for incoming call to ${req.locals.calledNumber}`); + // eslint-disable-next-line no-unused-vars + const {requestor, notifier, ...loggable} = appInfo; + logger.info({app: loggable}, `retrieved application for incoming call to ${req.locals.calledNumber}`); req.locals.callInfo = new CallInfo({ req, app: app2, diff --git a/lib/session/call-session.js b/lib/session/call-session.js index f86bf3e7..e2fdd5b0 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -471,10 +471,10 @@ class CallSession extends Emitter { this.backgroundGatherTask = makeTask(this.logger, t[0]); this._bargeInEnabled = true; this.backgroundGatherTask - .once('dtmf', this._clearTasks.bind(this)) - .once('vad', this._clearTasks.bind(this)) - .once('transcription', this._clearTasks.bind(this)) - .once('timeout', this._clearTasks.bind(this)); + .once('dtmf', this._clearTasks.bind(this, this.backgroundGatherTask)) + .once('vad', this._clearTasks.bind(this, this.backgroundGatherTask)) + .once('transcription', this._clearTasks.bind(this, this.backgroundGatherTask)) + .once('timeout', this._clearTasks.bind(this, this.backgroundGatherTask)); this.logger.info({gather}, 'CallSession:enableBotMode - starting background gather'); const resources = await this._evaluatePreconditions(this.backgroundGatherTask); const {span, ctx} = this.rootSpan.startChildSpan(`background-gather:${this.backgroundGatherTask.summary}`); @@ -1037,14 +1037,32 @@ class CallSession extends Emitter { } } - kill() { + kill(onBackgroundGatherBargein = false) { if (this.isConfirmCallSession) this.logger.debug('CallSession:kill (ConfirmSession)'); else this.logger.info('CallSession:kill'); if (this.currentTask) { this.currentTask.kill(this); this.currentTask = null; } - this.tasks = []; + if (onBackgroundGatherBargein) { + /* search for a config with bargein disabled */ + while (this.tasks.length) { + const t = this.tasks[0]; + if (t.name === TaskName.Config && t.bargeIn?.enable === false) { + /* found it, clear to that point and remove the disable + because we likely already received a partial transcription + and we don't want to kill the background gather before we + get the full transcription. + */ + delete t.bargeIn.enable; + this._bargeInEnabled = false; + this.logger.info('CallSession:kill - found bargein disabled in the stack, clearing to that point'); + break; + } + this.tasks.shift(); + } + } + else this.tasks = []; this.taskIdx = 0; } @@ -1664,11 +1682,12 @@ class CallSession extends Emitter { }); } - _clearTasks(evt) { - if (this.requestor instanceof WsRequestor) { + _clearTasks(backgroundGather, evt) { + if (this.requestor instanceof WsRequestor && !backgroundGather.cleared) { this.logger.info({evt}, 'CallSession:_clearTasks on event from background gather'); try { - this.kill(); + backgroundGather.cleared = true; + this.kill(true); } catch (err) {} } }