rasa: add support for eventhook which provides user and bot messages in realtime and supports redirecting to a new app

This commit is contained in:
Dave Horton
2021-09-02 10:27:59 -04:00
committed by Dave Horton
parent 19f3cbaa43
commit d15fdcf663
3 changed files with 72 additions and 8 deletions

View File

@@ -99,6 +99,25 @@ class Task extends Emitter {
}
}
async performHook(cs, hook, results) {
const json = await cs.requestor.request(hook, results);
if (json && Array.isArray(json)) {
const makeTask = require('./make_task');
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
if (tasks && tasks.length > 0) {
this.redirect(cs, tasks);
return true;
}
}
return false;
}
redirect(cs, tasks) {
this.logger.info({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
this.isReplacingApplication = true;
cs.replaceApplication(tasks);
}
async transferCallToFeatureServer(cs, sipAddress, opts) {
const uuid = uuidv4();
const {addKey} = cs.srf.locals.dbHelpers;