bugfix for REST outdial to teams

This commit is contained in:
Dave Horton
2020-11-24 10:06:58 -05:00
parent 25c3512e41
commit 16c728e246

View File

@@ -26,8 +26,19 @@ router.post('/', async(req, res) => {
switch (target.type) { switch (target.type) {
case 'phone': case 'phone':
case 'teams':
uri = `sip:${target.number}@${sbcAddress}`; uri = `sip:${target.number}@${sbcAddress}`;
to = target.number; 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, {
'X-MS-Teams-FQDN': obj.ms_teams_fqdn,
'X-MS-Teams-Tenant-FQDN': target.tenant || obj.tenant_fqdn
});
if (target.vmail === true) uri = `${uri};opaque=app:voicemail`;
}
break; break;
case 'user': case 'user':
uri = `sip:${target.name}`; uri = `sip:${target.name}`;
@@ -124,12 +135,14 @@ router.post('/', async(req, res) => {
if (err instanceof SipError) { if (err instanceof SipError) {
if ([486, 603].includes(err.status)) callStatus = CallStatus.Busy; if ([486, 603].includes(err.status)) callStatus = CallStatus.Busy;
else if (487 === err.status) callStatus = CallStatus.NoAnswer; else if (487 === err.status) callStatus = CallStatus.NoAnswer;
sipLogger.info(`REST outdial failed with ${err.status}`); if (sipLogger) sipLogger.info(`REST outdial failed with ${err.status}`);
cs.emit('callStatusChange', {callStatus, sipStatus: err.status}); else console.log(`REST outdial failed with ${err.status}`);
if (cs) cs.emit('callStatusChange', {callStatus, sipStatus: err.status});
} }
else { else {
cs.emit('callStatusChange', {callStatus, sipStatus: 500}); if (cs) cs.emit('callStatusChange', {callStatus, sipStatus: 500});
sipLogger.error({err}, 'REST outdial failed'); if (sipLogger) sipLogger.error({err}, 'REST outdial failed');
else console.error(err);
} }
ep.destroy(); ep.destroy();
} }