diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 7b978748..d2880fe8 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -410,6 +410,7 @@ class CallSession extends Emitter { try { const t = normalizeJambones(this.logger, [gather]); this.backgroundGatherTask = makeTask(this.logger, t[0]); + this._bargeInEnabled = true; this.backgroundGatherTask .once('dtmf', this._clearTasks.bind(this)) .once('vad', this._clearTasks.bind(this)) @@ -426,7 +427,7 @@ class CallSession extends Emitter { this.backgroundGatherTask && this.backgroundGatherTask.removeAllListeners(); this.backgroundGatherTask && this.backgroundGatherTask.span.end(); this.backgroundGatherTask = null; - if (autoEnable && !this.callGone && !this._stopping) { + if (autoEnable && !this.callGone && !this._stopping && this._bargeInEnabled) { this.logger.info('CallSession:enableBotMode: restarting background gather'); setImmediate(() => this.enableBotMode(gather, true)); } @@ -443,6 +444,7 @@ class CallSession extends Emitter { } } disableBotMode() { + this._bargeInEnabled = false; if (this.backgroundGatherTask) { try { this.backgroundGatherTask.removeAllListeners(); diff --git a/lib/tasks/config.js b/lib/tasks/config.js index 39540cf8..ea4964dc 100644 --- a/lib/tasks/config.js +++ b/lib/tasks/config.js @@ -93,7 +93,7 @@ class TaskConfig extends Task { }, 'Config: updated recognizer'); } if ('enable' in this.bargeIn) { - if (this.gatherOpts) { + if (this.bargeIn.enable === true && this.gatherOpts) { this.gatherOpts.recognizer = this.hasRecognizer ? this.recognizer : { @@ -103,7 +103,7 @@ class TaskConfig extends Task { this.logger.info({opts: this.gatherOpts}, 'Config: enabling bargeIn'); cs.enableBotMode(this.gatherOpts, this.autoEnable); } - else { + else if (this.bargeIn.enable === false) { this.logger.info('Config: disabling bargeIn'); cs.disableBotMode(); }