mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
dialogflow: finish playing a final prompt before replacing application
This commit is contained in:
@@ -87,7 +87,7 @@ class Dialogflow extends Task {
|
||||
this.ep.removeCustomEventListener('dialogflow::end_of_utterance');
|
||||
this.ep.removeCustomEventListener('dialogflow::error');
|
||||
|
||||
this.performAction({dialogflowResult: 'caller hungup'})
|
||||
if (!this.reportedFinalAction) this.performAction({dialogflowResult: 'caller hungup'})
|
||||
.catch((err) => this.logger.error({err}, 'dialogflow - error w/ action webook'));
|
||||
|
||||
await this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||
@@ -152,6 +152,7 @@ class Dialogflow extends Task {
|
||||
}
|
||||
else {
|
||||
this.logger.info('got empty intent');
|
||||
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -211,10 +212,15 @@ class Dialogflow extends Task {
|
||||
this.logger.debug({obj}, 'Dialogflow:_onIntent - playing message via tts');
|
||||
const fp = await synthAudio(obj);
|
||||
if (fp) cs.trackTmpFile(fp);
|
||||
|
||||
if (this.playInProgress) {
|
||||
await ep.api('uuid_break', ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||
}
|
||||
this.playInProgress = true;
|
||||
this.curentAudioFile = fp;
|
||||
|
||||
this.logger.debug(`starting to play tts ${fp}`);
|
||||
|
||||
if (this.events.includes('start-play')) {
|
||||
this._performHook(cs, this.eventHook, {event: 'start-play', data: {path: fp}});
|
||||
}
|
||||
@@ -226,6 +232,11 @@ class Dialogflow extends Task {
|
||||
|
||||
if (this.curentAudioFile === fp) {
|
||||
this.playInProgress = false;
|
||||
if (this.queuedTasks) {
|
||||
this.logger.debug('finished playing audio and we have queued tasks');
|
||||
this._redirect(cs, this.queuedTasks);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.greetingPlayed = true;
|
||||
|
||||
@@ -320,10 +331,16 @@ class Dialogflow extends Task {
|
||||
if (this.events.includes('stop-play')) {
|
||||
this._performHook(cs, this.eventHook, {event: 'stop-play', data: {path: evt.path}});
|
||||
}
|
||||
this.logger.info(`finished ${evt.path}`);
|
||||
this.logger.info(`finished ${evt.path}, queued tasks: ${this.queuedTasks.length}`);
|
||||
|
||||
if (this.curentAudioFile === evt.path) {
|
||||
this.playInProgress = false;
|
||||
if (this.queuedTasks) {
|
||||
this.logger.debug('finished playing audio and we have queued tasks');
|
||||
this._redirect(cs, this.queuedTasks);
|
||||
this.queuedTasks.length = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (!this.inbound && !this.greetingPlayed) {
|
||||
@@ -413,13 +430,24 @@ class Dialogflow extends Task {
|
||||
const makeTask = require('../make_task');
|
||||
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
||||
if (tasks && tasks.length > 0) {
|
||||
this.logger.info({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
|
||||
this.performAction({dialogflowResult: 'redirect'}, false);
|
||||
cs.replaceApplication(tasks);
|
||||
if (this.playInProgress) {
|
||||
this.queuedTasks = tasks;
|
||||
this.logger.info({tasks: tasks},
|
||||
`${this.name} replacing application with ${tasks.length} tasks after play completes`);
|
||||
return;
|
||||
}
|
||||
this._redirect(cs, tasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_redirect(cs, tasks) {
|
||||
this.logger.info({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
|
||||
this.performAction({dialogflowResult: 'redirect'}, false);
|
||||
this.reportedFinalAction = true;
|
||||
cs.replaceApplication(tasks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Dialogflow;
|
||||
|
||||
Reference in New Issue
Block a user