add tag task and varioius cleanup

This commit is contained in:
Dave Horton
2020-01-29 15:27:20 -05:00
parent bed4fa1f42
commit 92acd50595
17 changed files with 278 additions and 111 deletions

View File

@@ -145,7 +145,7 @@ class TaskDial extends Task {
this.target.forEach((t) => {
try {
t.url = t.url || this.confirmUrl;
t.method = t.method || this.confirmMethod;
t.method = t.method || this.confirmMethod || 'POST';
const sd = placeCall({
logger: this.logger,
application: cs.application,

View File

@@ -62,7 +62,7 @@ class TaskGather extends Task {
this._startTranscribing(ep);
}
if (this.input.includes('dtmf')) {
if (this.input.includes('digits')) {
ep.on('dtmf', this._onDtmf.bind(this, ep));
}
@@ -129,8 +129,14 @@ class TaskGather extends Task {
}
_killAudio() {
if (this.sayTask && !this.sayTask.killed) this.sayTask.kill();
if (this.playTask && !this.playTask.killed) this.playTask.kill();
if (this.sayTask && !this.sayTask.killed) {
this.sayTask.removeAllListeners('playDone');
this.sayTask.kill();
}
if (this.playTask && !this.playTask.killed) {
this.playTask.removeAllListeners('playDone');
this.playTask.kill();
}
}
_onTranscription(ep, evt) {

View File

@@ -42,6 +42,9 @@ function makeTask(logger, obj) {
case TaskName.Redirect:
const TaskRedirect = require('./redirect');
return new TaskRedirect(logger, data);
case TaskName.Tag:
const TaskTag = require('./tag');
return new TaskTag(logger, data);
}
// should never reach

View File

@@ -10,6 +10,7 @@ class TaskRedirect extends Task {
this.action = this.data.action;
this.method = this.data.method || 'POST';
this.auth = this.data.auth;
}
get name() { return TaskName.Redirect; }

View File

@@ -115,6 +115,14 @@
"action"
]
},
"tag": {
"properties": {
"data": "object"
},
"required": [
"data"
]
},
"transcribe": {
"properties": {
"transcriptionCallback": "string",

19
lib/tasks/tag.js Normal file
View File

@@ -0,0 +1,19 @@
const Task = require('./task');
const {TaskName} = require('../utils/constants');
class TaskTag extends Task {
constructor(logger, opts) {
super(logger, opts);
this.data = this.data.data;
}
get name() { return TaskName.Tag; }
async exec(cs) {
super.exec(cs);
cs.callInfo.customerData = this.data;
this.logger.debug({customerData: cs.callInfo.customerData}, 'TaskTag:exec set customer data');
}
}
module.exports = TaskTag;

View File

@@ -58,7 +58,14 @@ class Task extends Emitter {
async performAction(method, auth, results) {
if (this.action) {
const tasks = await this.actionHook(this.action, method, auth, results);
let action = this.action;
if (action.startsWith('/')) {
const or = this.callSession.originalRequest;
action = `${or.baseUrl}${this.action}`;
this.logger.debug({originalUrl: this.action, normalizedUrl: action}, 'Task:performAction normalized url');
if (!auth && or.auth) auth = or.auth;
}
const tasks = await this.actionHook(action, method, auth, results);
if (tasks && Array.isArray(tasks)) {
this.logger.debug({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
this.callSession.replaceApplication(tasks);