Adding +45 prefix to dialed number

I’m a new Asterisk user. I have just installed and configured PBX in a Flash and everything is working, but there is one thing I just can’t seem to figure out. My SIP Trunk provider demands that all calls starts with + and the country code. This is fine in Eyebeam (x-lite) where I can insert + in front of the dialed number directly, but it’s not OK on my VoiP phones (Linksys SPA942), where there is no + sign to be found.

What I need is either to have a plus sign added in front of any numbers (i.e. +4512345678 when I dial 4512345678), or even better - have the system automatically add +45 in front of numbers containing 8 digits (NXXXXXXX) and just the + if the number contains 10 digits (NXXXXXXXXX). For instance:
12345678 is translated to: +4512345678
4612345678 is translated to: +4612345678

I have searched everywhere, but can’t find a good explanation on how to do this. I guess it should be done in extensions_custom.conf. I tried this one, but Asterisk still just send the 8 original digits to the trunk:
exten => _NXXXXXXX,n,Dial(${TRUNK}/+45${EXTEN})

I also tried this one, but it didn’t work either:
exten => _NXXXXXXX,n,Prefix(+45)

This little + sign is driving me nuts! :confused: I think I can add digits in front of a dialed number in the outgoing dial rules/dial patterns, but it seems that the + sign has a completely differnt meaning here, and therefore can’t be added.

[quote=“yakoronor”]I have searched everywhere, but can’t find a good explanation on how to do this. I guess it should be done in extensions_custom.conf. I tried this one, but Asterisk still just send the 8 original digits to the trunk:
exten => _NXXXXXXX,n,Dial(${TRUNK}/+45${EXTEN})
[/quote]

This one should work. Please supply verbose CLI traces for the call.

Hi!

It seems that it adds the prefix in the first line of the trace, so I may have put the rule in the wrong place. I don’t know what Zap/g2 is. It’s not my trunk name. Here is the output when I try to dial 44445555 (the real numbers and names have been replaced):

-- Executing [44445555@from-internal:1] Dial("SIP/22334455-0844b968", "Zap/g2/+4544445555") in new stack

== Everyone is busy/congested at this time (1:0/0/1)
– Executing [44445555@from-internal:2] SIPAddHeader(“SIP/22334455-0844b968”, “P-Asserted-Identity: “Agdernett” sip:t4544445500@mytrunk.dk”) in new stack
– Executing [44445555@from-internal:3] Macro(“SIP/22334455-0844b968”, “record-enable||OUT|”) in new stack
– Executing [s@macro-record-enable:1] GotoIf(“SIP/22334455-0844b968”, “1?check”) in new stack
– Goto (macro-record-enable,s,4)
– Executing [s@macro-record-enable:4] AGI(“SIP/22334455-0844b968”, “recordingcheck|20101102-150509|1288706709.8”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/recordingcheck
recordingcheck|20101102-150509|1288706709.8: No AMPUSER db entry for . Not recording
– AGI Script recordingcheck completed, returning 0
– Executing [s@macro-record-enable:5] MacroExit(“SIP/22334455-0844b968”, “”) in new stack
– Executing [44445555@from-internal:4] Macro(“SIP/22334455-0844b968”, “dialout-trunk|2|44445555||”) in new stack
– Executing [s@macro-dialout-trunk:1] Set(“SIP/22334455-0844b968”, “DIAL_TRUNK=2”) in new stack
– Executing [s@macro-dialout-trunk:2] GosubIf(“SIP/22334455-0844b968”, “0?sub-pincheck|s|1”) in new stack
– Executing [s@macro-dialout-trunk:3] GotoIf(“SIP/22334455-0844b968”, “0?disabletrunk|1”) in new stack
– Executing [s@macro-dialout-trunk:4] Set(“SIP/22334455-0844b968”, “DIAL_NUMBER=44445555”) in new stack
– Executing [s@macro-dialout-trunk:5] Set(“SIP/22334455-0844b968”, “DIAL_TRUNK_OPTIONS=tr”) in new stack
– Executing [s@macro-dialout-trunk:6] Set(“SIP/22334455-0844b968”, “OUTBOUND_GROUP=OUT_2”) in new stack
– Executing [s@macro-dialout-trunk:7] GotoIf(“SIP/22334455-0844b968”, “1?nomax”) in new stack
– Goto (macro-dialout-trunk,s,9)
– Executing [s@macro-dialout-trunk:9] GotoIf(“SIP/22334455-0844b968”, “0?skipoutcid”) in new stack
– Executing [s@macro-dialout-trunk:10] Set(“SIP/22334455-0844b968”, “DIAL_TRUNK_OPTIONS=”) in new stack
– Executing [s@macro-dialout-trunk:11] Macro(“SIP/22334455-0844b968”, “outbound-callerid|2”) in new stack
– Executing [s@macro-outbound-callerid:1] ExecIf(“SIP/22334455-0844b968”, “0|SetCallerPres|”) in new stack
– Executing [s@macro-outbound-callerid:2] ExecIf(“SIP/22334455-0844b968”, “1|Set|REALCALLERIDNUM=22334455”) in new stack
– Executing [s@macro-outbound-callerid:3] GotoIf(“SIP/22334455-0844b968”, “1?normcid”) in new stack
– Goto (macro-outbound-callerid,s,6)
– Executing [s@macro-outbound-callerid:6] Set(“SIP/22334455-0844b968”, “USEROUTCID=”) in new stack
– Executing [s@macro-outbound-callerid:7] Set(“SIP/22334455-0844b968”, “EMERGENCYCID=”) in new stack
– Executing [s@macro-outbound-callerid:8] Set(“SIP/22334455-0844b968”, “TRUNKOUTCID=”) in new stack
– Executing [s@macro-outbound-callerid:9] GotoIf(“SIP/22334455-0844b968”, “1?trunkcid”) in new stack
– Goto (macro-outbound-callerid,s,12)
– Executing [s@macro-outbound-callerid:12] ExecIf(“SIP/22334455-0844b968”, “0|Set|CALLERID(all)=”) in new stack
– Executing [s@macro-outbound-callerid:13] ExecIf(“SIP/22334455-0844b968”, “0|Set|CALLERID(all)=”) in new stack
– Executing [s@macro-outbound-callerid:14] ExecIf(“SIP/22334455-0844b968”, “0|SetCallerPres|prohib_passed_screen”) in new stack
– Executing [s@macro-dialout-trunk:12] ExecIf(“SIP/22334455-0844b968”, “1|AGI|fixlocalprefix”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/fixlocalprefix
> fixlocalprefix: Using pattern NXXXXXXX
== fixlocalprefix: Dialpattern NXXXXXXX matched. 44445555 -> 44445555
– AGI Script fixlocalprefix completed, returning 0
– Executing [s@macro-dialout-trunk:13] Set(“SIP/22334455-0844b968”, “OUTNUM=44445555”) in new stack
– Executing [s@macro-dialout-trunk:14] Set(“SIP/22334455-0844b968”, “custom=SIP/MYTRUNK”) in new stack
– Executing [s@macro-dialout-trunk:15] ExecIf(“SIP/22334455-0844b968”, “0|Set|DIAL_TRUNK_OPTIONS=M(setmusic^)”) in new stack
– Executing [s@macro-dialout-trunk:16] Macro(“SIP/22334455-0844b968”, “dialout-trunk-predial-hook|”) in new stack
– Executing [s@macro-dialout-trunk-predial-hook:1] MacroExit(“SIP/22334455-0844b968”, “”) in new stack
– Executing [s@macro-dialout-trunk:17] GotoIf(“SIP/22334455-0844b968”, “0?bypass|1”) in new stack
– Executing [s@macro-dialout-trunk:18] GotoIf(“SIP/22334455-0844b968”, “0?customtrunk”) in new stack
– Executing [s@macro-dialout-trunk:19] Dial(“SIP/22334455-0844b968”, “SIP/MYTRUNK/44445555|300|”) in new stack
– Called MYTRUNK/44445555
– SIP/MYTRUNK-083baef8 is ringing
– SIP/MYTRUNK-083baef8 answered SIP/22334455-0844b968
== Spawn extension (macro-dialout-trunk, s, 19) exited non-zero on ‘SIP/22334455-0844b968’ in macro ‘dialout-trunk’
== Spawn extension (macro-dialout-trunk, s, 19) exited non-zero on ‘SIP/22334455-0844b968’
– Executing [h@macro-dialout-trunk:1] Macro(“SIP/22334455-0844b968”, “hangupcall|”) in new stack
– Executing [s@macro-hangupcall:1] GotoIf(“SIP/22334455-0844b968”, “1?skiprg”) in new stack
– Goto (macro-hangupcall,s,4)
– Executing [s@macro-hangupcall:4] GotoIf(“SIP/22334455-0844b968”, “1?skipblkvm”) in new stack
– Goto (macro-hangupcall,s,7)
– Executing [s@macro-hangupcall:7] GotoIf(“SIP/22334455-0844b968”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,9)
– Executing [s@macro-hangupcall:9] Hangup(“SIP/22334455-0844b968”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 9) exited non-zero on ‘SIP/22334455-0844b968’ in macro ‘hangupcall’
== Spawn extension (macro-hangupcall, s, 9) exited non-zero on ‘SIP/22334455-0844b968’

Zap/g2 will be asterisk’s real name for your trunk. The trunk name you see will be an abstraction created by the GUI you are using.

I see… :smiley: But why does it add the +45 prefix to my dialed number (44445555) in the first line:
– Executing [44445555@from-internal:1] Dial(“SIP/22334455-0844b968”, “Zap/g2/+4544445555”) in new stack

…while when further down, the number is set back to what I originally dialed:
– Executing [s@macro-dialout-trunk:19] Dial(“SIP/22334455-0844b968”, “SIP/MYTRUNK/44445555|300|”) in new stack

My guess is that if I were able to replace the number in when it actually seems to tial MYTRUNK, then the call would work, no?

This is what it looks like when I do a successful call from Eyebeam (where I’m able to add the +45 manually):
– Executing [+4544445555@from-internal:1] Macro(“SIP/22334455-09ca9e18”, “user-callerid|SKIPTTL|”) in new stack
– Executing [s@macro-user-callerid:1] Set(“SIP/22334455-09ca9e18”, “AMPUSER=22334455”) in new stack
– Executing [s@macro-user-callerid:2] GotoIf(“SIP/22334455-09ca9e18”, “0?report”) in new stack
– Executing [s@macro-user-callerid:3] ExecIf(“SIP/22334455-09ca9e18”, “1|Set|REALCALLERIDNUM=22334455”) in new stack
– Executing [s@macro-user-callerid:4] Set(“SIP/22334455-09ca9e18”, “AMPUSER=22334455”) in new stack
– Executing [s@macro-user-callerid:5] Set(“SIP/22334455-09ca9e18”, “AMPUSERCIDNAME=eyeBeam”) in new stack
– Executing [s@macro-user-callerid:6] GotoIf(“SIP/22334455-09ca9e18”, “0?report”) in new stack
– Executing [s@macro-user-callerid:7] Set(“SIP/22334455-09ca9e18”, “AMPUSERCID=22334455”) in new stack
– Executing [s@macro-user-callerid:8] Set(“SIP/22334455-09ca9e18”, “CALLERID(all)=“eyeBeam” <22334455>”) in new stack
– Executing [s@macro-user-callerid:9] ExecIf(“SIP/22334455-09ca9e18”, “0|Set|CHANNEL(language)=”) in new stack
– Executing [s@macro-user-callerid:10] GotoIf(“SIP/22334455-09ca9e18”, “1?continue”) in new stack
– Goto (macro-user-callerid,s,19)
– Executing [s@macro-user-callerid:19] NoOp(“SIP/22334455-09ca9e18”, “Using CallerID “eyeBeam” <22334455>”) in new stack
– Executing [+4544445555@from-internal:2] SIPAddHeader(“SIP/22334455-09ca9e18”, “P-Asserted-Identity: “MyIdentity” sip:t4544445500@mytrunk.dk”) in new stack
– Executing [+4544445555@from-internal:3] Macro(“SIP/22334455-09ca9e18”, “record-enable|22334455|OUT|”) in new stack
– Executing [s@macro-record-enable:1] GotoIf(“SIP/22334455-09ca9e18”, “1?check”) in new stack
– Goto (macro-record-enable,s,4)
– Executing [s@macro-record-enable:4] AGI(“SIP/22334455-09ca9e18”, “recordingcheck|20101103-073311|1288765991.10”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/recordingcheck
recordingcheck|20101103-073311|1288765991.10: Outbound recording not enabled
– AGI Script recordingcheck completed, returning 0
– Executing [s@macro-record-enable:5] MacroExit(“SIP/22334455-09ca9e18”, “”) in new stack
– Executing [+4544445555@from-internal:4] Macro(“SIP/22334455-09ca9e18”, “dialout-trunk|2|+4544445555||”) in new stack
– Executing [s@macro-dialout-trunk:1] Set(“SIP/22334455-09ca9e18”, “DIAL_TRUNK=2”) in new stack
– Executing [s@macro-dialout-trunk:2] GosubIf(“SIP/22334455-09ca9e18”, “0?sub-pincheck|s|1”) in new stack
– Executing [s@macro-dialout-trunk:3] GotoIf(“SIP/22334455-09ca9e18”, “0?disabletrunk|1”) in new stack
– Executing [s@macro-dialout-trunk:4] Set(“SIP/22334455-09ca9e18”, “DIAL_NUMBER=+4544445555”) in new stack
– Executing [s@macro-dialout-trunk:5] Set(“SIP/22334455-09ca9e18”, “DIAL_TRUNK_OPTIONS=tr”) in new stack
– Executing [s@macro-dialout-trunk:6] Set(“SIP/22334455-09ca9e18”, “OUTBOUND_GROUP=OUT_2”) in new stack
– Executing [s@macro-dialout-trunk:7] GotoIf(“SIP/22334455-09ca9e18”, “1?nomax”) in new stack
– Goto (macro-dialout-trunk,s,9)
– Executing [s@macro-dialout-trunk:9] GotoIf(“SIP/22334455-09ca9e18”, “0?skipoutcid”) in new stack
– Executing [s@macro-dialout-trunk:10] Set(“SIP/22334455-09ca9e18”, “DIAL_TRUNK_OPTIONS=”) in new stack
– Executing [s@macro-dialout-trunk:11] Macro(“SIP/22334455-09ca9e18”, “outbound-callerid|2”) in new stack
– Executing [s@macro-outbound-callerid:1] ExecIf(“SIP/22334455-09ca9e18”, “0|SetCallerPres|”) in new stack
– Executing [s@macro-outbound-callerid:2] ExecIf(“SIP/22334455-09ca9e18”, “0|Set|REALCALLERIDNUM=22334455”) in new stack
– Executing [s@macro-outbound-callerid:3] GotoIf(“SIP/22334455-09ca9e18”, “1?normcid”) in new stack
– Goto (macro-outbound-callerid,s,6)
– Executing [s@macro-outbound-callerid:6] Set(“SIP/22334455-09ca9e18”, “USEROUTCID=“EyeBeam” <+4522334455>”) in new stack
– Executing [s@macro-outbound-callerid:7] Set(“SIP/22334455-09ca9e18”, “EMERGENCYCID=”) in new stack
– Executing [s@macro-outbound-callerid:8] Set(“SIP/22334455-09ca9e18”, “TRUNKOUTCID=”) in new stack
– Executing [s@macro-outbound-callerid:9] GotoIf(“SIP/22334455-09ca9e18”, “1?trunkcid”) in new stack
– Goto (macro-outbound-callerid,s,12)
– Executing [s@macro-outbound-callerid:12] ExecIf(“SIP/22334455-09ca9e18”, “0|Set|CALLERID(all)=”) in new stack
– Executing [s@macro-outbound-callerid:13] ExecIf(“SIP/22334455-09ca9e18”, “1|Set|CALLERID(all)=EyeBeam <+4522334455>”) in new stack
– Executing [s@macro-outbound-callerid:14] ExecIf(“SIP/22334455-09ca9e18”, “0|SetCallerPres|prohib_passed_screen”) in new stack
– Executing [s@macro-dialout-trunk:12] ExecIf(“SIP/22334455-09ca9e18”, “0|AGI|fixlocalprefix”) in new stack
– Executing [s@macro-dialout-trunk:13] Set(“SIP/22334455-09ca9e18”, “OUTNUM=+4544445555”) in new stack
– Executing [s@macro-dialout-trunk:14] Set(“SIP/22334455-09ca9e18”, “custom=SIP/MYTRUNK”) in new stack
– Executing [s@macro-dialout-trunk:15] ExecIf(“SIP/22334455-09ca9e18”, “0|Set|DIAL_TRUNK_OPTIONS=M(setmusic^)”) in new stack
– Executing [s@macro-dialout-trunk:16] Macro(“SIP/22334455-09ca9e18”, “dialout-trunk-predial-hook|”) in new stack
– Executing [s@macro-dialout-trunk-predial-hook:1] MacroExit(“SIP/22334455-09ca9e18”, “”) in new stack
– Executing [s@macro-dialout-trunk:17] GotoIf(“SIP/22334455-09ca9e18”, “0?bypass|1”) in new stack
– Executing [s@macro-dialout-trunk:18] GotoIf(“SIP/22334455-09ca9e18”, “0?customtrunk”) in new stack
– Executing [s@macro-dialout-trunk:19] Dial(“SIP/22334455-09ca9e18”, “SIP/MYTRUNK/+4544445555|300|”) in new stack
– Called MYTRUNK/+4544445555
– SIP/MYTRUNK-09caf320 is making progress passing it to SIP/22334455-09ca9e18
– SIP/MYTRUNK-09caf320 is making progress passing it to SIP/22334455-09ca9e18
– SIP/MYTRUNK-09caf320 is making progress passing it to SIP/22334455-09ca9e18
– SIP/MYTRUNK-09caf320 answered SIP/22334455-09ca9e18

I’ve put the exten => _NXXXXXXX,n,Dial(${TRUNK}/+45${EXTEN}) in extensions_custom.conf in the context I’m loading in my trunk. I’ve also tried adding it before and after the context with the same results.

Any help is greatly appreciated!

Because you only changed the Dial in top level Dial application call, not the one in the macro.

Unfortunately you are in an awkward cross-over area, in that you are trying to attack a perceived limitation of a GUI interface by using Asterisk directly. Doing that requires some detailed knowledge of the dialplan skeleton used by the GUI. That might exist on the AsteriskNow forum. Someone here may have knowledge of AsteriskNow internals, but otherwise the job requires a non-trivial amount of time, that may be more easily available on a paid basis.

Of course, this might be a standard issue for AsteriskNow, for which it provides a mechanism. You would be best asking on the AsteriskNow forum for that.

Try this one:
Make a Perl script:

#!/usr/bin/perl
use Asterisk::AGI;
my $num = $ARGV[0];
my $digits; my $plus = “+”
$AGI = new Asterisk::AGI;
$digits=length($num);
if ( $digits = 8 ) {$AGI->set_variable(‘new_number’,"$plus45$num")};
if ( $digits = 10 ) {$AGI->set_variable(‘new_number’,"$plus$num")};

Put the scrip somewhere you want and give it permission.
Before to use this script you must install “asterisk-perl” module: asterisk.gnuinter.net/files/aste … .01.tar.gz

in extensions.conf

exten => _N.,1,AGI(/path/to/script/your_script.agi,${EXTEN})
exten => _N.,2,Dial(${TRUNK}/${new_number})

I think you need to challenge your SIP provider why a “+” is required. Thats not a valid digit to be prefixing for handoff to different providers. Its a convenience feature often seen on cellphones that simply figures out whether to translate the + to 011 or 001 for international. Follow standard NANP and INTL rules for digit dialing and you should be fine or switch provider!

“+” is not the problem. The problem is adding any prefix when using a GUI.

I am not a big fan with with any of the GUI because they simply limit you a lot and that may work for a majority of small installations, but the moment you need any customizations, learning how the GUI adds onto the DIALPLAN is more complex then just learning how to work directly with the dialplan in extensions.conf in the first place. Anywhow that’s my 02 cents rambling which won’t help you.

I like to know the name of this SIP provider. I understand adding a “+” is not a problem. With SIP, you can send pretty much any characters but thats not the point. You shouldn’t have to.