Hello,
I have a requirement to normalise a number to an international E164 inside Kamailio.
In my scenario I'm receiving a call from "a platform", and then making a call out to the same platform. I'm then adding some services to that call (e.g. recording it) on the way through.
The problem is that sometimes the number I receive in the FROM field in the initial invite from "A platform" has 44 at the front, but no +. "A Platform" is then rejecting the call back in from myself, because the FROM field isn't formatted correctly.
Scenario 1 - WORKS FINE - sometimes we see this. PSTN -> FROM:07700900000 -> A PLATFORM -> FROM:07700900000 -> ME Call Centre <- A PLATFORM <- FROM:07700900000 <- ME
Scenario 2 DOES NOT WORK - sometimes we see this. PSTN -> FROM:447700900000 -> A PLATFORM -> FROM:447700900000 -> Aeriandi Call Centre <- A PLATFORM <- FROM:447700900000 <- Aeriandi
Scenario 3 WORKS by fixing up the number by adding a + PSTN -> FROM:447700900000 -> A PLATFORM -> FROM: 447700900000 -> Aeriandi Call Centre <- A PLATFORM <- FROM:+447700900000 <- Aeriandi (ADD a PLUS)
So I'm investigating if it's possible to fix up the number and add the + in Kamailio. Clearly I could detect if the number starts with 44 and change this to +44, but this seems very brittle (what about other international numbers) - it there a proper way to do this, or a standard module?
Unfortunately asking "A platform" to send me the "FROM" in a consistent format is not an option.
Many Thanks,
Daniel
On Monday 02 November 2015 17:28:29 Daniel Bryars wrote:
So I'm investigating if it's possible to fix up the number and add the + in Kamailio. Clearly I could detect if the number starts with 44 and change this to +44, but this seems very brittle (what about other international numbers) - it there a proper way to do this, or a standard module?
I do it with a couple of regexps for $fU/$tU$rU. You just have to make some assumtions. It pretty stupid straight forward code, transforming to "e164 plus" format and than back to the endpoint specific settings:
$avp(ntU)=$tU;
if($tU=~"^00[1-9][0-9]+$") { $avp(ntU)="+"+$(tU{s.substr,2,0}); } else if($tU=~"^0[1-9][0-9]+$") { $avp(ntU)="+31"+$(tU{s.substr,1,0}); } else if($tU~="^[2-8][0-9]{5,6}$") { $avp(ntU)="+31"+$avp(areacode)+$tU; } else { $avp(ntU)="+"+$tU; }
and use $avp(ntU) with uac_replace_to (after modifiying $ntU to the format desired by endpoint (yet more regexps like above)).
Repeat for $fU and $rU. You might want to to this in an external script instead of kamailio config script though.
If there is a better way, I'd like to know myself.
On 02/11/15 18:52, Daniel Tryba wrote:
On Monday 02 November 2015 17:28:29 Daniel Bryars wrote:
So I'm investigating if it's possible to fix up the number and add the + in Kamailio. Clearly I could detect if the number starts with 44 and change this to +44, but this seems very brittle (what about other international numbers) - it there a proper way to do this, or a standard module?
I do it with a couple of regexps for $fU/$tU$rU. You just have to make some assumtions. It pretty stupid straight forward code, transforming to "e164 plus" format and than back to the endpoint specific settings:
$avp(ntU)=$tU; if($tU=~"^00[1-9][0-9]+$") { $avp(ntU)="+"+$(tU{s.substr,2,0}); } else if($tU=~"^0[1-9][0-9]+$") { $avp(ntU)="+31"+$(tU{s.substr,1,0}); } else if($tU~="^[2-8][0-9]{5,6}$") { $avp(ntU)="+31"+$avp(areacode)+$tU; } else { $avp(ntU)="+"+$tU; }
and use $avp(ntU) with uac_replace_to (after modifiying $ntU to the format desired by endpoint (yet more regexps like above)).
Repeat for $fU and $rU. You might want to to this in an external script instead of kamailio config script though.
If there is a better way, I'd like to know myself.
Dialplan module can be used to do those transformations -- if you have many countries, you can group the country rules under same dialplan id. I used to set dialplan id to to the country code then associate users with it via extra column in subscriber table (which can be loaded with load_credentials parameter in auth_db module). A second extra column might be needed for area code.
Maybe worth collecting the dialplan module rules for different country in a wiki page, so people that are familiar with various countries can contribute.
Cheers, Daniel