mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +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::end_of_utterance');
|
||||||
this.ep.removeCustomEventListener('dialogflow::error');
|
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'));
|
.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'));
|
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 {
|
else {
|
||||||
this.logger.info('got empty intent');
|
this.logger.info('got empty intent');
|
||||||
|
ep.api('dialogflow_start', `${ep.uuid} ${this.project} ${this.lang}`);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -211,10 +212,15 @@ class Dialogflow extends Task {
|
|||||||
this.logger.debug({obj}, 'Dialogflow:_onIntent - playing message via tts');
|
this.logger.debug({obj}, 'Dialogflow:_onIntent - playing message via tts');
|
||||||
const fp = await synthAudio(obj);
|
const fp = await synthAudio(obj);
|
||||||
if (fp) cs.trackTmpFile(fp);
|
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.playInProgress = true;
|
||||||
this.curentAudioFile = fp;
|
this.curentAudioFile = fp;
|
||||||
|
|
||||||
this.logger.debug(`starting to play tts ${fp}`);
|
this.logger.debug(`starting to play tts ${fp}`);
|
||||||
|
|
||||||
if (this.events.includes('start-play')) {
|
if (this.events.includes('start-play')) {
|
||||||
this._performHook(cs, this.eventHook, {event: 'start-play', data: {path: fp}});
|
this._performHook(cs, this.eventHook, {event: 'start-play', data: {path: fp}});
|
||||||
}
|
}
|
||||||
@@ -226,6 +232,11 @@ class Dialogflow extends Task {
|
|||||||
|
|
||||||
if (this.curentAudioFile === fp) {
|
if (this.curentAudioFile === fp) {
|
||||||
this.playInProgress = false;
|
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;
|
this.greetingPlayed = true;
|
||||||
|
|
||||||
@@ -320,10 +331,16 @@ class Dialogflow extends Task {
|
|||||||
if (this.events.includes('stop-play')) {
|
if (this.events.includes('stop-play')) {
|
||||||
this._performHook(cs, this.eventHook, {event: 'stop-play', data: {path: evt.path}});
|
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) {
|
if (this.curentAudioFile === evt.path) {
|
||||||
this.playInProgress = false;
|
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) {
|
if (!this.inbound && !this.greetingPlayed) {
|
||||||
@@ -413,13 +430,24 @@ class Dialogflow extends Task {
|
|||||||
const makeTask = require('../make_task');
|
const makeTask = require('../make_task');
|
||||||
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
||||||
if (tasks && tasks.length > 0) {
|
if (tasks && tasks.length > 0) {
|
||||||
this.logger.info({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
|
if (this.playInProgress) {
|
||||||
this.performAction({dialogflowResult: 'redirect'}, false);
|
this.queuedTasks = tasks;
|
||||||
cs.replaceApplication(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;
|
module.exports = Dialogflow;
|
||||||
|
|||||||
Reference in New Issue
Block a user