Area code to another countries

Hi Everybody

I’m new in asterisk. I have a dial plan configured to do manual local and international calls but I have to configure our server to do automatic calls to Uruguay, but I’m not sure how to do it because we use prefix to call. Some persons have told us that we have to add a block in the context with the area code of that country. (00-598-2-Phonenumber) but I don’t know how to do it. This is my dial plan. Can someone help us to know where is our error ??
I will be grateful

[CONTEXTBPX]
exten => _4-52-55-XX.,1,Set(CALLERID(num)=OURPHONE)
exten => _4-52-55-XX.,n,Set(prefix=${CUT(EXTEN|-|1)})    ; Obtengo prefijo campania
exten => _4-52-55-XX.,n,Set(country=${CUT(EXTEN|-|2)})   ; Obtengo codigo de pais
exten => _4-52-55-XX.,n,Set(area=${CUT(EXTEN|-|3)})      ; Obtengo codigo de area
exten => _4-52-55-XX.,n,Set(phone=${CUT(EXTEN|-|4)})     ; Obtengo numero de telefono
exten => _4-52-55-XX.,n,NoOp(=========Numero discado ${phone}===========)
exten => _4-52-55-XX.,n,Dial(SIP/CONTEXTBPX/${phone},60,rTo)
exten => _4-52-55-XX.,n,Hangup

exten => _4-52-155-XX.,1,Set(CALLERID(num)=OURPHONE)
exten => _4-52-155-XX.,n,Set(prefix=${CUT(EXTEN|-|1)})    ; Obtengo prefijo campania
exten => _4-52-155-XX.,n,Set(country=${CUT(EXTEN|-|2)})   ; Obtengo codigo de pais
exten => _4-52-155-XX.,n,Set(area=${CUT(EXTEN|-|3)})      ; Obtengo codigo de area
exten => _4-52-155-XX.,n,Set(phone=${CUT(EXTEN|-|4)})     ; Obtengo numero de telefono
exten => _4-52-155-XX.,n,NoOp(=========Numero discado ${phone}===========)
exten => _4-52-155-XX.,n,Dial(SIP/CONTEXTBPX/044${area:1}${phone},60,rTo)
exten => _4-52-155-XX.,n,Hangup

exten => _4-52-1X.-X.,1,Set(CALLERID(num)=OURPHONE)
exten => _4-52-1X.-X.,n,Set(prefix=${CUT(EXTEN|-|1)})    ; Obtengo prefijo campania
exten => _4-52-1X.-X.,n,Set(country=${CUT(EXTEN|-|2)})   ; Obtengo codigo de pais
exten => _4-52-1X.-X.,n,Set(area=${CUT(EXTEN|-|3)})      ; Obtengo codigo de area
exten => _4-52-1X.-X.,n,Set(phone=${CUT(EXTEN|-|4)})     ; Obtengo numero de telefono
exten => _4-52-1X.-X.,n,NoOp(=========Numero discado ${phone}===========)
exten => _4-52-1X.-X.,n,Dial(SIP/CONTEXTBPX/045${area:1}${phone},60,rTo)
exten => _4-52-1X.-X.,n,Hangup

exten => _4-52-X.-X.,1,Set(CALLERID(num)=OURPHONE)
exten => _4-52-X.-X.,n,Set(prefix=${CUT(EXTEN|-|1)})    ; Obtengo prefijo campania
exten => _4-52-X.-X.,n,Set(country=${CUT(EXTEN|-|2)})   ; Obtengo codigo de pais
exten => _4-52-X.-X.,n,Set(area=${CUT(EXTEN|-|3)})      ; Obtengo codigo de area
exten => _4-52-X.-X.,n,Set(phone=${CUT(EXTEN|-|4)})     ; Obtengo numero de telefono
exten => _4-52-X.-X.,n,NoOp(=========Numero discado ${phone}===========)
exten => _4-52-X.-X.,n,Dial(SIP/CONTEXTBPX/01${area}${phone},60,rTo)
exten => _4-52-X.-X.,n,Hangup

exten => _4-X.,1,Set(CALLERID(num)=OURPHONE)
exten => _4-X.,n,Set(prefix=${CUT(EXTEN|-|1)})    ; Obtengo prefijo campania
exten => _4-X.,n,Set(country=${CUT(EXTEN|-|2)})   ; Obtengo codigo de pais
exten => _4-X.,n,Set(area=${CUT(EXTEN|-|3)})      ; Obtengo codigo de area
exten => _4-X.,n,Set(phone=${CUT(EXTEN|-|4)})     ; Obtengo numero de telefono
exten => _4-X.,n,NoOp(=========Numero discado ${phone}===========)
exten => _4-X.,n,Dial(SIP/CONTEXTBPX/00${prefix}${area}${phone},60,rTo)
exten => _4-X.,n,Hangup

exten => _4-598-X.,1,Set(CALLERID(num)=OURPHONE)
exten => _4-598-X.,n,Set(prefix=${CUT(EXTEN|-|1)})    ; Obtengo prefijo campania
exten => _4-598-X.,n,Set(country=${CUT(EXTEN|-|2)})   ; Obtengo codigo de pais
exten => _4-598-X.,n,Set(area=${CUT(EXTEN|-|3)})      ; Obtengo codigo de area
exten => _4-598-X.,n,Set(phone=${CUT(EXTEN|-|4)})     ; Obtengo numero de telefono
exten => _4-598-X.,n,NoOp(=========Numero discado ${phone}===========)
exten => _4-498-X.,n,Dial(SIP/CONTEXTBPX/00${country}${phone},60,rTo)
exten => _4-598-X.,n,Hangup

Please use the </>button to markup your dialplan properly.

I don’t undestand the difference between manual and automatic, here.

We really need to know what the form of the complete incoming number is and what you want dialled as a result.

Your current dialplan patterns seem to be invalid in that “.” can only appear at the end of a pattern.

“-” is ignored in patterns and the matched string, so people can dial numbers without the "-"s and still have them match the patterns, but the CUT will fail. They can also insert extra "-"s and have the CUT parse the wrong field (possibly allowing a value that isn’t supposed to be allowed. The expected way of matching codes is to match enough of the code explicitly that you know the exact start and end of the substring you want.

Well. We use software in a middleware to do manual and automatic calls. Manual calls is not the problem. We want to do automatic calls througt this software and we have to put a new block of instructions. To call from here we have to dial 00+Country code(598)+Area code(1-4)+ phone number but I didn’t configure it. I’m still looking for to solve it
The prefix “4” is just to link the server with the PBX
Thanks for Answer David

You have an error in the extenion field, here.

I still don’t understand the relevance of automatic versus manual. Your dialplan appears to be overcomplicated and, as I pointed out, it is not syntactically valid, because of the misplaced "."s, but you seem to be making lots of assumptions about how it is supposed to operate that we are not party to

You really need to go back to whoever designed it, or the documentation.

David:
Yeah. Seeing manuals and comments I think too that this dialplan is so complicated. I didn’t do it but I have to modify it.
The reason between automatic of manual calls is because this is for a little contact center and sometimes they have an automatic dialing to contact clients
For some reason we have several similar dialing plans with “.” functioning, but I’m
barely learning more about this.

Thanks

To solve the problem yourself, consider the following:

; ~ Pattern A
exten => _12.,1,NoOp(12 Followed by One or More Digits)
 same => n,NoOp(Do Something)

; ~ Pattern B
exten => _1X.,1,NoOp(1 Followed by At Least Two More Digits)
 same => n,NoOp(Do Something)

; ~ Pattern C
exten => _13.,1,NoOp(13 Followed by One or More Digits)
 same => n,NoOp(Do Something)

Asterisk will use the first pattern that matches the digits that are dialed. So dialing 13-1234-1234 will always use pattern B in the above.

You could fix it (in the less obvious way) by changing pattern B so it does not match anything that starts with 13 .

; ~ Pattern B
exten => _1[124567890].,1,NoOp(1 Followed by 1,2,4,5,6,7,8,9, or 0 and One or More Digits)
 same => n,NoOp(Do Something)
1 Like

@david551,

This is not actually true. The “.” is just one or more digits. It could be used anywhere in a dial plan. It’s only common practice to use it at the end of a pattern.

For instance, I could treat any calls that end with a 5 like the following. It is a valid pattern.

exten => _X.5,1,NoOp(Two or More Digits that End with 5)
 same => n,NoOp(Do Something)

I use something similar for load testing.


Of course the dial plan shared by @jabsociales is hard to read, the use of “.” is strange and there’s no obvious reason for it be written that way. Since _1234X.X. would be equal to _1234XXX. It’s 1234 followed by four or more digits.

That conflicts with the wiki documentation, which says both . and ! terminate the pattern. It also conflicts with the code, in main/pbx.c, which eats the incoming digits up to either the ex-girlfriend logic “/” or the end of the string:

				while (*str2 && *str2 != '/') {
					str2++;
					i++;
				}

And finally, parsing such a construct requires backtracking, which is not compatible with a simple, fast, parser.

@david551
I do not condone using [.] or [!] anywhere except the end of a pattern in production. But I have seen it work in my testing.

There’s absolutely no reason for “.” or “!” to be anywhere except at the end of a pattern in a production system. Although the wiki does suggest [.] or [!] would be the proper way to handle these wildcards

What’s actually happening in the dialplan in this thread is that everything after the first . is being ignored, so _4-52-1X.-X. is being treated as though it were _4-52-1X. or rather _4521X. as the hyphens are ignored in both pattern and dialed number.

I’m not sure what it does with the excess pattern, but I think it has already updated the best match so far, and the there re no more digits to improve that, so even if it tries to match more of the pattern, it won’t update the match score. In other words it has done the end of match processing even if it turns out that it tries to interpret more of the pattern.

Well, Gentlemen, Thanks for help.

We think we have solved it. Just is necessary to do some tests to confirm. We have put this code and it seems is working. Area code 00598 was the problem.

Thanks for all :slight_smile:

exten => _4-598-X.-X.,1,Set(prefix={CUT(EXTEN|-|1)}) ; Obtengo prefijo campania exten => _4-598-X.-X.,n,Set(country={CUT(EXTEN|-|2)}) ; Obtengo codigo de pais
exten => _4-598-X.-X.,n,Set(area={CUT(EXTEN|-|3)}) ; Obtengo codigo de area exten => _4-598-X.-X.,n,Set(phone={CUT(EXTEN|-|4)}) ; Obtengo numero de telefono
exten => _4-598-X.-X.,n,Set(CALLERID(num)=10Digits)
exten => _4-598-X.-X.,n,NoOp(========= Numero discado {phone}===========) exten => _4-598-X.-X.,n,Dial(SIP/CONTEXT/**00598**{phone},60,rTo)
exten => _4-598-X.-X.,n,Hangup

I would remove the second “-X.” from all of those lines, as they don’t do anything and might confuse people trying to maintain it in the future.

You still need to evaluate whether it is vulnerable to being attacked by entering a hyphen in an unexpected place. It can definitely be confused by doing that, but I’m not sure if there is any way of making an expensive call that wouldn’t othrwisee be allowed.

My feeling is that you should filter out all the hyphens before trying to match the number. If you do that, your _4-52-1X.-X. becomes:

_4521., 1, Dial(SIP/CONTEXTIPBX/045${EXTEN:4},60,rTo)

and _4-52-X.-X. becomes

_452.,1,Dial(SIP/CONTEXTIPBX/01${EXTEN:3},60,rTo)

errors and omissions excepted.

Also, it looks to me like this line is wrong, and if it were correct, you wouldn’t have had to add your 598 block:

exten => _4-X.,n,Dial(SIP/CONTEXTBPX/00${prefix}${area}${phone},60,rTo)

I think it was supposed to be:

exten => _4-X.,n,Dial(SIP/CONTEXTBPX/00${country}${area}${phone},60,rTo)

That block and the 155 block should be simplifiable to one liners, as well.

One of the problems here has been trying to work out what the original was trying to do.

2 Likes