mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 17:17:58 +00:00
add support for retry logic and dtmf
This commit is contained in:
@@ -2,6 +2,11 @@ const Emitter = require('events');
|
||||
|
||||
const hasKeys = (obj) => typeof obj === 'object' && Object.keys(obj) > 0;
|
||||
|
||||
const stripNulls = (obj) => {
|
||||
Object.keys(obj).forEach((k) => (obj[k] === null || typeof obj[k] === 'undefined') && delete obj[k]);
|
||||
return obj;
|
||||
};
|
||||
|
||||
class SpeechConfig extends Emitter {
|
||||
constructor({logger, ep, opts = {}}) {
|
||||
super();
|
||||
@@ -19,7 +24,7 @@ class SpeechConfig extends Emitter {
|
||||
this.logger.debug({opts, sessionLevel: this.sessionConfig, turnLevel: this.turnConfig}, 'SpeechConfig updated');
|
||||
}
|
||||
|
||||
makeGatherTaskConfig(prompt) {
|
||||
makeGatherTaskConfig({textPrompt, urlPrompt}) {
|
||||
const opts = JSON.parse(JSON.stringify(this.sessionConfig || {}));
|
||||
const nextTurnKeys = Object.keys(this.turnConfig || {});
|
||||
const newKeys = nextTurnKeys.filter((k) => !(k in opts));
|
||||
@@ -42,26 +47,43 @@ class SpeechConfig extends Emitter {
|
||||
/* bargein settings */
|
||||
const bargein = opts.bargein || {};
|
||||
const speechBargein = Array.isArray(bargein.enable) && bargein.enable.includes('speech');
|
||||
const dtmfBargein = Array.isArray(bargein.enable) && bargein.enable.includes('dtmf');
|
||||
const minBargeinWordCount = speechBargein ? (bargein.minWordCount || 1) : 0;
|
||||
const {interDigitTimeout=0, maxDigits, minDigits=1, submitDigit} = (opts.dtmf || {});
|
||||
const {noInputTimeout, noInputRetries, noInputSpeech, noInputUrl} = (opts.user || {});
|
||||
const sayConfig = {
|
||||
text: prompt,
|
||||
text: textPrompt,
|
||||
synthesizer: opts.synthesizer
|
||||
};
|
||||
const playConfig = {
|
||||
url: urlPrompt
|
||||
};
|
||||
const config = {
|
||||
input,
|
||||
listenDuringPrompt: speechBargein,
|
||||
bargein: speechBargein,
|
||||
minBargeinWordCount,
|
||||
dtmfBargein,
|
||||
minDigits,
|
||||
maxDigits,
|
||||
interDigitTimeout,
|
||||
finishOnKey: submitDigit,
|
||||
recognizer: opts?.recognizer,
|
||||
timeout: opts?.user?.noInputTimeout || 0,
|
||||
say: sayConfig
|
||||
timeout: noInputTimeout,
|
||||
retry : {
|
||||
noInputRetries,
|
||||
noInputSpeech,
|
||||
noInputUrl
|
||||
}
|
||||
};
|
||||
|
||||
this.logger.debug({config}, 'Congigy SpeechConfig:_makeGatherTask config');
|
||||
const final = stripNulls(config);
|
||||
|
||||
/* turn config can now be emptied for next turn of conversation */
|
||||
this.turnConfig = {};
|
||||
return config;
|
||||
return textPrompt ?
|
||||
{...final, say: sayConfig} :
|
||||
{...final, play: playConfig};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user