Illustration of Yeti character writing with a pencil.

Asterisk Dial Plan - Adding Prefixes to Dialed Numbers


We chose Voicepulse for our SIP Trunking and DID Provider. They provide you with some great starter configuration files to get you going, but their extensions.conf file left us needing to always dial 1 and area code for all numbers in order to call out. This is because their conf file only has call out rules to match when the full number has been dialed:

You can see the _1NXXNXXXXXX on each line will match when any number is dialed that starts with a 1 then is followed by 10 more digits.



exten => _1NXXNXXXXXX,1,Set(CALLERID(num)=14132565440)
exten => _1NXXNXXXXXX,2,Set(CALLERID(name)=LEFT-CLICK)
exten => _1NXXNXXXXXX,n,NoOp(SIPCALLID: ${SIPCALLID})
exten => _1NXXNXXXXXX,n,Dial(SIP/${EXTEN}@${VOICEPULSE_GATEWAY_OUT_A})
exten => _1NXXNXXXXXX,n,GotoIf($[${DIALSTATUS}=CHANUNAVAIL]?${EXTEN}|GatewayB)
exten => _1NXXNXXXXXX,n(GatewayB),Dial(SIP/${EXTEN}@${VOICEPULSE_GATEWAY_OUT_B})

This is not what people are used to. Sometimes it seems too much to always dial the 1. So I added this rule to match numbers dialed without the 1:

You can see that with this added set, the _NXXNXXXXXX will match 10 digit numbers without the 1 and proceed to call out. The trick here was to add a 1 before the variable ${EXTEN} where it appeared. This will tell Asterisk to add the 1 for you.



exten => _NXXNXXXXXX,1,Set(CALLERID(num)=14132565440)
exten => _NXXNXXXXXX,2,Set(CALLERID(name)=LEFT-CLICK)
exten => _NXXNXXXXXX,n,NoOp(SIPCALLID: ${SIPCALLID})
exten => _NXXNXXXXXX,n,Dial(SIP/1${EXTEN}@${VOICEPULSE_GATEWAY_OUT_A})
exten => _NXXNXXXXXX,n,GotoIf($[${DIALSTATUS}=CHANUNAVAIL]?1${EXTEN}|GatewayB)
exten => _NXXNXXXXXX,n(GatewayB),Dial(SIP/1${EXTEN}@${VOICEPULSE_GATEWAY_OUT_B}

One step further was to make it so people didn’t need to dial the area code when making “local” calls:

Much like the previous example, _NXXXXXX causes the match for 7 digit numbers and placing 1413 before every ${EXTEN} produces a proper call out.



exten => _NXXXXXX,1,Set(CALLERID(num)=14132565440)
exten => _NXXXXXX,2,Set(CALLERID(name)=LEFT-CLICK)
exten => _NXXXXXX,n,NoOp(SIPCALLID: ${SIPCALLID})
exten => _NXXXXXX,n,Dial(SIP/1413${EXTEN}@${VOICEPULSE_GATEWAY_OUT_A})
exten => _NXXXXXX,n,GotoIf($[${DIALSTATUS}=CHANUNAVAIL]?1413${EXTEN}|GatewayB)
exten => _NXXXXXX,n(GatewayB),Dial(SIP/1413${EXTEN}@${VOICEPULSE_GATEWAY_OUT_B})

comments powered by Disqus