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:
@@ -176,8 +176,8 @@ class Cognigy extends Task {
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
|
||||
_makeGatherTask({textPrompt, urlPrompt} = {}) {
|
||||
const config = this.config.makeGatherTaskConfig({textPrompt, urlPrompt});
|
||||
_makeGatherTask({textPrompt, urlPrompt, turnConfig} = {}) {
|
||||
const config = this.config.makeGatherTaskConfig({textPrompt, urlPrompt, turnConfig});
|
||||
const {retry, ...rest} = config;
|
||||
this.retry = retry;
|
||||
const gather = makeTask(this.logger, {gather: rest}, this);
|
||||
@@ -199,19 +199,22 @@ class Cognigy extends Task {
|
||||
}
|
||||
|
||||
_makeReferTask(referTo) {
|
||||
const refer = makeTask(this.logger, {'sip:refer': {
|
||||
return makeTask(this.logger, {'sip:refer': {
|
||||
referTo
|
||||
}});
|
||||
return refer;
|
||||
}}
|
||||
);
|
||||
}
|
||||
|
||||
_makeHangupTask(reason) {
|
||||
const hangup = makeTask(this.logger, {hangup: {
|
||||
return makeTask(this.logger, {hangup: {
|
||||
headers: {
|
||||
'X-Reason': reason
|
||||
}
|
||||
}});
|
||||
return hangup;
|
||||
}
|
||||
|
||||
_makePlayTask(url, loop) {
|
||||
|
||||
}
|
||||
|
||||
/* if we need to interrupt the currently-running say task(s), call this */
|
||||
@@ -235,11 +238,16 @@ class Cognigy extends Task {
|
||||
async _onBotFinalPing(cs, ep) {
|
||||
this.logger.info({prompts: this.prompts}, 'Cognigy:_onBotFinalPing');
|
||||
try {
|
||||
await this.taskQueue.lastPromise;
|
||||
this.gatherTask = this._makeGatherTask();
|
||||
this.gatherTask.exec(cs, ep, this)
|
||||
.catch((err) => this.logger.info({err}, 'Cognigy gather task returned error'));
|
||||
this.prompts = [];
|
||||
if (!this.gatherTaskExists) {
|
||||
await this.taskQueue.lastPromise;
|
||||
this.gatherTask = this._makeGatherTask();
|
||||
this.gatherTask.exec(cs, ep, this)
|
||||
.catch((err) => this.logger.info({err}, 'Cognigy gather task returned error'));
|
||||
this.prompts = [];
|
||||
} else {
|
||||
this.logger.info({}, 'no need to create a gather task, it already exists!');
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'Could not execute bot final ping!');
|
||||
}
|
||||
@@ -264,8 +272,10 @@ class Cognigy extends Task {
|
||||
}
|
||||
|
||||
const text = parseBotText(evt);
|
||||
if (evt.data) this.config.update(evt.data);
|
||||
if (text) {
|
||||
if (evt.data && evt.data.config && evt.data.config.session) this.config.update(evt.data.config.session);
|
||||
|
||||
// only add say task if its a normal cognigy node and not a "gather task"
|
||||
if (text && (!evt.data || !evt.data.type || !evt.data.type !== 'gather')) {
|
||||
this._enqueueTask(async() => {
|
||||
this.logger.info({text}, 'received text');
|
||||
const sayTask = this._makeSayTask(text);
|
||||
@@ -293,6 +303,22 @@ class Cognigy extends Task {
|
||||
cs.replaceApplication([this._makeReferTask(evt.data.referTo)]);
|
||||
});
|
||||
return;
|
||||
case 'gather':
|
||||
this.gatherTaskExists = true;
|
||||
this._enqueueTask(async() => {
|
||||
this.gatherTask = this._makeGatherTask({
|
||||
textPrompt: evt.data.text,
|
||||
urlPrompt: evt.data.url,
|
||||
nextTurnConfig: evt.data.config && evt.data.config.nextTurn
|
||||
});
|
||||
try {
|
||||
this.gatherTask.exec(cs, ep, this);
|
||||
} catch (err) {
|
||||
this.logger.info({err}, 'Cognigy gather task returned error');
|
||||
}
|
||||
this.gatherTaskExists = false;
|
||||
});
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user