add sms messaging support

This commit is contained in:
Dave Horton
2020-10-09 08:00:17 -04:00
parent 950f1c83b7
commit c02aa94500
12 changed files with 689 additions and 590 deletions

View File

@@ -44,6 +44,14 @@ class CallInfo {
this.callStatus = CallStatus.Trying,
this.sipStatus = 100;
}
else if (this.direction === CallDirection.None) {
// outbound SMS
const {messageSid, accountSid, applicationSid, res} = opts;
this.messageSid = messageSid;
this.accountSid = accountSid;
this.applicationSid = applicationSid;
this.res = res;
}
else {
// outbound call triggered by REST
const {req, accountSid, applicationSid, to, tag} = opts;

View File

@@ -34,18 +34,20 @@ class CallSession extends Emitter {
this.srf = srf;
this.callInfo = callInfo;
this.tasks = tasks;
this.updateCallStatus = srf.locals.dbHelpers.updateCallStatus;
this.serviceUrl = srf.locals.serviceUrl;
this.taskIdx = 0;
this.stackIdx = 0;
this.callGone = false;
this.tmpFiles = new Set();
// if this is a ConfirmSession
if (!this.isConfirmCallSession) sessionTracker.add(this.callSid, this);
if (!this.isSmsCallSession) {
this.updateCallStatus = srf.locals.dbHelpers.updateCallStatus;
this.serviceUrl = srf.locals.serviceUrl;
}
if (!this.isConfirmCallSession && !this.isSmsCallSession) {
sessionTracker.add(this.callSid, this);
}
}
/**
@@ -66,7 +68,7 @@ class CallSession extends Emitter {
* SIP call-id for the call
*/
get callId() {
return this.callInfo.direction;
return this.callInfo.callId;
}
/**
@@ -166,6 +168,13 @@ class CallSession extends Emitter {
return this.constructor.name === 'ConfirmCallSession';
}
/**
* returns true if this session is a SmsCallSession
*/
get isSmsCallSession() {
return this.constructor.name === 'SmsCallSession';
}
/**
* execute the tasks in the CallSession. The tasks are executed in sequence until
* they complete, or the caller hangs up.
@@ -201,7 +210,7 @@ class CallSession extends Emitter {
this._onTasksDone();
this._clearResources();
if (!this.isConfirmCallSession) sessionTracker.remove(this.callSid);
if (!this.isConfirmCallSession && !this.isSmsCallSession) sessionTracker.remove(this.callSid);
}
trackTmpFile(path) {

View File

@@ -0,0 +1,22 @@
const CallSession = require('./call-session');
/**
* @classdesc Subclass of CallSession. Represents a CallSession
* that is established for the purpose of sending an outbound SMS
* @extends CallSession
*/
class SmsCallSession extends CallSession {
constructor({logger, application, srf, tasks, callInfo}) {
super({
logger,
application,
srf,
tasks,
callInfo
});
}
}
module.exports = SmsCallSession;