mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
add tag task and varioius cleanup
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -115,6 +115,14 @@
|
||||
"action"
|
||||
]
|
||||
},
|
||||
"tag": {
|
||||
"properties": {
|
||||
"data": "object"
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
]
|
||||
},
|
||||
"transcribe": {
|
||||
"properties": {
|
||||
"transcriptionCallback": "string",
|
||||
|
||||
19
lib/tasks/tag.js
Normal file
19
lib/tasks/tag.js
Normal 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;
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user