mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 17:17:58 +00:00
drop queue speech on barge in
This commit is contained in:
@@ -73,6 +73,7 @@ class Cognigy extends Task {
|
||||
resolver = resolve;
|
||||
rejector = reject;
|
||||
});
|
||||
taskPromise.resolve = resolver;
|
||||
this.taskQueue.push(async(cb) => {
|
||||
this.logger.debug('executing task from queue');
|
||||
try {
|
||||
@@ -86,6 +87,10 @@ class Cognigy extends Task {
|
||||
}
|
||||
this.logger.debug('say task executed from queue');
|
||||
});
|
||||
if(this.taskQueue.lastPromise){
|
||||
// resolve the previous promise for cleanup
|
||||
this.taskQueue.lastPromise.resolve({});
|
||||
}
|
||||
this.taskQueue.lastPromise = taskPromise;
|
||||
return taskPromise;
|
||||
}
|
||||
@@ -180,6 +185,19 @@ class Cognigy extends Task {
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a promt which will be sent to the consumer. We will create a say task if bargein is disabled
|
||||
* for session and nextTurn, else create a gather task.
|
||||
*/
|
||||
_createPromtTask({text, url, turnConfig, dontListenAfterSpeech} = {}){
|
||||
const bargeInOnNextTurn = turnConfig?.bargein?.enable?.length>0;
|
||||
const bargeInSession = this.config.bargeInEnabled;
|
||||
if(bargeInOnNextTurn || bargeInSession){
|
||||
return this._makeGatherTask({textPrompt: text, url: urlPrompt, turnConfig, dontListenAfterSpeech});
|
||||
}
|
||||
return this._makeSayTask({text, turnConfig});
|
||||
}
|
||||
|
||||
_makeGatherTask({textPrompt, urlPrompt, turnConfig} = {}) {
|
||||
this.logger.debug({textPrompt, urlPrompt, turnConfig}, '_makeGatherTask');
|
||||
const config = this.config.makeGatherTaskConfig({textPrompt, urlPrompt, turnConfig});
|
||||
@@ -274,11 +292,11 @@ class Cognigy extends Task {
|
||||
const text = parseBotText(evt);
|
||||
|
||||
// only add say task if its a normal cognigy node and not a "gather task"
|
||||
if (text && (evt?.data?.type !== 'gather')) {
|
||||
if (text && (evt?.data?.type !== 'promt')) {
|
||||
this.logger.info({text}, 'received text');
|
||||
this._enqueueTask(async() => {
|
||||
// todo inject the session config into the say task
|
||||
const sayTask = this._makeSayTask({text});
|
||||
const sayTask = this._createPromtTask({ text, dontListenAfterSpeech: true });
|
||||
await sayTask.exec(cs, ep, this);
|
||||
this.logger.debug({text}, 'executed say task');
|
||||
});
|
||||
@@ -304,9 +322,9 @@ class Cognigy extends Task {
|
||||
return;
|
||||
case 'promt':
|
||||
this._enqueueTask(async() => {
|
||||
const sayTask = this._makeSayTask({
|
||||
const sayTask = this._createPromtTask({
|
||||
text: evt.data.text,
|
||||
nextTurn: evt?.data?.config?.nextTurn
|
||||
turnConfig: evt?.data?.config?.nextTurn
|
||||
});
|
||||
try {
|
||||
await sayTask.exec(cs, ep, this);
|
||||
@@ -337,6 +355,17 @@ class Cognigy extends Task {
|
||||
this.logger.debug({evt}, `Cognigy: got transcription for callSid ${cs.callSid}`);
|
||||
const utterance = evt.alternatives[0].transcript;
|
||||
|
||||
//if we have barge in enabled AND we enabled skipping until next question
|
||||
//then stop execution of currently queues bot output before sending the
|
||||
//response to waiting bot since otherwise we could stop upcoming bot output
|
||||
|
||||
if(this.config.skipUntilBotInput){
|
||||
// clear task queue, resolve the last promise and cleanup;
|
||||
this.taskQueue.end();
|
||||
this.taskQueue.lastPromise.resolve();
|
||||
this.taskQueue.autostart = true;
|
||||
}
|
||||
|
||||
if (this.eventHook) {
|
||||
this.performHook(cs, this.eventHook, {event: 'userMessage', message: utterance})
|
||||
.then((redirected) => {
|
||||
@@ -376,7 +405,7 @@ class Cognigy extends Task {
|
||||
/* send dtmf to bot */
|
||||
try {
|
||||
if (this.client && this.client.connected) {
|
||||
this.client.sendMessage(evt.digits);
|
||||
this.client.sendMessage(String(evt.digits));
|
||||
}
|
||||
else {
|
||||
// if the bot is not connected, should we maybe throw an error here?
|
||||
|
||||
Reference in New Issue
Block a user