improve log messages

This commit is contained in:
akirilyuk
2022-02-01 18:22:06 +01:00
parent b532a49e45
commit 9657017669

View File

@@ -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;