From 9657017669fb2454fe2ca60e0dfd992d19fc2076 Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Tue, 1 Feb 2022 18:22:06 +0100 Subject: [PATCH] improve log messages --- lib/tasks/cognigy/index.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/tasks/cognigy/index.js b/lib/tasks/cognigy/index.js index 28a6e470..90574049 100644 --- a/lib/tasks/cognigy/index.js +++ b/lib/tasks/cognigy/index.js @@ -63,14 +63,16 @@ class Cognigy extends Task { async _enqueueTask(task) { let resolver; let rejector; + + const boundTask = task.bind(this); const taskPromise = new Promise(async(resolve, reject) => { resolver = resolve; rejector = reject; }); this.taskQueue.push(async(cb) => { - this.logger.info('EXECUTING SAY TASK'); + this.logger.debug('executing say task from queue'); try { - const result = await task(); + const result = await boundTask(); resolver(result); cb(result); } catch (err) { @@ -78,7 +80,7 @@ class Cognigy extends Task { rejector(err); cb(err); } - this.logger.info('SAY TASK EXECUTED'); + this.logger.debug('say task executed from queue'); }); this.taskQueue.lastPromise = taskPromise; return taskPromise; @@ -256,11 +258,11 @@ class Cognigy extends Task { const text = parseBotText(evt); if (evt.data) this.config.update(evt.data); if (text) { - this._enqueueTask((async() => { + this._enqueueTask(async() => { this.logger.info({text}, 'received text'); const sayTask = this._makeSayTask(text); await sayTask.exec(cs, ep, this); - }).bind(this)); + }); } @@ -268,7 +270,7 @@ class Cognigy extends Task { try { switch (evt.data.type) { case 'hangup': - this._enqueueTask((async() => { + this._enqueueTask(async() => { this.performAction({cognigyResult: 'hangup Succeeded'}); this.reportedFinalAction = true; cs.replaceApplication([{hangup: { @@ -277,18 +279,18 @@ class Cognigy extends Task { } }}]); this.taskQueue.end(); - }).bind(this)); + }); return; case 'refer': - this._enqueueTask((async() => { + this._enqueueTask(async() => { this.performAction({cognigyResult: 'refer succeeded'}); this.reportedFinalAction = true; cs.replaceApplication([{'sip:refer': { referTo: evt.data.number, referredBy: 'cognigy' }}]); - }).bind(this)); + }); return; default: break;