Asterisk Dialplan preventing dialplan from repeating continuously - asterisk

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.

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

Send DTMF Digit with dialplan

I have the following dialplan:
exten => 224,1,NoOp(IN CALL : ${CALLERID(num)} => ${EXTEN})
exten => 224,n,Dial(${PJSIP_DIAL_CONTACTS(97,97)})
;exten => 224,n,Wait(3)
exten => 224,n,SendDTMF(*11234*,200)
exten => 224,n,Wait(3)
exten => 224,n,SendDTMF(#*)
exten => 224,n,Hangup()
When I call the extension 97 and it is connected, it doesnt seem to go next in line SendDTMF. What am I doing wrong?
Greetings
For who is looking for something like this without SendDTMF application, you can send DTMF with D option:
exten => n, Dial (SIP/97,60,D(1234))
If the DTMF passed are getted on the other side incomplete, use w option to delay 500 milliseconds.
Here I'm delaying 1 second
exten => n,Dial (SIP/97,60,D(ww1234))
Did you try using macros
[macro-send]
exten => s,1,SendDTMF(*11234*,200)
exten => s,n,Wait(3)
exten => s,n,SendDTMF(#*)
[yourDialPlan]
exten => 224,1,NoOp(IN CALL : ${CALLERID(num)} => ${EXTEN})
exten => 224,n,Dial(${PJSIP_DIAL_CONTACTS(97,97)},,M(send))
exten => 224,n,Hangup()

How to prevent Macro from returning to Gosub

I'm using Asterisk. Here is my scenario:
[my-custom-ivr]
exten => s,1,Background(fa/main_menu)
exten => 1,1,Gosub(ghesse-sub,s,1(1))
[ghesse-sub]
exten => s,n,Macro(get-subfolder,${ARG1})
exten => S,n,Read(digitsDetected,"barg/1-Ghesseh/GhesseMenu/1",1,,2,10)
exten => s,n,NoOp(${digitsDetected});
exten => s,n,Macro(get-storyfilename,${digitsDetected})
exten => s,n,Playback(${StoryFileName})
exten => s,n,NoOp(${MaxStoryID})
exten => s,n,NoOp(${StoryFolderID})
After executing Macro(get-subfolder,${ARG1}) it goes back to Gosub(ghesse-sub,s,1(1)). How to prevent it from doing that?
This is the desired behavior of GoSub (execute a subroutine and then continue where you left off).
If you don't want this behavior, then you should be using Goto instead.

Resources