mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
rest dial dtmf
This commit is contained in:
@@ -2,10 +2,38 @@ const Task = require('./task');
|
|||||||
const {TaskName} = require('../utils/constants');
|
const {TaskName} = require('../utils/constants');
|
||||||
const makeTask = require('./make_task');
|
const makeTask = require('./make_task');
|
||||||
const { normalizeJambones } = require('@jambonz/verb-specifications');
|
const { normalizeJambones } = require('@jambonz/verb-specifications');
|
||||||
|
const DtmfCollector = require('../utils/dtmf-collector');
|
||||||
/**
|
/**
|
||||||
* Manages an outdial made via REST API
|
* Manages an outdial made via REST API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function parseDtmfOptions(logger, dtmfCapture) {
|
||||||
|
let parentDtmfCollector, childDtmfCollector;
|
||||||
|
const parentKeys = [], childKeys = [];
|
||||||
|
|
||||||
|
if (Array.isArray(dtmfCapture)) {
|
||||||
|
Array.prototype.push.apply(parentKeys, dtmfCapture);
|
||||||
|
Array.prototype.push.apply(childKeys, dtmfCapture);
|
||||||
|
}
|
||||||
|
else if (dtmfCapture.childCall || dtmfCapture.parentCall) {
|
||||||
|
if (dtmfCapture.childCall && Array.isArray(dtmfCapture.childCall)) {
|
||||||
|
Array.prototype.push.apply(childKeys, dtmfCapture.childCall);
|
||||||
|
}
|
||||||
|
if (dtmfCapture.parentCall && Array.isArray(dtmfCapture.parentCall)) {
|
||||||
|
Array.prototype.push.apply(childKeys, dtmfCapture.parentCall);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (childKeys.length) {
|
||||||
|
childDtmfCollector = new DtmfCollector({logger, patterns: childKeys});
|
||||||
|
}
|
||||||
|
if (parentKeys.length) {
|
||||||
|
parentDtmfCollector = new DtmfCollector({logger, patterns: parentKeys});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {childDtmfCollector, parentDtmfCollector};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class TaskRestDial extends Task {
|
class TaskRestDial extends Task {
|
||||||
constructor(logger, opts) {
|
constructor(logger, opts) {
|
||||||
super(logger, opts);
|
super(logger, opts);
|
||||||
@@ -15,10 +43,23 @@ class TaskRestDial extends Task {
|
|||||||
this.fromHost = this.data.fromHost;
|
this.fromHost = this.data.fromHost;
|
||||||
this.to = this.data.to;
|
this.to = this.data.to;
|
||||||
this.call_hook = this.data.call_hook;
|
this.call_hook = this.data.call_hook;
|
||||||
|
this.dtmfHook = this.data.dtmfHook;
|
||||||
this.timeout = this.data.timeout || 60;
|
this.timeout = this.data.timeout || 60;
|
||||||
this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
||||||
this.referHook = this.data.referHook;
|
this.referHook = this.data.referHook;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (this.dtmfHook) {
|
||||||
|
const {parentDtmfCollector, childDtmfCollector} = parseDtmfOptions(logger, this.data.dtmfCapture || {});
|
||||||
|
if (parentDtmfCollector) {
|
||||||
|
this.parentDtmfCollector = parentDtmfCollector;
|
||||||
|
}
|
||||||
|
if (childDtmfCollector) {
|
||||||
|
this.childDtmfCollector = childDtmfCollector;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.on('connect', this._onConnect.bind(this));
|
this.on('connect', this._onConnect.bind(this));
|
||||||
this.on('callStatus', this._onCallStatus.bind(this));
|
this.on('callStatus', this._onCallStatus.bind(this));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user