allow dial to user without supplying sip_realm (will default to that configured for the caller account)

This commit is contained in:
Dave Horton
2020-11-29 15:00:42 -05:00
parent 16c728e246
commit 1bc583e805
4 changed files with 67 additions and 61 deletions

View File

@@ -246,9 +246,10 @@ class TaskDial extends Task {
async _attemptCalls(cs) {
const {req, srf} = cs;
const {getSBC} = srf.locals;
const {lookupTeamsByAccount} = srf.locals.dbHelpers;
const {lookupTeamsByAccount, lookupAccountBySid} = srf.locals.dbHelpers;
const sbcAddress = this.proxy || getSBC();
const teamsInfo = {};
let fqdn;
if (!sbcAddress) throw new Error('no SBC found for outbound call');
const opts = {
@@ -270,11 +271,23 @@ class TaskDial extends Task {
this._killOutdials();
}, this.timeout * 1000);
this.target.forEach((t) => {
this.target.forEach(async(t) => {
try {
t.url = t.url || this.confirmUrl;
t.method = t.method || this.confirmMethod || 'POST';
if (t.type === 'teams') t.teamsInfo = teamsInfo;
if (t.type === 'user' && !t.name.includes('@') && !fqdn) {
const user = t.name;
try {
const {sip_realm} = await lookupAccountBySid(cs.accountSid);
if (sip_realm) {
t.name = `${user}@${sip_realm}`;
this.logger.debug(`appending sip realm ${sip_realm} to dial target user ${user}`);
}
} catch (err) {
this.logger.error({err}, 'Error looking up account by sid');
}
}
const sd = placeCall({
logger: this.logger,
application: cs.application,

View File

@@ -103,7 +103,8 @@ function installSrfLocals(srf, logger) {
lookupAppBySid,
lookupAppByRealm,
lookupAppByTeamsTenant,
lookupTeamsByAccount
lookupTeamsByAccount,
lookupAccountBySid
} = require('@jambonz/db-helpers')({
host: process.env.JAMBONES_MYSQL_HOST,
user: process.env.JAMBONES_MYSQL_USER,
@@ -142,6 +143,7 @@ function installSrfLocals(srf, logger) {
lookupAppByRealm,
lookupAppByTeamsTenant,
lookupTeamsByAccount,
lookupAccountBySid,
updateCallStatus,
retrieveCall,
listCalls,