Need a comparison on the last digits

Hi all. I have a number. For example, +49 8104 555555555. How can I make dialing +49 8104 555555555, 00 8104 555555555, 8104 555555555, 555555555 always the same action? Can this be done in one line, one exten?
I tried exten => _.5555555555,GoTo(incoming-office ,s,114). This does not work. This line accepts calls from both 555555555 and 555555551 and so on. I need a comparison on the last digits, in general.

Thanks for the help!

exten => _X.,GotoIf($[“${EXTEN:-9}” = “555555555”]?incoming-office ,s,114)

1 Like

Provided you know how many “last digits” you want to compare (which, for
example in Germany, is essentially impossible, because there is no standard
for the length of a telephone number), you can use the $LEN() function to find
out how many digits (or symbols, if you’re including “+”) have been dialled,
and then use ${NUMBER:chop} to remove the first “chop” digits off the front,
which you would calculate as (length-digits_to_keep).

Personally Iwould go about this the other way and ask “what prefixes are people
allowed to dial before a number my dialplan is interested in?” and then set up
an extension for each prefix, all pointing to a generic extension which then
does the dialling work for you.

For example (this is in AEL format, but that’s easy to adapt:

_0ZX. => goto 0049${EXTEN:1};
_+ZX. => goto 00${EXTEN:1};
_ZX. => goto 0049221${EXTEN};

_00X. => { All the interesting stuff; }

So, if someone dials a number starting with zero and followed by a non-zero
digit, that will strip the zero, prefix with the country code 0049 and then
pass over to the generic extension.

If someone dials anything starting with two zeros, that’s just processed as-
is.

If somedial dials a number starting with +, that symbol gets replaced with 00.

If someone dials a number starting with non-zero, it gets prefixed with 0049221
(which means Cologne, Germany) and then handled by the generic extension.

Hope that helps,

Antony.

1 Like

You can use negative values when substringing variables, to access from the tail of the number, however, the preferred approach in a case like this is to canonicalise the numbers, for example into E.164 format.

Dialplan . and ! wildcards can only be used at the end of a number.

1 Like

Ooh, I forgot that you can use a negative number in ${EXTEN:chop}.

Much neater than my calculation :slight_smile:

Antony.

Hi Antony! This number is not dialed by employees. Customers of one of the companies call this number (one of many). I want that when dialing (outside) this number, there will be a transition to a specific employee. It is defined in a different context and has nothing to do with the question.
The problem is that if you call from the CIS, then the number will be +49, if you call from Germany, then 555 55 555, if you call from Europe, then 00 8104 555 55 555.

Therefore, it is beneficial to make a comparison any digits 555 55 555 go to if. The problem is that we do not have the exact number of digits in front that need to be cut off. So, my question:

exten => (anymanydigits)5555555555,GoTo(incoming-office ,s,114) it is possible?

Canonicalise the numbers. Presumably these are different providers, so just have a context for each.

Do you propose to make, conditionally, three exten lines for a different possible set of a specific number? This is the solution, but I expected to be able to do it more elegantly)

What does it mean?

I expect you to rewrite all the numbers into the +49 format, based only on length and initial digits, then use your individual extension matches on the result.

Canonicalise means convert to a standard form.

You use GoTo to rewrite the ${EXTEN} value.

1 Like

Sorry, but I still don’t really understand what you’re talking about. Can you provide an example ?

_+49., 1,GoTo(canoncalised,${EXTEN},1)
_00XXXXXXXXXXXXX.,s,GoTo(canonicalised,+49${EXTEN:2},1)
_8104XXXXXXXX.,s,GoTo(canoncialised,+498014${EXTEN:4},1) ; Might need to use exact length matches
_.,s,Hangup() ; should really use the correct cause code for an invalid number

etc.

Although, normally only one format would be assoiciated with any one source, and you would just have the appropriate GoTo in the initial context for that source.

1 Like

As I understand it, in your example, all calls in the context are cast to the same beginning +49? Then we always get numbers of the same length and format. Is that the point? _00X wiil be +49X, etc?

small fif is to always use E.164
as it makes it easyer when you end up with users in multiple cuntrys

[FromDE_8104]
exten => _00Z!,1,Goto(+${EXTEN:2},1) ;Interantional Prefix
exten => _XXXXXXXXXXXXX,1,Goto(+49${EXTEN},1) ; National
exten => _XXXXXXXXX,1,Goto(+498104${EXTEN},1) ; Arear code 8104
exten => _+!,1,Hangup(${AST_CAUSE_UNALLOCATED}) ;E.164

exten => +498104555555555,1,Goto(incoming-office,s,114)

Good point of view. But how to put it into practice with Germany? In Germany, there is no set length for a phone number. It can be 5-7-8 or even 9 characters, depending on the phone company. As Antony said in his post.

Anyway, thanks for your all recommendations. I will.

if I remember correctly, with area code there is a leading 0
update

[FromDE]
exten => _00Z!,1,Goto(+${EXTEN:2},1) ;Interantional Prefix
exten => _0XXXXX!,1,Goto(+49${EXTEN:1},1) ; National
exten => _XXXXX!,1,Goto(+49${ArearCode}${EXTEN},1) ; Local (set_var=ArearCode=8104) in pj_sip.conf
exten => _+!,1,Hangup(${AST_CAUSE_UNALLOCATED}) ;E.164

exten => +498104555555555,1,Goto(incoming-office,s,114)
1 Like

exten = _49.,1,ExecIf($[“${EXTEN:-9}” = “555555555”]?NoOp(Do what you have to do or replace ExecIf with GotoIf))

1 Like

I can’t all ur answers mark Solutions. But thanks for you all.

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