Add prefix in outgoing calls in Asterisk

Hi,

We have a many services in our company, each one must display a
different number in his outgoing calls. We use a Asterisk SIP server.

Our SIP provider asks us to make our Asterisk server send a prefix before the outgoing number.

for exemple, for a normal call from the extension 1200, the SIP server send the number 0033123456789.

we want to make it adding a prefix for calls from each extension.
For exemple :
Add 401 before for calls from 1200 and send 40133123456789.
Add 402 before for calls from 1201 and send 40233123456789.
…Etc

Can you help please ?

Many thanks.

Use this

exten => 3312./1200,1,Dial(SIP/myprovider/401${EXTEN})
exten => 3312./1201,1,Dial(SIP/myprovider/402${EXTEN})

Hello,

Thank you for the reply.

In which section I must to put this lines in the extensions.conf file please ?

Cordially.

We can’t answer that without the complete contents or your extensions.conf, and its inclusions, and an outline of how it is supposed to work

You should ask the people who wrote the dial plan. (For DIY dialplans it should be obvious; for GUI generated ones, you should obtain support from the maintainers of the GUI.)

Ok, do you want that I send you the file or only that I put the code here ?

Cordially.

Any code needs to be put here so that multiple eyes can look at it.

Ok here it is, I’ve deleted the commented lines to reduce the file.
Many thanks :

static=yes

writeprotect=no

clearglobalvars=no

[globals]
CONSOLE=Console/dsp                             ; Console interface for demo

IAXINFO=guest                                   ; IAXtel username/password

TRUNK=Zap/G2                                    ; Trunk interface

TRUNKMSD=1                                      ; MSD digits to strip (usually 1 or 0)

[dundi-e164-canonical]


[dundi-e164-customers]


[dundi-e164-via-pstn]


[dundi-e164-local]

include => dundi-e164-canonical
include => dundi-e164-customers
include => dundi-e164-via-pstn

[dundi-e164-switch]

switch => DUNDi/e164

[dundi-e164-lookup]

include => dundi-e164-local
include => dundi-e164-switch

[macro-dundi-e164]

exten => s,1,Goto(${ARG1},1)
include => dundi-e164-lookup


[iaxtel700]
exten => _91700XXXXXXX,1,Dial(IAX2/${GLOBAL(IAXINFO)}@iaxtel.com/${EXTEN:1}@iaxtel)


[iaxprovider]

[trunkint]

exten => _9011.,1,Macro(dundi-e164,${EXTEN:4})
exten => _9011.,n,Dial(${GLOBAL(TRUNK)}/${EXTEN:${GLOBAL(TRUNKMSD)}})

[trunkld]

exten => _91NXXNXXXXXX,1,Macro(dundi-e164,${EXTEN:1})
exten => _91NXXNXXXXXX,n,Dial(${GLOBAL(TRUNK)}/${EXTEN:${GLOBAL(TRUNKMSD)}})

[trunklocal]

exten => _9NXXXXXX,1,Dial(${GLOBAL(TRUNK)}/${EXTEN:${GLOBAL(TRUNKMSD)}})

[trunktollfree]

exten => _91800NXXXXXX,1,Dial(${GLOBAL(TRUNK)}/${EXTEN:${GLOBAL(TRUNKMSD)}})
exten => _91888NXXXXXX,1,Dial(${GLOBAL(TRUNK)}/${EXTEN:${GLOBAL(TRUNKMSD)}})
exten => _91877NXXXXXX,1,Dial(${GLOBAL(TRUNK)}/${EXTEN:${GLOBAL(TRUNKMSD)}})
exten => _91866NXXXXXX,1,Dial(${GLOBAL(TRUNK)}/${EXTEN:${GLOBAL(TRUNKMSD)}})

[international]

ignorepat => 9
include => longdistance
include => trunkint

[longdistance]

ignorepat => 9
include => local
include => trunkld

[local]

ignorepat => 9
include => default
include => trunklocal
include => iaxtel700
include => trunktollfree
include => iaxprovider


include => parkedcalls

[macro-trunkdial]

exten => s,1,Dial(${ARG1})
exten => s,n,Goto(s-${DIALSTATUS},1)
exten => s-NOANSWER,1,Hangup
exten => s-BUSY,1,Hangup
exten => _s-.,1,NoOp

[macro-stdexten];

exten => s,1,Dial(${ARG2},20)                   ; Ring the interface, 20 seconds maximum
exten => s,2,Goto(s-${DIALSTATUS},1)            ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)

exten => s-NOANSWER,1,Voicemail(${ARG1},u)      ; If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1)         ; If they press #, return to start

exten => s-BUSY,1,Voicemail(${ARG1},b)          ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1)             ; If they press #, return to start

exten => _s-.,1,Goto(s-NOANSWER,1)              ; Treat anything else as no answer

exten => a,1,VoicemailMain(${ARG1})             ; If they press *, send the user into VoicemailMain

[macro-stdPrivacyexten];

exten => s,1,Dial(${ARG2},20|p)                 ; Ring the interface, 20 seconds maximum, call screening
                                                ; option (or use P for databased call screening)
exten => s,2,Goto(s-${DIALSTATUS},1)            ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)

exten => s-NOANSWER,1,Voicemail(${ARG1},u)      ; If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1)         ; If they press #, return to start

exten => s-BUSY,1,Voicemail(${ARG1},b)          ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1)             ; If they press #, return to start

exten => s-DONTCALL,1,Goto(${ARG3},s,1)         ; Callee chose to send this call to a polite "Don't call again" script.

exten => s-TORTURE,1,Goto(${ARG4},s,1)          ; Callee chose to send this call to a telemarketer torture script.

exten => _s-.,1,Goto(s-NOANSWER,1)              ; Treat anything else as no answer

exten => a,1,VoicemailMain(${ARG1})             ; If they press *, send the user into VoicemailMain

[macro-page];

exten => s,1,ChanIsAvail(${ARG1}|js)                    ; j is for Jump and s is for ANY call
exten => s,n,GoToIf([${AVAILSTATUS} = "1"]?autoanswer:fail)
exten => s,n(autoanswer),Set(_ALERT_INFO="RA")                  ; This is for the PolyComs
exten => s,n,SIPAddHeader(Call-Info: Answer-After=0)    ; This is for the Grandstream, Snoms, and Others
exten => s,n,NoOp()                                     ; Add others here and Post on the Wiki!!!!
exten => s,n,Dial(${ARG1}||)
exten => s,n(fail),Hangup


[demo]

exten => s,1,Wait(1)                    ; Wait a second, just for fun
exten => s,n,Answer                     ; Answer the line
exten => s,n,Set(TIMEOUT(digit)=5)      ; Set Digit Timeout to 5 seconds
exten => s,n,Set(TIMEOUT(response)=10)  ; Set Response Timeout to 10 seconds
exten => s,n(restart),BackGround(demo-congrats) ; Play a congratulatory message
exten => s,n(instruct),BackGround(demo-instruct)        ; Play some instructions
exten => s,n,WaitExten                  ; Wait for an extension to be dialed.

exten => 2,1,BackGround(demo-moreinfo)  ; Give some more information.
exten => 2,n,Goto(s,instruct)

exten => 3,1,Set(LANGUAGE()=fr)         ; Set language to french
exten => 3,n,Goto(s,restart)            ; Start with the congratulations

exten => 1000,1,Goto(default,s,1)

exten => 1234,1,Playback(transfer,skip)         ; "Please hold while..."
                                        ; (but skip if channel is not up)
exten => 1234,n,Macro(stdexten,1234,${GLOBAL(CONSOLE)})

exten => 1235,1,Voicemail(1234,u)               ; Right to voicemail

exten => 1236,1,Dial(Console/dsp)               ; Ring forever
exten => 1236,n,Voicemail(1234,b)               ; Unless busy

exten => #,1,Playback(demo-thanks)      ; "Thanks for trying the demo"
exten => #,n,Hangup                     ; Hang them up.


exten => t,1,Goto(#,1)                  ; If they take too long, give up
exten => i,1,Playback(invalid)          ; "That's not valid, try again"

exten => 500,1,Playback(demo-abouttotry); Let them know what's going on
exten => 500,n,Dial(IAX2/guest@pbx.digium.com/s@default)        ; Call the Asterisk demo
exten => 500,n,Playback(demo-nogo)      ; Couldn't connect to the demo site
exten => 500,n,Goto(s,6)                ; Return to the start over message.

exten => 600,1,Playback(demo-echotest)  ; Let them know what's going on
exten => 600,n,Echo                     ; Do the echo test
exten => 600,n,Playback(demo-echodone)  ; Let them know it's over
exten => 600,n,Goto(s,6)                ; Start over

exten => 76245,1,Macro(page,SIP/Grandstream1)

exten => _7XXX,1,Macro(page,SIP/${EXTEN})

exten => 7999,1,Set(TIMEOUT(absolute)=60)
exten => 7999,2,Page(Local/Grandstream1@page&Local/Xlite1@page&Local/1234@page/n|d)


exten => 8500,1,VoicemailMain
exten => 8500,n,Goto(s,6)

[page]
exten => _X.,1,Macro(page,SIP/${EXTEN})


[default]
exten => _2.,1,Dial(H323/${EXTEN}@avaya,20); Avaya
exten => 6000,1,Dial(SIP/6000)
exten => _0033.,1,Dial(SIP/mani/${EXTEN},20,tTm)
exten => _0033.,2,Hangup


;Routing Incoming Calls

exten => _33112345670,1,Dial(H323/3502@avaya,20)
exten => _33112345670,2,Hangup

exten => _33112345671,1,Dial(H323/2168@avaya,20)
exten => _33112345671,2,Hangup


exten => _33112345672,1,Dial(H323/2121@avaya,20)
exten => _33112345672,2,Hangup

;End of Routing

include => demo


exten => _33176430364,2,Hangup

Which context your extensions use? Try to put it there.

It looks like he may be referring to the route to the Avaya, which is H.323, rather than SIP. However he didn’t answer the bit about what the dialplan was intended to do.

Hi,

Sorry for the delay, I was out of office.
David is right, our Asterisk server is referring to the route to the Avaya.
I’m not so good in asterisk, so sorry if I can’t answer all your questions.

Cordially.

You are not currently sending the 33123456789 to the Avaya, only a four digit number. You have used pattern match syntax for an exact match, so gain nothing by using it.

Given the first point, I’m still confused as to what the you are trying to do and I think you still need to describe what the system is trying to do.

If the Avaya route really gives access to outgoing lines, you would not normally want it in the default context as the default context is normally accessible to external callers.

Hi,
I explain my need.
I’ve buyed two DDI from my SIP provider, I told him that we have two differents services and we want that each service display his own DDI on outgoing calls.
For that they affected a prefix for each DDI, so every calls must be routed towards them presided by one of those prefix to let them know who is calling and what DDI to display.

I think that Avaya sends all digits, here is the Avaya’s trace for my station during a call :

>                                  LIST TRACE
> time            data
> 10:09:17 TRACE STARTED 06/03/2016 CM Release String cold-03.0.124.0-21460
> 10:09:19     active station      2122 cid 0x148e
> 10:09:19     G711A ss:off ps:20
>              rgn:1 [192.168.9.28]:2912
>              rgn:1 [192.168.9.11]:2118
> 10:09:19     dial 940233184887120 route:ARS
> 10:09:19     term trunk-group 100      cid 0x148e
> 10:09:19     dial 940233184887120 route:ARS
> 10:09:19     route-pattern  100 preference 1 location 1/ALL  cid 0x148e
> 10:09:19     seize trunk-group 100 member 2    cid 0x148e
> 10:09:19     Calling Number & Name NO-CPNumber NO-CPName
> 10:09:19     Setup digits 40233184887120
> 10:09:19     Calling Number & Name NO-CPNumber Rachid ELASSA
> 10:09:19     Proceed trunk-group 100 member 2    cid 0x148e
> 10:09:20     active trunk-group 100 member 2    cid 0x148e 

And here is the Asterix Log in same moment :

Connected to Asterisk 10.4.0 currently running on h323gw (pid = 2373)
Verbosity is at least 3
    -- Executing [s@default:1] Wait("H323/ip$192.168.9.12:10186/32613", "1") in new stack
    -- Executing [s@default:2] Answer("H323/ip$192.168.9.12:10186/32613", "") in new stack
[Jun  3 10:44:38] NOTICE[2451]: chan_h323.c:804 oh323_rtp_read: Inband DTMF is not supported on codec alaw. Use RFC2833
    -- Executing [s@default:3] Set("H323/ip$192.168.9.12:10186/32613", "TIMEOUT(digit)=5") in new stack
    -- Digit timeout set to 5.000
    -- Executing [s@default:4] Set("H323/ip$192.168.9.12:10186/32613", "TIMEOUT(response)=10") in new stack
    -- Response timeout set to 10.000
    -- Executing [s@default:5] BackGround("H323/ip$192.168.9.12:10186/32613", "demo-congrats") in new stack
    -- <H323/ip$192.168.9.12:10186/32613> Playing 'demo-congrats.alaw' (language 'en')
[Jun  3 10:44:51] WARNING[2391]: chan_sip.c:3663 retrans_pkt: Retransmission timeout reached on transmission f9eb9d0751f098b64fcc514850a31c25 for seqno 1 (Critical Response) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions
Packet timed out after 32000ms with no response
  == Spawn extension (default, s, 5) exited non-zero on 'H323/ip$192.168.9.12:10186/32613'

After, the call does not succeed and I hear a welcome message from the Asterisk server “demo-congrats.alaw”

Calls whitout 401 or 401 work.

Regards.

Do you also get a message about 940… not being found in context ???

If you don’t, the Avaya isn’t forwarding any digits. If you do, it is because you have no extension pattern that matches that number.

Why do you have the demonstration context included in your default context. It is the presence of that context that is resulting in the message you are getting played. The call would otherwise simply be rejected as an unknown number.

I’m also confused because the 401 seems to be incoming whereas you were originally asking to add it to outgoing calls.

In your default context, right before the include of demo context put these lines

exten => 3318./2122,1,Dial(SIP/myprovider/401${EXTEN})
exten => 3318./2123,1,Dial(SIP/myprovider/402${EXTEN})
exten => 3318,1,Noop(${CALLERID(number)})

Try again without dialing from the Avaya with 401 or 402 in your dial string, post here what asterisk cli shows.

Okay , I’ll try this on Monday and I’ll let you know .

thank you and have a good weekend.

Regars.

It’s not working,

I will assign the outgoing number to the switchboard operator and I will ask her to route the incoming calls to the right service, it’ll be more easy.

I thank you all for your time and your help.

Have a nice week.

Hello Everybody;
I solved my problem and I want to share the solution with you in case somebody have the same problem :
In my fileextensions.conf I had only :

> exten => _0033.,1,Dial(SIP/mani/${EXTEN})
> exten => _0033.,2,Hangup

So, only numbers which start with 0033 can be called, thus I added the
lines below to allow numbers which begin with 4 to be called:

exten => _4.,1,Dial(SIP/mani/${EXTEN})
exten => _4.,2,Hangup

hoping that will help.

Regards.