diff --git a/lib/http-routes/api/create-call.js b/lib/http-routes/api/create-call.js index 55b3d81f..86d75f5d 100644 --- a/lib/http-routes/api/create-call.js +++ b/lib/http-routes/api/create-call.js @@ -26,8 +26,19 @@ router.post('/', async(req, res) => { 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, { + '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; case 'user': uri = `sip:${target.name}`; @@ -124,12 +135,14 @@ router.post('/', async(req, res) => { if (err instanceof SipError) { if ([486, 603].includes(err.status)) callStatus = CallStatus.Busy; else if (487 === err.status) callStatus = CallStatus.NoAnswer; - sipLogger.info(`REST outdial failed with ${err.status}`); - cs.emit('callStatusChange', {callStatus, sipStatus: err.status}); + if (sipLogger) sipLogger.info(`REST outdial failed with ${err.status}`); + else console.log(`REST outdial failed with ${err.status}`); + if (cs) cs.emit('callStatusChange', {callStatus, sipStatus: err.status}); } else { - cs.emit('callStatusChange', {callStatus, sipStatus: 500}); - sipLogger.error({err}, 'REST outdial failed'); + if (cs) cs.emit('callStatusChange', {callStatus, sipStatus: 500}); + if (sipLogger) sipLogger.error({err}, 'REST outdial failed'); + else console.error(err); } ep.destroy(); }