merge features from hosted branch (#32)

major merge of features from the hosted branch that was created temporarily during the initial launch of jambonz.org
This commit is contained in:
Dave Horton
2021-06-17 16:25:50 -04:00
committed by GitHub
parent 473a34ec9f
commit 9b59d08dcf
68 changed files with 3436 additions and 1066 deletions

View File

@@ -3,9 +3,11 @@ const makeTask = require('../../tasks/make_task');
const RestCallSession = require('../../session/rest-call-session');
const CallInfo = require('../../session/call-info');
const {CallDirection, CallStatus} = require('../../utils/constants');
const { v4: uuidv4 } = require('uuid');
const SipError = require('drachtio-srf').SipError;
const sysError = require('./error');
const Requestor = require('../../utils/requestor');
const dbUtils = require('../../utils/db-utils');
router.post('/', async(req, res) => {
const {logger} = req.app.locals;
@@ -15,6 +17,7 @@ router.post('/', async(req, res) => {
let uri, cs, to;
const restDial = makeTask(logger, {'rest:dial': req.body});
const {srf} = require('../../..');
const {lookupAccountDetails} = dbUtils(logger, srf);
const {getSBC, getFreeswitch} = srf.locals;
const sbcAddress = getSBC();
if (!sbcAddress) throw new Error('no available SBCs for outbound call creation');
@@ -24,13 +27,24 @@ router.post('/', async(req, res) => {
headers: req.body.headers || {}
};
const {lookupTeamsByAccount, lookupAccountBySid} = srf.locals.dbHelpers;
const account = await lookupAccountBySid(req.body.account_sid);
const accountInfo = await lookupAccountDetails(req.body.account_sid);
const callSid = uuidv4();
opts.headers = {
...opts.headers,
'X-Call-Sid': callSid,
'X-Account-Sid': req.body.account_sid
};
switch (target.type) {
case 'phone':
case 'teams':
uri = `sip:${target.number}@${sbcAddress}`;
to = target.number;
if ('teams' === target.type) {
const {lookupTeamsByAccount} = srf.locals.dbHelpers;
const obj = await lookupTeamsByAccount(req.body.account_sid);
if (!obj) throw new Error('dial to ms teams not allowed; account must first be configured with teams info');
Object.assign(opts.headers, {
@@ -83,8 +97,10 @@ router.post('/', async(req, res) => {
* attach our requestor and notifier objects
* these will be used for all http requests we make during this call
*/
app.requestor = new Requestor(logger, app.call_hook);
if (app.call_status_hook) app.notifier = new Requestor(logger, app.call_status_hook);
app.requestor = new Requestor(logger, account.account_sid, app.call_hook, account.webhook_secret);
if (app.call_status_hook) {
app.notifier = new Requestor(logger, account.account_sid, app.call_status_hook, account.webhook_secret);
}
else app.notifier = {request: () => {}};
/* now launch the outdial */
@@ -104,10 +120,11 @@ router.post('/', async(req, res) => {
req: inviteReq,
to,
tag: app.tag,
callSid,
accountSid: req.body.account_sid,
applicationSid: app.application_sid
});
cs = new RestCallSession({logger, application: app, srf, req: inviteReq, ep, tasks, callInfo});
cs = new RestCallSession({logger, application: app, srf, req: inviteReq, ep, tasks, callInfo, accountInfo});
cs.exec(req);
res.status(201).json({sid: cs.callSid});

View File

@@ -8,12 +8,15 @@ const makeTask = require('../../tasks/make_task');
router.post('/:sid', async(req, res) => {
const {logger} = req.app.locals;
const {srf} = req.app.locals;
const {messageSid} = req.body;
const {message_sid, account_sid} = req.body;
logger.debug({body: req.body}, 'got createMessage request');
const data = [Object.assign({verb: 'message'}, req.body)];
delete data[0].messageSid;
const data = [{
verb: 'message',
...req.body
}];
delete data[0].message_sid;
try {
const tasks = normalizeJambones(logger, data)
@@ -21,8 +24,8 @@ router.post('/:sid', async(req, res) => {
const callInfo = new CallInfo({
direction: CallDirection.None,
messageSid,
accountSid: req.params.sid,
messageSid: message_sid,
accountSid: account_sid,
res
});
const cs = new SmsSession({logger, srf, tasks, callInfo});

View File

@@ -13,11 +13,14 @@ router.post('/:partner', async(req, res) => {
logger.debug({body: req.body}, `got incomingSms request from partner ${req.params.partner}`);
let tasks;
const {srf} = require('../../..');
const {lookupAccountBySid} = srf.locals.dbHelpers;
const app = req.body.app;
const account = await lookupAccountBySid(app.accountSid);
const hook = app.messaging_hook;
const requestor = new Requestor(logger, hook);
const requestor = new Requestor(logger, account.account_sid, hook, account.webhook_secret);
const payload = {
provider: req.params.partner,
carrier: req.params.partner,
messageSid: app.messageSid,
accountSid: app.accountSid,
applicationSid: app.applicationSid,
@@ -38,7 +41,7 @@ router.post('/:partner', async(req, res) => {
}
// process any versb in response
// process any verbs in response
if (Array.isArray(tasks) && tasks.length) {
const {srf} = req.app.locals;

View File

@@ -32,7 +32,10 @@ function retrieveCallSession(callSid, opts) {
return cs;
}
const updateCall = async(req, res) => {
/**
* update a call
*/
router.post('/:callSid', async(req, res) => {
const logger = req.app.locals.logger;
const callSid = req.params.callSid;
logger.debug({body: req.body}, 'got upateCall request');
@@ -42,23 +45,11 @@ const updateCall = async(req, res) => {
logger.info(`updateCall: callSid not found ${callSid}`);
return res.sendStatus(404);
}
res.sendStatus(204);
res.sendStatus(202);
cs.updateCall(req.body, callSid);
} catch (err) {
sysError(logger, res, err);
}
};
/**
* update a call
*/
/* leaving in for legacy; should have been (and now is) a PUT */
router.post('/:callSid', async(req, res) => {
await updateCall(req, res);
});
router.put('/:callSid', async(req, res) => {
await updateCall(req, res);
});
module.exports = router;