Can't dial a number with whitespace or parens

Hello! Been using Freepbx for over a year now. I’ve come to the forums and searched and found so many answers for weird problems, I can’t thank the community enough.

However, I’ve finally been stymied - couldn’t find anything with my weak search-fu.

I can receive calls just fine.
I can make outbound calls with numbers and dashes just fine.

HOWEVER, if the phone number contains a paren or whitespace, the dial noise happens, but it hangs up.
The log says:
[2017-10-25 08:41:03] NOTICE[2784][C-00000005] chan_sip.c: Call from ‘pamppfs2’ (192.168.1.225:55902) to extension ‘(777) 777-7777’ rejected because extension not found in context ‘from-internal’.
[2017-10-25 08:41:03] VERBOSE[1628] chan_sip.c: Extension Changed 231[ext-local] new state InUse for Notify User 235
[2017-10-25 08:41:03] VERBOSE[1628] chan_sip.c: Extension Changed 231[ext-local] new state Idle for Notify User 235 (queued)

Any idea how to fix it?

Again, if the digits are entered in without whitespace, without parens, it’ll dial just fine and connect me to the person on the other end.

Any suggestions would be much appreciated.

This little bit of dialplan will match strings that have a space or parenthesis character within the first four positions and proceed to filter spaces and parentheses out of the whole dial string. Make a section in /etc/asterisk/extensions_custom.conf with the heading

[from-internal-custom]

or if that heading already exists, just add these lines to it:

exten => _[0-9 ()][0-9 ()][0-9 ()][0-9 ()].,1,NoOp(Found an extension with spaces and parens)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)

then run

asterisk -rx "dialplan reload"

from SSH and give it a try.

I was bothered this morning becase I started thinking about this solution and wondered why it doesn’t match plain digit strings and cause a loop. After all, it should match 1234… as well as 1(23)… according to the pattern. The reason it works is explained on the Asterisk Pattern Matching wiki. All of the patterns in the [from-internal] context that are just digits will match first because of rule 3 under “Order of Pattern Matching,” which states that more constrained patterns will be selected first. After all the digit-only patterns are exhausted then Asterisk will find this pattern that contains digits, spaces, and parentheses. You may need to adjust things if you use patterns that include alpha characters.

Hello @billsimon, @Seneschul,

You can always strip all the unnecessary strings at the final stage before dialling the number.
Yo can use the macro-dialout-trunk-predial-hook macro to do that.

I use it like this:

[macro-dialout-trunk-predial-hook]
;Remove spaces or dashes from outboundnumber when calling
exten => s,1,Set(OUTNUM=${FILTER(0123456789*#+,${OUTNUM})})
exten => s,n,MacroExit()

Thank you,

Daniel Friedman
Trixton LTD.

Daniel, how does the call get routed to the trunk in the first place in order to get filtered by that macro? Do you have an Outbound Route that matches spaces and such?

@billsimon
Hmm. It actually is causing an endless loop… actually, oh dear.

It’s taking priority over all other matches and endlessly looping, first.

Wound up playing with the regex a bit. Eventually expanded it to multiple lines to address international calling.
Current version (Edited for clarity):

[from-internal-custom]
exten => _[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _X[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXXXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXXXXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)
exten => _XXXXXXXXXXXXX[\ ()].,1,NoOp(Found an extension with spaces and parens, filtering)
same => n,Goto(from-internal,${FILTER(0-9,${EXTEN})},1)

Works well, it’s ugly but Asterisk does not support leading fuzzy matches so I’m unsure of how to reduce it down.

@danielf
I tried your solution, as it seems much more succinct.
However, it kept failing with the original “Bad Extension” error. I placed your solution in the “extensions_custom.conf” file - should it have gone somewhere else?

Conversationally speaking, why wouldn’t freepbx come with this built-in?
I didn’t have an issue with it until I started using their ZULU UC softphone - all other softphones automatically stripped whitespace/parens.
When I spoke to Sangoma, they insisted it was not their app, and I needed to have my configuration audited by them for where I had screwed something up. (Which I found ridiculous as I haven’t modified any dialplans …)

Thank you so much for getting me on the right path!

Sene

1 Like

Sene, which pattern were you dialing that caused the infinite loop? I am curious, because it doesn’t happen in my dialplan with the pattern I posted. I was glad for your question, because it inspired me to figure out something that I had wanted to do as well.

Hello @Seneschul, @billsimon

Yes, You need to insert my code to the extensions_custom.conf file and reload the dialplan:
asterisk -x'dialplan reload'.

My code only works with outbound calls. If you need it to use with internal calls as well,
you should use the macro-dialout-one-predial-hook (just copy my code with the desired macro name).

If it still does not work for you, I appreciate if you will share your logs with my code.

Thank you,

Daniel Friedman
Trixton LTD.

Daniel, those macros aren’t called unless the dialed number matches in the dialplan first. In the case with spaces and parentheses there is no match, so the call fails immediately.

@billsimon

The following all went to infinite recursive loops:

  1. (123) 123 1234
  2. 1234567890
  3. 123 123 1234

I don’t know enough about dialplans, but since the original one matched on a leading number/whitespace/paren, it kept rematching, since it matched the telephone number both before and after it was fixed.

What something had you wanted to do?
This merry rabbit hole started with me wanting to have a Zulu screenpop list open tickets for the incoming call.

See my reply to myself above… it should only match when there are spaces and parentheses, and not match after it converts it to all digits, because the pattern that includes the space and parentheses has a lower matching order. And those patterns work for me with my code, so I don’t understand why you’re looping.

The something I had wanted to do was have better handling of cases exactly like yours. I have an LDAP that returns spaces in phone numbers.

Hello @billsimon,

You are wrong about that. Those macros are being called no matter what, because they are being called from the dialling macros. If you need a special customization before dialling, then you need to use them. Read the macro-dialout-trunk macro and you will understand.

If for some reason then number is not being dialled internally, then it moves to the outbound dialling macros and then if there is a customization the custom macros are being called.

So, if my code is not working, please provide the logs @Seneschul .

Thank you,

Daniel Friedman
Trixton LTD.

Here are two examples. First I tried dialing “(814) 8654090” and then I tried “181 486 54090” after loading your macro. I don’t see it ever trying to call the predial-hook macro. Am I missing something else beside simply adding the macro to extensions_custom.conf and reloading the dialplan?

http://pastebin.freepbx.org/view/2fbbf84c

Hello @billsimon,

Your calls do not hit the dialling macro. Can you share your outbound routes screenshot?
What is your Freepbx version?

Thank you,

Daniel Friedman
Trixton LTD.

I do not have outbound routes that include spaces and parens… that was my point, it does not match at the front end so those macros don’t get used.

Hello @billsimon,

I understand now your point regarding the dialling rules. Sorry for that.

Try using a general outbound route like _X. for the white spaces and as for the parentheses you can use a prefix ( and + if the number starts with a “+” in the outbound routes. You need to adjust your outbound routes as per your dialling patterns or to use the from-internal-custom context like you did before.

I prefer to use the Freepbx GUI and my code because it is being called at the final stage before the actual dialling and filters out all the white spaces and dashes.

Thank you,

Daniel Friedman
Trixton LTD.

@Danielf
Ahh, that makes more sense.

I hate to say it, but I’m more partial to the multi-line segment I put in than to having a solution that bridges multiple areas of the PBX system, if at all avoidable.

I can’t experiment any more with the dialing plan until after hours, so I’ll have to wait to try anything new out.

Hello @Seneschul,

Well you know, that is the beauty of the open source world. Everyone have an opinion and all approaches are working. So go ahead and pick what suits you the most for your needs.

For me personally, I prefer the “bypassing” method of the custom contexts or macros to avoid messing with the Freepbx framework. After all it is a superb product that serves us all for many years.

Thank you,

Daniel Friedman
Trixton LTD.

Is there a reason those devices are sending digits in an improper format?

Phonebook maybe?

I don’t see why else this would end up being sent…

Have a nice day!

Nick