mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 17:17:58 +00:00
make barge in disableable
This commit is contained in:
@@ -189,18 +189,18 @@ class Cognigy extends Task {
|
||||
* 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} = {}) {
|
||||
_createPromtTask({text, url, turnConfig, listenAfterSpeech} = {}) {
|
||||
const bargeInOnNextTurn = turnConfig?.bargein?.enable?.length > 0;
|
||||
const bargeInSession = this.config.bargeInEnabled;
|
||||
if (bargeInOnNextTurn || bargeInSession) {
|
||||
return this._makeGatherTask({textPrompt: text, url, turnConfig, dontListenAfterSpeech});
|
||||
return this._makeGatherTask({textPrompt: text, url, turnConfig, listenAfterSpeech});
|
||||
}
|
||||
return this._makeSayTask({text, turnConfig});
|
||||
}
|
||||
|
||||
_makeGatherTask({textPrompt, urlPrompt, turnConfig} = {}) {
|
||||
_makeGatherTask({textPrompt, urlPrompt, turnConfig, listenAfterSpeech} = {}) {
|
||||
this.logger.debug({textPrompt, urlPrompt, turnConfig}, '_makeGatherTask');
|
||||
const config = this.config.makeGatherTaskConfig({textPrompt, urlPrompt, turnConfig});
|
||||
const config = this.config.makeGatherTaskConfig({textPrompt, urlPrompt, turnConfig, listenAfterSpeech});
|
||||
const {retry, ...rest} = config;
|
||||
this.retry = retry;
|
||||
const gather = makeTask(this.logger, {gather: rest}, this);
|
||||
@@ -305,7 +305,7 @@ class Cognigy extends Task {
|
||||
this.logger.info({text}, 'received text');
|
||||
this._enqueueTask(async() => {
|
||||
// todo inject the session config into the say task
|
||||
const promtTask = this._createPromtTask({ text, dontListenAfterSpeech: true });
|
||||
const promtTask = this._createPromtTask({ text, listenAfterSpeech: false });
|
||||
await promtTask.exec(cs, ep, this);
|
||||
this.logger.debug({text}, 'executed say task');
|
||||
});
|
||||
@@ -369,7 +369,7 @@ class Cognigy extends Task {
|
||||
//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.bargeInEnabled && this.config.skipUntilBotInput) {
|
||||
if (this.config.bargeInEnabled && this.config.skipToBotOutputEnd !== false) {
|
||||
// clear task queue, resolve the last promise and cleanup;
|
||||
this.taskQueue.lastPromise.resolve();
|
||||
this.taskQueue.end();
|
||||
|
||||
@@ -16,14 +16,23 @@ class SpeechConfig extends Emitter {
|
||||
this.update(opts);
|
||||
}
|
||||
|
||||
update(session) {
|
||||
// TODO validation of session params?
|
||||
if (session) {
|
||||
this.sessionConfig = lodash.merge(
|
||||
_mergeConfig(changedConfig = {}){
|
||||
const merged = lodash.merge(
|
||||
{},
|
||||
this.sessionConfig,
|
||||
session
|
||||
);
|
||||
merged.bargein.enable = changedConfig.bargein?.enable?.length === 0 ? [] : changedConfig.bargein?.enable;
|
||||
|
||||
// should we override hints with empty array or leave it as it is once saved?
|
||||
// merged.recognizer.hints = changedConfig.recognizer?.hints
|
||||
|
||||
}
|
||||
|
||||
update(session) {
|
||||
// TODO validation of session params?
|
||||
if (session) {
|
||||
this.sessionConfig = this._mergeConfig(session);
|
||||
}
|
||||
this.logger.debug({sessionLevel: this.sessionConfig}, 'SpeechConfig updated');
|
||||
}
|
||||
@@ -49,24 +58,10 @@ class SpeechConfig extends Emitter {
|
||||
};
|
||||
}
|
||||
|
||||
makeGatherTaskConfig({textPrompt, urlPrompt, turnConfig = {}, dontListenAfterSpeech} = {}) {
|
||||
makeGatherTaskConfig({textPrompt, urlPrompt, turnConfig = {}, listenAfterSpeech} = {}) {
|
||||
// we merge from top to bottom deeply so we wil have
|
||||
// defaults from session config and then will override them via turn config
|
||||
const opts = lodash.merge(
|
||||
{},
|
||||
this.sessionConfig || {}, // this should not be undefined ever
|
||||
turnConfig
|
||||
);
|
||||
|
||||
/*
|
||||
const nextTurnKeys = Object.keys(this.turnConfig || {});
|
||||
const newKeys = nextTurnKeys.filter((k) => !(k in opts));
|
||||
const bothKeys = nextTurnKeys.filter((k) => k in opts);
|
||||
|
||||
for (const key of newKeys) opts[key] = this.turnConfig[key];
|
||||
for (const key of bothKeys) opts[key] = {...opts[key], ...this.turnConfig[key]};
|
||||
|
||||
*/
|
||||
const opts = this._mergeConfig(turnConfig);
|
||||
|
||||
this.logger.debug({
|
||||
opts,
|
||||
@@ -126,7 +121,7 @@ class SpeechConfig extends Emitter {
|
||||
noInputSpeech,
|
||||
noInputUrl
|
||||
},
|
||||
listenAfterSpeech: !dontListenAfterSpeech
|
||||
listenAfterSpeech
|
||||
};
|
||||
|
||||
const final = stripNulls(config);
|
||||
|
||||
Reference in New Issue
Block a user