mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 17:17:58 +00:00
first implementation of nextTurn and gather task cognigy
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const Emitter = require('events');
|
||||
|
||||
const lodash = require('lodash');
|
||||
const hasKeys = (obj) => typeof obj === 'object' && Object.keys(obj) > 0;
|
||||
|
||||
const stripNulls = (obj) => {
|
||||
@@ -13,19 +13,33 @@ class SpeechConfig extends Emitter {
|
||||
this.logger = logger;
|
||||
this.ep = ep;
|
||||
this.sessionConfig = opts.session || {};
|
||||
this.turnConfig = opts.nextTurn || {};
|
||||
this.update(opts);
|
||||
}
|
||||
|
||||
update(opts = {}) {
|
||||
const {session, nextTurn = {}} = opts;
|
||||
if (session) this.sessionConfig = {...this.sessionConfig, ...session};
|
||||
this.turnConfig = nextTurn;
|
||||
this.logger.debug({opts, sessionLevel: this.sessionConfig, turnLevel: this.turnConfig}, 'SpeechConfig updated');
|
||||
// TODO validation of session params?
|
||||
const {session } = opts;
|
||||
if (session) {
|
||||
this.sessionConfig = lodash.merge(
|
||||
{},
|
||||
this.sessionConfig,
|
||||
session
|
||||
);
|
||||
}
|
||||
//this.turnConfig = nextTurn;
|
||||
this.logger.debug({opts, sessionLevel: this.sessionConfig}, 'SpeechConfig updated');
|
||||
}
|
||||
|
||||
makeGatherTaskConfig({textPrompt, urlPrompt} = {}) {
|
||||
const opts = JSON.parse(JSON.stringify(this.sessionConfig || {}));
|
||||
makeGatherTaskConfig({textPrompt, urlPrompt, turnConfig} = {}) {
|
||||
// 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);
|
||||
@@ -33,10 +47,12 @@ class SpeechConfig extends Emitter {
|
||||
for (const key of newKeys) opts[key] = this.turnConfig[key];
|
||||
for (const key of bothKeys) opts[key] = {...opts[key], ...this.turnConfig[key]};
|
||||
|
||||
*/
|
||||
|
||||
this.logger.debug({
|
||||
opts,
|
||||
sessionConfig: this.sessionConfig,
|
||||
turnConfig: this.turnConfig,
|
||||
turnConfig
|
||||
}, 'Congigy SpeechConfig:_makeGatherTask current options');
|
||||
|
||||
/* input type: speech and/or dtmf entry */
|
||||
@@ -62,6 +78,7 @@ class SpeechConfig extends Emitter {
|
||||
};
|
||||
}
|
||||
|
||||
// todo what is the logic here if we put both? play over say or say over play?
|
||||
if (urlPrompt) {
|
||||
playConfig = {
|
||||
url: urlPrompt
|
||||
@@ -89,9 +106,6 @@ class SpeechConfig extends Emitter {
|
||||
|
||||
const final = stripNulls(config);
|
||||
|
||||
/* turn config can now be emptied for next turn of conversation */
|
||||
this.turnConfig = {};
|
||||
|
||||
const finalConfig = final;
|
||||
if (sayConfig) {
|
||||
finalConfig.say = sayConfig;
|
||||
|
||||
Reference in New Issue
Block a user