added initial support for REST-initiated outdials

This commit is contained in:
Dave Horton
2020-02-01 16:16:00 -05:00
parent 44a1b45357
commit 2525b8c70a
28 changed files with 985 additions and 127 deletions

View File

@@ -5,6 +5,7 @@ class CallInfo {
constructor(opts) {
this.direction = opts.direction;
if (this.direction === CallDirection.Inbound) {
// inbound call
const {app, req} = opts;
this.callSid = req.locals.callSid,
this.accountSid = app.account_sid,
@@ -19,19 +20,32 @@ class CallInfo {
this.originatingSipTrunkName = req.get('X-Originating-Carrier');
}
else if (opts.parentCallInfo) {
console.log(`is opts.parentCallInfo a CallInfo ${opts.parentCallInfo instanceof CallInfo}`);
const {req, parentCallInfo} = opts;
this.callSid = uuidv4();
// outbound call that is a child of an existing call
const {req, parentCallInfo, to, callSid} = opts;
this.callSid = callSid || uuidv4();
this.parentCallSid = parentCallInfo.callSid;
this.accountSid = parentCallInfo.accountSid;
this.applicationSid = parentCallInfo.applicationSid;
this.from = req.callingNumber;
this.to = req.calledNumber;
this.to = to || req.calledNumber;
this.callerName = this.from.name || req.callingNumber;
this.callId = req.get('Call-ID');
this.callStatus = CallStatus.Trying,
this.sipStatus = 100;
}
else {
// outbound call triggered by REST
const {req, accountSid, applicationSid, to, tag} = opts;
this.callSid = uuidv4();
this.accountSid = accountSid;
this.applicationSid = applicationSid;
this.callStatus = CallStatus.Trying,
this.callId = req.get('Call-ID');
this.sipStatus = 100;
this.from = req.callingNumber;
this.to = to;
if (tag) this._customerData = tag;
}
}
updateCallStatus(callStatus, sipStatus) {
@@ -43,6 +57,10 @@ class CallInfo {
this._customerData = obj;
}
get customerData() {
return this._customerData;
}
toJSON() {
const obj = {
callSid: this.callSid,
@@ -59,9 +77,10 @@ class CallInfo {
['parentCallSid', 'originatingSipIP', 'originatingSipTrunkName'].forEach((prop) => {
if (this[prop]) obj[prop] = this[prop];
});
if (typeof this.duration === 'number') obj.duration = this.duration;
if (this._customerData && Object.keys(this._customerData).length) {
obj.customerData = this._customerData;
if (this._customerData) {
Object.assign(obj, {customerData: this._customerData});
}
return obj;
}