How to route to different extensions - asterisk

I am new to asterisk and I would like to do a simple routing job
I have configured asterisk to have 3 sip ddi numbers
Below sip.conf:
[0001]
type=peer
fromuser=4420XXXX0001
host=X.X.X.X
dtmfmode=rfc2833
canreinvite=no
insecure=invite
context=default
[0002]
type=peer
fromuser=4420XXXX0002
host=X.X.X.X
dtmfmode=rfc2833
canreinvite=no
insecure=invite
context=default
[0003]
type=peer
fromuser=4420XXXX0003
host=X.X.X.X
dtmfmode=rfc2833
canreinvite=no
insecure=invite
context=default
At the moment if I make a call I always use the first DDI 4420XXXX0001 which is the first extension number
Below extensions.conf
[default]
;Outgoing Number 0001
exten => _44.,1,Noop(CALLERID:${CALLERID})
exten => _44.,n,Set(CALLERID(all)="My Name"<+4420XXXX0001>)
exten => _44.,n,Dial(SIP/+${EXTEN:2}#0001)
exten => _44.,n,Hangup
;Outgoing Number 0002
exten => _44.,1,Noop(CALLERID:${CALLERID})
exten => _44.,n,Set(CALLERID(all)="My Name"<+4420XXXX0002>)
exten => _44.,n,Dial(SIP/+${EXTEN:2}#0002)
exten => _44.,n,Hangup
;Outgoing Number 0003
exten => _44.,1,Noop(CALLERID:${CALLERID})
exten => _44.,n,Set(CALLERID(all)="My Name"<+4420XXXX0003>)
exten => _44.,n,Dial(SIP/+${EXTEN:2}#0003)
exten => _44.,n,Hangup
How can I route this out in order to use different lines and different caller ids
I apologise for the naming conventions I find difficult to explain this
Thanks

Please read any asterisk book. This one topic at start of book, really
There are alot of posible variant how to balance trunks. For example this one is random balancing of 3 trunks.
[gate];начальный контекст
exten => _7XXXXXXXXXX,1,Set(num=${EXTEN})
exten => _7XXXXXXXXXX,2,Goto(gate_variants,${RAND(1,6)},1)
[gate_variants];все допустимые варианты
exten => 1,1,Set(DO=1-2-3)
exten => 2,1,Set(DO=1-3-2)
exten => 3,1,Set(DO=2-1-3)
exten => 4,1,Set(DO=2-3-1)
exten => 5,1,Set(DO=3-1-2)
exten => 6,1,Set(DO=3-2-1)
exten => _[1-6],2,goto(s,1)
exten => s,1,Set(i=0); делаем цикл(я это не писал, это у меня стандартная заготовка ;) )
exten => s,n(loop),Set(i=$[ i + 1]) ; смотрим по номеру
exten => s,n,Set(do_now=${CUT(DO,-,${i}) ; берем и-тый номер.
exten => s,n,GotoIF($[ "${do_now}" == "" ]?end); номера кончилися ((
exten => s,n,Dial(IAX2/manager${do_now}/${num},,g) ; звоним
exten => s,n,Goto({DIALSTATUS},1); проверяем результат
exten => s,n(end),Hangup; больше нет номеров
exten => BUSY,1,Goto(s,loop); повторяем
exten => CONGESTION,1,Goto(s,loop)
exten => FAIL,1,Goto(s,loop)
exten => NOANSWER,1,Goto(s,loop)
exten => ANSWER,1,Hangup;это не повторям, вроде дозвонилися.
exten => ANSWERED,1,Hangup
http://asterisk-support.ru/question/13916/dialplan-balansirovka-i-tsikl-mezhdu-trankami/#19951

Related

Asterisk GoSub() function not working for me

I am trying to make calls between extensions 101 and 102 and is NOT going through. I have the following extensions.conf file
[general]
autofallthrough=no
priorityjumping=yes
static=yes
writeprotect=no
clearglobalvars=yes
[default]
exten => .,1,Hangup()
[inbound-schedule]
; #_#_# Phone Number #_#_#
exten => 7867086699,1,Answer
exten => 7867086699,n,NoOp(Office-ANI-${EXTEN})
exten => 7867086699,n,Set(CDR(userfield)=ib_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)})
exten => 7867086699,n,MixMonitor(ib_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)}.wav)
exten => 7867086699,n,Goto(schedule,${EXTEN},1)
exten => .,1,Hangup()
[schedule]
exten => _NXXNXXXXXX,1,NoOp(Time-of-Day-Routing)
exten => _NXXNXXXXXX,n,GotoIfTime(8:58-17:02,mon-fri,*,*?inbound,${EXTEN},1)
exten => _NXXNXXXXXX,n,Goto(inbound-closed,${EXTEN},1)
[inbound]
exten => _NXXNXXXXXX,1,NoOp(Office-Open)
exten => _NXXNXXXXXX,n,Set(NUMINVALID=1)
exten => _NXXNXXXXXX,n,Set(TIMEOUT(digit)=3) ; max wait in-between digits seconds
exten => _NXXNXXXXXX,n,Set(TIMEOUT(response)=3) ; max wait for digit entry seconds
exten => _NXXNXXXXXX,n,Ringing
exten => _NXXNXXXXXX,n(menu),Wait(1)
exten => _NXXNXXXXXX,n,Background(custom/open-recording)
exten => _NXXNXXXXXX,n,Wait(3)
exten => _NXXNXXXXXX,n,Background(custom/open-recording)
exten => _NXXNXXXXXX,n,Wait(3)
exten => _NXXNXXXXXX,n,Dial(SIP/101,18)
exten => _NXXNXXXXXX,n,Voicemail(100#default,su)
exten => 0,1,NoOp(Office-Open-Press-Zero)
exten => 0,n,Voicemail(100#default,su)
exten => 2,1,NoOp(Operator-Directory)
exten => 2,n,Directory(default,vm-operator,f)
exten => 200,1,NoOp(External-Voicemail-Dial-From-${CALLERID(num)})
exten => 200,n,Playback(vm-dialout)
exten => 200,n,Wait(1)
exten => 200,n,VoiceMailMain()
exten => _1XX,1,Macro(local-followme,${EXTEN})
exten => t,1,Playback(option-is-invalid)
exten => t,n,Hangup()
exten => i,1,Set(NUMINVALID=$[${NUMINVALID}+1]})
exten => i,n,Playback(option-is-invalid)
exten => i,n,Gotoif($["${NUMINVALID}" < "4"]?:10)
exten => i,n,Goto(_NXXNXXXXXX,menu)
exten => i,10,Playback(vm-goodbye)
exten => i,n,Hangup()
[inbound-closed]
exten => _NXXNXXXXXX,1,NoOp(Office-Closed)
exten => _NXXNXXXXXX,n,Set(NUMINVALID=1)
exten => _NXXNXXXXXX,n,Set(TIMEOUT(digit)=3)
exten => _NXXNXXXXXX,n,Set(TIMEOUT(response)=3)
exten => _NXXNXXXXXX,n,Ringing
exten => _NXXNXXXXXX,n(menu),Wait(1)
exten => _NXXNXXXXXX,n,Background(custom/closed-recording)
exten => _NXXNXXXXXX,n,Wait(3)
exten => _NXXNXXXXXX,n,Background(custom/closed-recording)
exten => _NXXNXXXXXX,n,Wait(3)
exten => _NXXNXXXXXX,n,Dial(SIP/101,18)
exten => _NXXNXXXXXX,n,Voicemail(100#default,su)
exten => 0,1,NoOp(Office-Open-Press-Zero)
exten => 0,n,Voicemail(100#default,su)
exten => 2,1,NoOp(Operator-Directory)
exten => 2,n,Directory(default,vm-operator,f)
exten => 200,1,NoOp(External-Voicemail-Dial-From-${CALLERID(num)})
exten => 200,n,Playback(vm-dialout)
exten => 200,n,Wait(1)
exten => 200,n,VoiceMailMain()
exten => _1XX,1,Macro(local-followme,${EXTEN})
exten => t,1,Playback(option-is-invalid)
exten => t,n,Hangup()
exten => i,1,Set(NUMINVALID=$[${NUMINVALID}+1]})
exten => i,n,Playback(option-is-invalid)
exten => i,n,Gotoif($["${NUMINVALID}" < "4"]?:10)
exten => i,n,Goto(_NXXNXXXXXX,menu)
exten => i,10,Playback(vm-goodbye)
exten => i,n,Hangup()
[outbound]
exten => _NXXNXXXXXX,1,Dial(SIP/${EXTEN}#voip-outbound,120,trwW)
exten => _NXXNXXXXXX,n,Hangup()
exten => .,1,Playback(invalid)
exten => .,n,Hangup()
[internal]
; #_#_#_#_#_#_#_#_# INTERNAL MAIN CONTEXT #_#_#_#_#_#_#_#_#_#
; Extension to Extension Dialing
exten => _1XX,1,Macro(local-followme,${EXTEN})
; Call Pickup
exten => _*971XX,1,SET(GLOBAL(PICKUPMARK)=${EXTEN:2})
exten => _*971XX,n,Pickup(${EXTEN:2}#PICKUPMARK)
; Voicemail Access
exten => 1000,1,VoiceMailMain(${CALLERID(num)}#default)
exten => 2000,1,VoiceMailMain()
; Outbound Dialing
exten => _NXXXXXX,1,Answer
exten => _NXXXXXX,n,Set(CDR(userfield)=ib_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)})
exten => _NXXXXXX,n,MixMonitor(ob_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)}.wav)
exten => _NXXXXXX,n,Set(CALLERID(num)=7867086699)
exten => _NXXXXXX,n,Goto(outbound,310${EXTEN},1)
exten => _NXXNXXXXXX,1,Answer
exten => _NXXNXXXXXX,n,Set(CDR(userfield)=ib_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)})
exten => _NXXNXXXXXX,n,MixMonitor(ob_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)}.wav)
exten => _NXXNXXXXXX,n,Set(CALLERID(num)=7867086699)
exten => _NXXNXXXXXX,n,Goto(outbound,${EXTEN},1)
exten => _1NXXNXXXXXX,1,Answer
exten => _1NXXNXXXXXX,n,Set(CDR(userfield)=ib_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)})
exten => _1NXXNXXXXXX,n,MixMonitor(ob_${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}_${EXTEN}_${CALLERID(num)}.wav)
exten => _1NXXNXXXXXX,n,Set(CALLERID(num)=7867086699)
exten => _1NXXNXXXXXX,n,Goto(outbound,${EXTEN:1},1)
exten => t,1,Playback(invalid)
exten => t,n,Hangup()
exten => i,1,Playback(invalid)
exten => i,n,Hangup()
exten => .,1,Playback(invalid)
exten => .,n,Hangup()
[macro-local-followme]
exten => s,1,GotoIf($[${DB_EXISTS(followme/${ARG1})}=0]?nofollow)
exten => s,n,GotoIf($[${DB_RESULT:0:1}=0]?nofollow:follow)
exten => s,n(follow),Dial(SIP/${ARG1},20)
exten => s,n,Followme(${ARG1},n) ; Removed sa so no name recording
exten => s,n,Goto(s-${DIALSTATUS},1)
exten => s,n(nofollow),Dial(SIP/${ARG1},20)
exten => s,n,Goto(s-${DIALSTATUS},1)
exten => s-NOANSWER,1,Voicemail(${ARG1},u) ; If unavailable, send to voicemail
exten => s-BUSY,1,Voicemail(${ARG1},u) ; I changed b to u. If busy, send to voicemail w/ busy ann
exten => _s-.,1,Goto(s-NOANSWER,1)
[outbound-follow-me]
exten => _NXXNXXXXXX,1,NoOp(follow-me-activated-${EXTEN})
exten => _NXXNXXXXXX,n,Set(CALLERID(num)=${IF($[ ${LEN(${CALLERID(num)})} = 3]?7867086699:${CALLERID(num)})})
exten => _NXXNXXXXXX,n,Goto(outbound,${EXTEN},1)
exten => _1NXXNXXXXXX,1,NoOp(follow-me-activated-${EXTEN})
exten => _1NXXNXXXXXX,n,Set(CALLERID(num)=${IF($[ ${LEN(${CALLERID(num)})} = 3]?7867086699:${CALLERID(num)})})
exten => _1NXXNXXXXXX,n,Goto(outbound,${EXTEN:1},1)
exten => _1XX,1,Dial(SIP/${EXTEN},120,t)
exten => _1XX,n,Hangup()
[vm-operator]
exten => o,1,NoOp(operator-zero-out)
exten => o,n,Goto(vm-zero-menu,s,1)
; Direct Extension Dialing
exten => _1XX,1,Macro(local-followme,${EXTEN})
[vm-zero-menu]
exten => s,1,NoOp(operator-asterisk-out)
exten => s,n,Set(TIMEOUT(digit)=3)
exten => s,n,Set(TIMEOUT(response)=3)
exten => s,n,Background(custom/vm-operator-recording)
exten => s,n,Wait(3)
exten => s,n,Voicemail(100#default,su)
exten => 0,1,Voicemail(100#default,su)
exten => 1,1,NoOp(Operator-Directory)
exten => 1,n,Directory(default,vm-operator,f)
exten => 2,1,Voicemail(100#default,su)
exten => 3,1,Voicemail(100#default,su)
exten => 4,1,Voicemail(100#default,su)
exten => 5,1,Voicemail(100#default,su)
exten => 6,1,Voicemail(100#default,su)
exten => 7,1,Voicemail(100#default,su)
exten => 8,1,Voicemail(100#default,su)
exten => 9,1,Voicemail(100#default,su)
; Direct Extension Dialing
exten => _1XX,1,Macro(local-followme,${EXTEN})
exten => t,1,Playback(invalid)
exten => t,n,Hangup()
exten => i,1,Playback(invalid)
exten => i,n,Hangup()
exten => .,1,Playback(invalid)
exten => .,n,Hangup()
I got the following error:
Executing [102#internal:1] Gosub("SIP/101-00000002", "local-followme,s,1(102)") in new stack
[2021-05-18 20:26:16] ERROR[19823][C-0000000a]: app_stack.c:593 gosub_exec: Attempt to reach a non-existent destination for Gosub: (Context:local-followme, Extension:s, Priority:1)
== Spawn extension (internal, 102, 1) exited non-zero on 'SIP/101-00000002'
== Using SIP RTP CoS mark 5
app_stack is loaded apparently, this is what I have with the command "module show like app_stack" on CLI
app_stack.so - Dialplan subroutines (Gosub, Return, etc 0 - Running - core
I will really appreciate any guidance. Thanks.
Confirm if you are reloading the dialplan module by "dialplan reload" command in Asterisk CLI, it seems like what is being executed in the call is GoSub instead of Macro. You can validate dialplan statements loaded in Asterisk by doing "dialplan show" or "dialplan show context-name"
Please, avoid using Macro application, you should use GoSub application instead, Macro is considered deprecated.
Here's a Gosub example:
[internal]
exten => _1XX,1,GoSub(local-followme,s,1(${EXTEN}))
[local-followme]
exten => s,1,Verbose(GoSub executing)
same = n,Verbose(Argument 1: ${ARG1})
same = n,Return()

How to make incoming call recors on asterisk?

Situation: Analog phone line -> Asterisk with PSTN card -> Central PBX ->
exten => _1709,1,Set(CALLERID(name)=City_09)
exten => _1709,n,Noop(${CALLERID(name)})
exten => _1709,n,GoTo(incoming-reception,s,1)
Next
[incoming-reception]
include => external-trunk
exten => 0027449999,1,GoTo(incoming-reception,s,1)
exten => anonymous,1,GoTo(incoming-reception,s,1)
;exten => s,1,GotoIfTime(9:00-18:00|mon-sat|*|*?incoming-reception-work,s,1)
exten => s,1,GotoIfTime(9:00-18:00|mon-fri|*|*?incoming-reception-work,s,1)
exten => s,n,Answer()
exten => s,n,Set(TIMEOUT(digit)=2)
exten => s,n,NoOp(${CALLERID(num)})
exten => s,n,Set(CHANNEL(language)=ru)
exten => s,n,Wait(2)
exten => s,n,Background(day_off_1_welcome)
exten => s,n,Background(day_off_2_message)
exten => s,n,Voicemail(2001,s,300)
exten => 5,1,GoTo(incoming-reception-enoff,s,2)
exten => i,1,GoTo(incoming-reception,s,3)
exten => h,1,Congestion(10)
exten => h,2,HangUp()
next
[incoming-reception-work]
include => external-trunk
exten => s,1,Answer()
exten => s,n,Set(TIMEOUT(digit)=2)
exten => s,n,NoOp(${CALLERID(num)})
exten => s,n,Set(CHANNEL(language)=ru)
exten => s,n,Wait(2)
exten => s,n,Background(business_hours_1_welcome)
exten => s,n,Queue(test,T,,,32)
exten => s,n,Queue(test2,T)
exten => s,101,Background(business_hours_4_message)
exten => s,102,Voicemail(2001,s,300)
exten => 5,1,GoTo(incoming-reception-en,s,1)
exten => 9,1,Background(business_hours_4_message)
exten => 9,2,Voicemail(2001,s,300)
exten => i,1,GoTo(incoming-reception-work,s,1)
exten => h,1,Congestion(10)
exten => h,2,HangUp()
How can I make record incoming calls? Asterisk 1.8 (no freepbx, console only)
You could try to use Monitor/StopMonitor dialplan procedures to record incoming calls. Use the following template:
same => n,Monitor(wav,''${UNIQUEID},m)
same => n,Set(FILEARG="/tmp/asterisk/monitor/${UNIQUEID}.wav")
.
.
same => n,Hangup()
exten => h,1,StopMonitor()
same => n,System(/usr/local/bin/record-file-to-database --file=${FILEARG})
Check your Asterisk configs for the exact location of Monitor output folder.
See also an example here

Asterisk autodial and play recording

I am trying to originate a call using rawman, sending a phone number (57522666) as a parameter and playing a message to the answering party.
This is what I have so far:
http://192.168.11.11:8088/rawman?action=originate&channel=????&context=outboundmsg1&exten=s&priority=1&timeout=30000
And in extensions.conf:
[outboundmsg1]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Background(custom/message)
exten => t,1,Playback(vm-goodbye)
exten => t,2,Hangup
I have a SIP ATA as trunk with the following name: 23656429
I have no clue what to put in the channel parameter. I have tried SIP/23656429#57522666, but I don't get the outbound call.
In case someone else runs into this question... I got it to work by using the following:
http://192.168.11.11:8088/rawman?action=originate&channel=SIP/23656429/57522666&context=outboundmsg1&exten=s&priority=1&timeout=30000&callerid=23656429
And in extensions.conf
[outboundmsg1]
exten => s,1,Answer
exten => s,2,WaitExten()
exten => s,n,Wait(1)
exten => s,n,Playback(custom/elcodigo) ; "play outbound msg"
exten => s,n,SayDigits(1498)
exten => 2,n, Wait(1)
exten => s,n,Hangup

Asterisk context configuration

I have three contexts on my asterisk configuration and I want to configure it.
This is my extensions.conf with my users :
[agent]
exten => 100,1,NoOp(Communication en cours)
exten => 100,n,Dial(SIP/legende,10)
exten => 100,n,Hangup()
exten => 200,1,NoOp(Communication en cours)
exten => 200,n,Dial(SIP/malotru,10)
exten => 200,n,Hangup()
[sources]
exten => 300,1,NoOp(Communication en cours)
exten => 300,n,Dial(SIP/pepe,10)
exten => 300,n,Hangup()
exten => 400,1,NoOp(Communication en cours)
exten => 400,n,Dial(SIP/meme,10)
exten => 400,n,Hangup()
[analyste]
exten => 500,1,NoOp(Communication en cours)
exten => 500,n,Dial(SIP/cyclone,10)
exten => 500,n,Hangup()
exten => 600,1,NoOp(Communication en cours)
exten => 600,n,Dial(SIP/lafouine,10)
exten => 600,n,Hangup()
I want the users from the context "sources" not to be able to call anyone but they can receive calls from others and I want the context "analyst" only be able to call the "agents" users.
Maybe we have to add regex ?
If you want context not able call anything use something like that
[sources]
exten => _.,1,Answer
exten => _.,n,Playback(pbx-invalid); or put name of any sound file you want.
Incoming calls from OTHER contexts depend of that contexts, i.e incoming will work if it work now.

Asterisk Dialplan preventing dialplan from repeating continuously

I have the following macro in my diaplan which is excuted each time an incoming call comes.
Problem is that it is repeating itself indefinitely. I want it to repeat 3 times, if no input from the user, it should say goodbye and quit. Could anyone help me with this please.
Thanks
[macro-test]
;exten => s,1,Answer()
;exten => s,n,Wait(2)
exten => s,1,Set(AGISIGHUP=no)
exten => s,n,NoOp(AGISUGHUP: ${AGISIGHUP})
exten => s,n,Set(CALLED=${MACRO_EXTEN})
exten => s,n,Set(CALLER=${CUT(CUT(SIP_HEADER(From),#,1),:,2)})
exten => s,n(action),Set(EXIT=0)
exten => s,n,Set(TOKEN="")
exten => s,n,Set(INIT="true")
exten => s,n,While($[${EXIT}<1])
exten => s,n,Set(EXIT=1)
exten => s,n,Agi(agi://${ARG1}/server.agi?caller=${CALLER}&called=${CALLED}&init=${INIT})
exten => s,n,Set(INIT="false")
exten => s,n,NoOp(AGISTATUS: ${AGISTATUS})
exten => s,n,GotoIf($["${AGISTATUS}" != "SUCCESS"]?fail:succ)
exten => s,n(succ),EndWhile()
exten => s,n,Set(INIT="end")
exten => s,n,Agi(agi://${ARG1}/server.agi?caller=${CALLER}&called=${CALLED}&init=${INIT})
exten => s,n,Hangup()
exten => s,n(fail),Wait(2)
exten => s,n,Playback(vm-goodbye)
exten => s,n,Hangup()
exten => h,1,NoOp(Notify Billing System)
exten => h,n,NoOp(Other Tasks)
exten => h,n,Hangup()
Simple loop dialplan
exten =>s ,1,Set(loop=3)
exten =>s,n(loop),Noop(loop start here)
exten =>s,n,Noop(do something here)
exten =>s,n,Set(loop=$[ ${loop} - 1 ]);decrease loop countr
exten =>s,n,GotoIf($[ ${loop} > 0 ]?loop); if still have something, do again
exten => h,n,Hangup()
Don't call hangup, when you're already hung up.

Resources