diff --git a/lib/tasks/cognigy/index.js b/lib/tasks/cognigy/index.js index 0ddaf20d..c4d3aabc 100644 --- a/lib/tasks/cognigy/index.js +++ b/lib/tasks/cognigy/index.js @@ -263,16 +263,16 @@ class Cognigy extends Task { try { // lets wait until we have finished processing the speech before // starting a gather... - this.logger.debug("enqueued bot final ping gather"); + this.logger.debug('enqueued bot final ping gather'); this._enqueueTask(async() => { - this.logger.debug("executing bot final ping gather"); - try { + this.logger.debug('executing bot final ping gather'); + try { const gatherTask = this._makeGatherTask(); await gatherTask.exec(cs, ep, this); } catch (err) { this.logger.info({err}, 'Cognigy final ping gather task returned error'); } - this.logger.debug("executed bot final ping gather"); + this.logger.debug('executed bot final ping gather'); }); } catch (err) { diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 2faad08f..39e22547 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -25,7 +25,8 @@ class TaskGather extends Task { this.minBargeinWordCount = this.data.minBargeinWordCount || 1; // this is specially for barge in where we want to make a bargebale promt // to a user without listening after the say task has finished - this.timeout = this.data.listenAfterSpeech === false ? 1 : (this.timeout || 15) * 1000; + this.listenAfterSpeech = this.data.listenAfterSpeech === false; + this.timeout = (this.timeout || 15) * 1000; this.interim = this.partialResultCallback || this.bargein; if (this.data.recognizer) { const recognizer = this.data.recognizer; @@ -99,15 +100,21 @@ class TaskGather extends Task { try { if (this.sayTask) { this.logger.debug('Gather: kicking off say task'); - this.sayTask.exec(cs, ep); // kicked off, _not_ waiting for it to complete + this.sayTask.exec(cs, ep).then(() => { + this.logger.debug('Gather: completed say task promise'); + if (!this.killed) { + if (this.listenAfterSpeech) { + startListening(cs, ep); + } else { + this.kill(cs); + } + } + return; + }).catch(err => this.logger.error({err}, 'Gather: failed to play say task')); // kicked off, _not_ waiting for it to complete this.sayTask.on('playDone', async(err) => { if (err) return this.logger.error({err}, 'Gather:exec Error playing tts'); this.logger.debug('Gather: say task completed'); - if (!this.killed) { - - startListening(cs, ep); - } }); } else if (this.playTask) {