Multiple DID formats in same trunk

So, I have a strange problem to solve. We have a customer whose ITSP does not do DID normalisation before passing call to trunk.

ITSP sends DID in SIP To: field in one of following formats:

To: <sip:[email protected];user=phone>       
To: <sip:[email protected];user=phone>               
To: <sip:[email protected];user=phone>       
To: <tel:+49123456789>

What would be the most elegant solutions to get DID from To: in same context?

Obvious solution - to change an ITSP - is not an option in this case.

AFAIK there is no elegant solution. You will need to write custom dial plan to normalize the formats.

Use the context from-pstn-toheader in extensions.conf as a guide. Put a modified version of that, named e.g. from-pstn-normalize-did, into extensions_custom.conf, then change the context for your trunk to from-pstn-normalize-did.

You don’t have to worry about tel vs. sip or what comes after the @, but you do need to properly handle the case where the @ is not present.

Also, if you have DIDs in other countries from the same provider, you might see e.g. 0033123456789 for a Paris DID, which your dial plan will have to normalize.

Perhaps ‘cut’ on @ and select the last 9 digits from field 1

[custom-get-did-from-to-header]
exten => 1,n,Set(realdid=${SIP_HEADER(To)})
exten => s,n,Set(realdid=${CUT(realdid,@,1)})
exten => s,n,Goto(from-trunk,${realdid,-9})

thanks for suggestion, but not all of formats have @. Also, numer is not 9 digits necessarily.

I was afraid that would be the answer.

If there is no @ then field 1 is everything, -9 selects the last nine digits of field 1. which matches everyone of your examples.

True, but Germany has variable length numbers and DIDs in different cities would likely have different lengths. Also, if the OP has DIDs from other countries, length would obviously vary.

However, this is good idea. I will strip > first, then match against @. Then strip everything from beginning to :.

You can then cut on : and work with field 2. an expanded version of the from-pstn-e164-us modified for Germany would be a good place to start, selectively remove the prefixes appropriately to leave just the ‘national’ number,

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.