mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-19 04:17:44 +00:00
limit simring outdials to 10 and eliminate any duplicates
This commit is contained in:
@@ -1,12 +1,45 @@
|
||||
const Task = require('./task');
|
||||
const makeTask = require('./make_task');
|
||||
const {CallStatus, CallDirection, TaskName, TaskPreconditions} = require('../utils/constants');
|
||||
const {CallStatus, CallDirection, TaskName, TaskPreconditions, MAX_SIMRINGS} = require('../utils/constants');
|
||||
const assert = require('assert');
|
||||
const placeCall = require('../utils/place-outdial');
|
||||
const config = require('config');
|
||||
const moment = require('moment');
|
||||
const debug = require('debug')('jambonz:feature-server');
|
||||
|
||||
function compareTasks(t1, t2) {
|
||||
if (t1.type !== t2.type) return false;
|
||||
switch (t1.type) {
|
||||
case 'phone':
|
||||
return t1.number === t1.number;
|
||||
case 'user':
|
||||
return t2.name === t1.name;
|
||||
case 'sip':
|
||||
return t2.uri === t1.uri;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow at most 10 targets and eliminate duplicates
|
||||
*/
|
||||
function filterAndLimit(logger, tasks) {
|
||||
assert(Array.isArray(tasks));
|
||||
const unique = tasks.reduce((acc, t) => {
|
||||
if (acc.find((el) => compareTasks(el, t))) return acc;
|
||||
return [...acc, t];
|
||||
}, []);
|
||||
|
||||
if (unique.length !== tasks.length) {
|
||||
logger.info(`filterAndLimit: removed ${tasks.length - unique.length} duplicate dial targets`);
|
||||
}
|
||||
|
||||
if (unique.length > MAX_SIMRINGS) {
|
||||
logger.info(`filterAndLimit: max number of targets exceeded: ${unique.length}; first ${MAX_SIMRINGS} will be used`);
|
||||
unique.length = MAX_SIMRINGS;
|
||||
}
|
||||
return unique;
|
||||
}
|
||||
|
||||
class TaskDial extends Task {
|
||||
constructor(logger, opts) {
|
||||
super(logger, opts);
|
||||
@@ -19,7 +52,7 @@ class TaskDial extends Task {
|
||||
this.method = this.data.method || 'POST';
|
||||
this.statusCallback = this.data.statusCallback;
|
||||
this.statusCallbackMethod = this.data.statusCallbackMethod || 'POST';
|
||||
this.target = this.data.target;
|
||||
this.target = filterAndLimit(this.logger, this.data.target);
|
||||
this.timeout = this.data.timeout || 60;
|
||||
this.timeLimit = this.data.timeLimit;
|
||||
this.url = this.data.url;
|
||||
@@ -46,7 +79,7 @@ class TaskDial extends Task {
|
||||
}
|
||||
await this._attemptCalls(cs);
|
||||
await this.awaitTaskDone();
|
||||
this.performAction(this.method, this.results);
|
||||
this.performAction(this.method, null, this.results);
|
||||
} catch (err) {
|
||||
this.logger.error(`TaskDial:exec terminating with error ${err.message}`);
|
||||
this.kill();
|
||||
|
||||
@@ -50,5 +50,6 @@
|
||||
"Error": "mod_audio_fork::error",
|
||||
"BufferOverrun": "mod_audio_fork::buffer_overrun",
|
||||
"JsonMessage": "mod_audio_fork::json"
|
||||
}
|
||||
},
|
||||
"MAX_SIMRINGS": 10
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user