mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 17:17:58 +00:00
feat: lcr
This commit is contained in:
@@ -91,8 +91,13 @@ router.post('/', async(req, res) => {
|
|||||||
* check if from-number matches any existing numbers on Jambonz
|
* check if from-number matches any existing numbers on Jambonz
|
||||||
* */
|
* */
|
||||||
if (target.type === 'phone' && !target.trunk) {
|
if (target.type === 'phone' && !target.trunk) {
|
||||||
const {lookupCarrierByPhoneNumber} = dbUtils(this.logger, srf);
|
const {lookupCarrierByPhoneNumber, lookupCarrierByLcr} = dbUtils(this.logger, srf);
|
||||||
const voip_carrier_sid = await lookupCarrierByPhoneNumber(req.body.account_sid, restDial.from);
|
// firstly LCR
|
||||||
|
let voip_carrier_sid = await lookupCarrierByLcr(req.body.account_sid, to);
|
||||||
|
if (!voip_carrier_sid) {
|
||||||
|
// later by phone
|
||||||
|
voip_carrier_sid = await lookupCarrierByPhoneNumber(req.body.account_sid, restDial.from);
|
||||||
|
}
|
||||||
logger.info(
|
logger.info(
|
||||||
`createCall: selected ${voip_carrier_sid} for requested phone number: ${restDial.from || 'unspecified'})`);
|
`createCall: selected ${voip_carrier_sid} for requested phone number: ${restDial.from || 'unspecified'})`);
|
||||||
if (voip_carrier_sid) {
|
if (voip_carrier_sid) {
|
||||||
|
|||||||
@@ -399,7 +399,7 @@ class TaskDial extends Task {
|
|||||||
const {req, srf} = cs;
|
const {req, srf} = cs;
|
||||||
const {getSBC} = srf.locals;
|
const {getSBC} = srf.locals;
|
||||||
const {lookupTeamsByAccount, lookupAccountBySid} = srf.locals.dbHelpers;
|
const {lookupTeamsByAccount, lookupAccountBySid} = srf.locals.dbHelpers;
|
||||||
const {lookupCarrier, lookupCarrierByPhoneNumber} = dbUtils(this.logger, cs.srf);
|
const {lookupCarrier, lookupCarrierByPhoneNumber, lookupCarrierByLcr} = dbUtils(this.logger, cs.srf);
|
||||||
const sbcAddress = this.proxy || getSBC();
|
const sbcAddress = this.proxy || getSBC();
|
||||||
const teamsInfo = {};
|
const teamsInfo = {};
|
||||||
let fqdn;
|
let fqdn;
|
||||||
@@ -467,10 +467,10 @@ class TaskDial extends Task {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* trunk isn't specified,
|
* trunk isn't specified,
|
||||||
* check if number matches any existing numbers
|
* check if number matches any LCR routes
|
||||||
* */
|
* */
|
||||||
if (t.type === 'phone' && !t.trunk) {
|
if (t.type === 'phone' && !t.trunk) {
|
||||||
const voip_carrier_sid = await lookupCarrierByPhoneNumber(req.body.account_sid, t.number);
|
const voip_carrier_sid = lookupCarrierByLcr(req.body.account_sid, t.number);
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
`Dial:_attemptCalls: selected ${voip_carrier_sid} for requested phone number: ${t.number})`);
|
`Dial:_attemptCalls: selected ${voip_carrier_sid} for requested phone number: ${t.number})`);
|
||||||
if (voip_carrier_sid) {
|
if (voip_carrier_sid) {
|
||||||
|
|||||||
@@ -150,10 +150,40 @@ module.exports = (logger, srf) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sqlQueryLcrByAccountSid = `SELECT lcr_sid FROM lcr WHERE account_sid = ? OR
|
||||||
|
service_provider_sid = (SELECT service_provider_sid from accounts where account_sid = ?)`;
|
||||||
|
const sqlQueryLcrRouteByLcrSid = 'SELECT * FROM lcr_routes WHERE lcr_sid = ? ORDER BY priority';
|
||||||
|
const sqlQueryLcrCarrierSetEntryByLcrRouteSid = 'SELECT * FROM lcr_carrier_set_entry WHERE lcr_route_sid = ? ORDER BY priority'
|
||||||
|
const lookupCarrierByLcr = async(account_sid, toNumber) => {
|
||||||
|
const pp = pool.promise();
|
||||||
|
try {
|
||||||
|
const[lcrs] = await pp.query(sqlQueryLcrByAccountSid, [account_sid, account_sid]);
|
||||||
|
if (lcrs.length) {
|
||||||
|
const lcr_sid = lcrs[0];
|
||||||
|
const [lcr_routes] = await pp.query(sqlQueryLcrRouteByLcrSid, [lcr_sid]);
|
||||||
|
if (lcr_routes.length) {
|
||||||
|
for (const r of lcr_routes) {
|
||||||
|
var matcher = new RegExp(r.regex);
|
||||||
|
if (matcher.test(toNumber)) {
|
||||||
|
const [entries] = await pp.query(sqlQueryLcrCarrierSetEntryByLcrRouteSid, [r.lcr_route_sid]);
|
||||||
|
// Currently just support first entry;
|
||||||
|
if(entries.length) {
|
||||||
|
return entries[0].voip_carrier_sid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({err}, `lookupCarrierByLcr: Error ${account_sid}:${toNumber}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
lookupAccountDetails,
|
lookupAccountDetails,
|
||||||
updateSpeechCredentialLastUsed,
|
updateSpeechCredentialLastUsed,
|
||||||
lookupCarrier,
|
lookupCarrier,
|
||||||
lookupCarrierByPhoneNumber
|
lookupCarrierByPhoneNumber,
|
||||||
|
lookupCarrierByLcr
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user