initial support for Rasa

This commit is contained in:
Dave Horton
2021-09-01 21:06:32 -04:00
parent 47073955e0
commit 98f53138d1
6 changed files with 134 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ const makeTask = require('./make_task');
const assert = require('assert');
class TaskGather extends Task {
constructor(logger, opts) {
constructor(logger, opts, parentTask) {
super(logger, opts);
this.preconditions = TaskPreconditions.Endpoint;
@@ -40,6 +40,8 @@ class TaskGather extends Task {
if (this.say) this.sayTask = makeTask(this.logger, {say: this.say}, this);
if (this.play) this.playTask = makeTask(this.logger, {play: this.play}, this);
this.parentTask = parentTask;
}
get name() { return TaskName.Gather; }
@@ -154,7 +156,6 @@ class TaskGather extends Task {
});
ep.addCustomEventListener(AwsTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
}
this.logger.debug({vars: opts}, 'setting freeswitch vars');
await ep.set(opts)
.catch((err) => this.logger.info(err, 'Error setting channel variables'));
@@ -235,7 +236,11 @@ class TaskGather extends Task {
await this.performAction({digits: this.digitBuffer});
}
else if (reason.startsWith('speech')) {
await this.performAction({speech: evt});
if (this.parentTask) this.parentTask.emit('transcription', evt);
else await this.performAction({speech: evt});
}
else if (reason.startsWith('timeout') && this.parentTask) {
this.parentTask.emit('timeout', evt);
}
this.notifyTaskDone();
}