How to strip or replace the + character at the beginning of a called number
Every now and then you run into a situation where a particular phone will try to call numbers with a + (plus sign) character at the start of the phone number. This can occur if you have such numbers in the phone's "phonebook", or if you receive a call that had a + at the start of the Caller ID number, and you then use the phone's callback feature. This plays havoc with FreePBX - you can't match the + in a Dial Rule because the plus sign has a special meaning there. So, how do you get rid of the + and (optionally) replace it with something more meaningful, like your international dialing code? Here's one way to do it:
Step 1: Add a context to /etc/asterisk/extensions_custom.conf
[custom-strip-plus]
exten => _+X!,1,Noop(Stripping + from start of number)
exten => _+X!,n,Goto(from-internal,${EXTEN:1},1)
exten => _[*0-9]!,1,Goto(from-internal,${EXTEN},1)
exten => h,1,Hangup()
The line with the Noop is just a comment, so you can change the text between the parenthesis to anything meaningful to you - it's there so if you are watching call progress in the CLI, you can see when the + is being stripped. The next line after the Noop is where the action is - as shown, it simply strips the +. If you want it to replace the + with any digits (such as "011" or "00"), simply insert those digits immediately before ${EXTEN:1} (between the comma and the $). So if your international dialing code is "00", you might do this:
exten => _+X!,n,Goto(from-internal,00${EXTEN:1},1)
Step 2: Go the FreePBX page of all affected extensions and change the context from from-internal to custom-strip-plus - I know it's a pain to have to change the context manually if you have several extensions, but until some other solution is devised, it's the only way I know to make this work.
Step 3 (optional): In your outgoing trunk(s), strip any added international dialing code on calls within your own country - if you added an international dialing code in step 1, you probably don't want it sent on calls within your own country. The solution to that is to add a line in your trunk dial rules that looks for the international dialing code you added followed by your country code, and replaces that with your in-country dialing code (if any). For example, if your country code is 385, and for in-country calls you dial 0+ the number, you might do this (changes 00385 to just 0):
0+00385|.
Or in the U.S. and Canada, if you used 011 for the international dialing code, you might do this to replace the 0111 with just 1:
1+0111|.
Credit: The above was developed in response to a question on the Elastix Forum. Thanks to "protenus" for asking the initial question and then providing meaningful feedback!
- Printer-friendly version
- Login or register to post comments


