I have the following context in my asterisk dialplan.
[start-call]
exten => _X.,1,AGI(agi://localhost:4000)
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect)
exten => _X.,1000(redirect),Hangup(31)
exten => 900,n,Goto(start-call,${EXTEN},1)
exten => h,n,Hangup
I have an AGI app which connects the call and collects DTMF inputs, and set that number as the extension using the SET EXTENSION agi command (line 1). I set the AGISTATUS to FAILURE only when there is no DTMF input. If there is no input, I timeout, and hangup (line 3). But if 900 is entered I go back to start-call context and do some magic in the AGI application (line 4).
The problem is that, right now even if I enter 900 the call just gets hung up. And not from line 3 but the last line. So its skipping line 4 somehow. If I move the 900 extension (line 4) before the one labelled redirect (line 3), it works.
I thought asterisk increments the 'n' priority automatically, and would expect this to work in the order listed above. Am I wrong here?
n iterates automatically - it adds 1 to the previous priority. This is also why you have to initialize the incrementor with priority 1 in the first line.
When you put priority 1000 somewhere in the middle (which is totally valid) the next line with n will add 1 to this, resulting in priority 1001 - which is never hit as already explained by others.
Your dialplan can be read like below:
[start-call]
exten => _X.,1,AGI(agi://localhost:4000)
exten => _X.,2,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect)
exten => _X.,1000(redirect),Hangup(31)
exten => 900,1001,Something() ; not 3!
exten => h,1,Hangup
To fix this you must either reorder your extensions as explained by others or use the + operator for priorities:
[start-call]
exten => _X.,1,AGI(agi://localhost:4000) ; 1
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect) ; 2
exten => _X.,n+1000(redirect),Hangup(31) ; 1002
exten => 900,n,Something() ; 3
exten => h,1,Hangup
By the way, you can also use text labels as extensions, which will make your dialplans more readable:
[start-call]
exten => _X.,1,AGI(agi://localhost:4000) ; 1
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?agi_failure,1) ; 2
exten => 900,n,Something() ; 3
exten => agi_failure,1,DoSomething()
exten => agi_failure,n,DoEvenMore()
exten => h,1,Hangup
Dialplan must be consecutive. Ext 1000 is never hit - hence asterisk falls through to the h exten.
Yes the dialplan must be consecutive, and once you start the "n" series you need to stick with it. I am assuming extension 900 is an example of the DTMF input -- this new extension must always start with a priority of 1. The "h" extension must also start with a priority of 1
[start-call]
exten => _X.,1,AGI(agi://localhost:4000)
exten => _X.,n,GotoIf($["${AGISTATUS}" = "FAILURE"]?redirect)
exten => _X.,n,**if input received do something here**
exten => _X.,n(redirect),Hangup(31)
exten => 900,1,Goto(start-call,${EXTEN},1)
exten => h,1,Hangup
Related
In my asterisk extension I had wrote like this
[callback]
exten => Set(FROM=${CALLERID(num)})
exten => 2020,1,Answer()
exten => 2020,n,GotoIf(callback)
exten => 2020,n(callback),System(/etc/asterisk/scripts/callback)
exten => 2020,n,Hangup()
exten => 1111,1,Answer()
exten => 1222,1,Dial(SIP/2000) ;here instead of 2000 I want to bring callerid number FROM
exten => 1222,n,Hangup()
When I give SIP/2000 everything is working fine after I give miss call to 2020 I am able to get call.
But when I give like this SIP/$FROM its not working. CallerID number is coming blank.
Can anyone help me to solve this problem
On Asterisk 1.2 or higher, replace the 2nd line with:
exten => Set(FROM=${CALLERID(num)},g)
On Asterisk 1.0 or 1.1, replace the 2nd line with:
exten => SetGlobalVar(FROM=${CALLERID(num)})
How to remove first 3 digits/letters from CALLED NUMBER. Let's say number 123456789 calls to abc987654321. I want to remove abc because in the context I have only 987654321. I know how to cut from CALLER but don't know how to cut from CALLED(Destination) number. This is what I tried so far but nothing happen:
exten => _[a-z]XXXXXXXXXXXX,1,Set({CALLEDID}=${CALLEDID:3})
exten => _[a-z]XXXXXXXXXXXX,2,Dial(SIP/${CALLEDID},1)
exten => _[a-z]XXXXXXXXXXXX,3,Voicemail(${CALLEDID}#VoiceMail)
exten => _[a-z]XXXXXXXXXXXX,4,Playback(Goodbye)
exten => _[a-z]XXXXXXXXXXXX,5,Hangup
You can use FILTER function or just do goto. You not need cut from destination,you need cut from extension.
exten => _[a-z]XXXXXXXXXXXX,1,Goto(${EXTEN:3},1)
exten => _XXXXXXXXXXXX,1,Dial(SIP/${EXTEN},1)
exten => _XXXXXXXXXXXX,n,Voicemail(${EXTEN}#VoiceMail)
exten => _XXXXXXXXXXXX,n,Playback(Goodbye)
exten => _XXXXXXXXXXXX,n,Hangup
Please note, your dialplan still do voicemail if called part hanguped after call. Read default extensions.conf.sample to see how to deal with voicemail
I am in a situation where I often need to change the active call flow control (which can only be one..right?).
I find that netsting call flow controls is very unhandy if you have 4 different scenarios.
So what I would like to do is to create an 4 different extensions that set the appropriate call flow as the inbound route destination.
To make an example:
I have
CALL FLOW NR 1
CALL FLOW NR 2
CALL FLOW NR 3
CALL FLOW NR 4
I would like to create:
extension *881 -> Toggles Call Flow nr 1 and sets it as destination
of the inbound route
extension *882 -> Toggles Call Flow nr 2 and sets it as destination
of the inbound route
extension *883 -> Toggles Call Flow nr 3 and sets it as destination
of the inbound route
extension *884 -> Toggles Call Flow nr 4 and sets it as destination
of the inbound route
Is something like that possible?
If so...how would you achieve it?
My system is based asterisk 11 and freepbx 2.11.
Thank you in advance for your time and effort.
You can put as many time conditions as needed.
You can use special code to turn on/off time condition(used for holidays). You can check exact code on timecondition page.
You also can create custom module which will change flow, more info see on dev.freepbx.org. As option you can hire someone do your condition module.
I figured it out
edit /etc/asterisk/extensions_custom.com and paste the following
[from-internal-custom]
include => enable-switch
[check-active-switch]
exten => s,1,NoOp("This context loops through all the switches and checks which one is ON. Than it follows its destination")
exten => s,n,GoSub(sub-get-nr-of-switches,s,1)
exten => s,n,Set(nrofs=${GOSUB_RETVAL})
exten => s,n,Set(i=0)
exten => s,n,Set(default-dest=app-daynight,${switchnr},1)
exten => s,n,Set(switchnr="NULL")
exten => s,n,While($[$[${i} < ${nrofs}] & $[${switchnr} = "NULL"]])
exten => s,n,Set(switchnr=${IF($["${DB(DAYNIGHT/C${i})}" = "NIGHT"]?${i}:"NULL")})
exten => s,n,Set(i=$[${i} + 1])
exten => s,n,EndWhile
exten => s,n,GotoIf($[${switchnr}!="NULL"]?app-daynight,${switchnr},1:${default-dest})
exten => s,n,Hangup()
[sub-get-nr-of-switches]
exten => s,1,Set(nr_of_s=0)
exten => s,n,Set(exten_state="NOT_ACQUIRED")
exten => s,n,While($[${exten_state}!=0])
exten => s,n,Set(exten_state=$[${VALID_EXTEN(app-daynight,${nr_of_s},1)}])
exten => s,n,NoOp(Exten nr ${nr_of_s} of app-daynight is ${exten_state})
exten => s,n,Set(nr_of_s=${IF($[${exten_state}=1]?$[${nr_of_s}+1]:${nr_of_s})})
exten => s,n,EndWhile
exten => s,n,NoOp(${nr_of_s} switches found)
exten => s,n,Return(${nr_of_s})
[enable-switch]
exten =>_*20X,1,NoOp("Abilita Switch selezionato e disabilita altre")
same => n,GoSub(sub-get-nr-of-switches,s,1)
same => n,Set(nrofs=${GOSUB_RETVAL})
same => n,Set(switchtoactivate=${EXTEN:3})
same => n,NoOp(Activated Switch nr ${switchtoactivate})
same => n,Set(i=0)
same => n,While($[${i}<${nrofs}])
same => n,Set(DB(DAYNIGHT/C${i})=DAY)
same => n,Set(i=$[${i}+1])
same => n,EndWhile
same => n,Set(freepbx_toggle_dest=*28${switchtoactivate})
same => n,Goto(app-daynight-toggle,${freepbx_toggle_dest},1)
same => n,Hangup
Next go to freepbx and create a custom destination -> check-active-switch,s,1 and set it as destination of the inbound route
I am using the "monitor" command to record full calls. This works well, but only when the user goes through the entire callflow. I tried monitoring the recorded file size as the call progresses. Once the call starts, the file sizes start increasing (of both the "in" and "out" sides of the call). However, if the user hangs up prematurely in the middle of the call, whatever has been recorded thus far is inexplicably dropped and stubs (44 bytes) are left in its place. Any insight into why this behavior occurs will be appreciated.
I am reproducing a snippet from the dialplan I used in my extensions.conf file below:
exten => 7611,1,Answer()
exten => 7611,n,Playback(/var/lib/asterisk/sounds/custom/transferring_with_record_wa rning)
exten => 7611,n,Set(GROUP()=outgoing)
exten => 7611,n,NoOp(The current group count : ${GROUP_COUNT(outgoing)})
exten => 7611,n,GotoIf($[${GROUP_COUNT(outgoing)}>1]?15)
exten => 7611,n,Set(GLOBAL(current_timestamp_7611)=${STRFTIME(${EPOCH},GMT+1,%s)})
exten => 7611,n,Set(GLOBAL(current_full_format_timestamp_7611)=${STRFTIME(${EPOCH},G MT-8,%d%m%Y_%H%M%S)})
exten => 7611,n,NoOp(The current timestamp : ${current_timestamp_7611})
exten => 7611,n,NoOp(The last timestamp : ${last_timestamp_7611})
exten => 7611,n,GotoIf($[(${last_timestamp_7611}+20>${current_timestamp_7611})]?15)
exten => 7611,n,NoOp(All cases passed)
exten => 7611,n,Ringing()
exten => 7611,n,Wait(2)
exten => 7611,n,Monitor(wav,HALEF_audio_ext_7611_${current_full_format_timestamp_761 1})
exten => 7611,n,Dial(SIP/1200#JVXML97,,XgF(default^7611^14))
exten => 7611,n,Set(GLOBAL(last_timestamp_7611)=${STRFTIME(${EPOCH},GMT+1,%s)})
exten => 7611,n,Hangup()
exten => 7611,n,Ringing()
exten => 7611,n,Wait(2)
exten => 7611,n,Playback(/var/lib/asterisk/sounds/custom/busy_later)
exten => 7611,n,Wait(1)
exten => 7611,n,Hangup()
I understand that the "record" command has a "k" parameter which keeps the recorded file upon hangup, but I'm not able to find any similar functionality with the Monitor command. (I'd use "record", but I'd like to record the full call (duplex) and do it automatically, without any user input requirement).
Thanks!
Use MixMonitor command.
Check you have permissions needed for write files.
Check debug if you unsure.
PS. using diaplan WITH n, without labels and goto to EXACT priority is very bad practice, can result hard-catchable bugs. Using GLOBAL variables without need also not so nice idea.
I'm a beginner on Asterisk, but already have my PBX working connected to the PSTN. The issue I'm having is that I have this rule
exten => _*X.*,1,Log(DEBUG, Calling through provider one to ${EXTEN:1:-1})
same => n,Dial(SIP/${EXTEN:1:-1}#oneProvider,60)
There are no other extensions that start with *. What I want to achieve is to dial out as soon as the second * is pressed (and there's nothing the user can press to go to a valid extension), right now it waits a few seconds and dial. I also tried adding ! at the end of the extension, but nothing changed.
Am I missing something? Is this feasible?
Thanks!
This task is not doable in current asterisk.
It will not work beacuase * matched .(dot) in your dialplan.
Except dialplan like this(very ugly one beacuase it will go dialplan for every new digit)
[originalcontext]
exten => *,1,Goto(collect_number,s,1)
[collect_number]
exten => s,1,WaitExten(); wait for single digit
exten => *,1,Set(stars=${stars}*);save stars
exten => *,2,GotoIF($[ "${stars}" == "**" ]?dial,1); if 2 star already,go dial.
exten =>_X,1,Set(digits=${digits}${EXTEN});save digits
exten => _.,3,WaitExten(); wait enother input;
exten => _.,4,Goto(dial,1); go dial if no new digits
exten => dial,1,Dial(SIP/${digits}#oneProvider,60)
Correct solution - use Read application and ask user use # to end number instead of *.
You also can try dialplan like this:
exten => _*X*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXXXX*!,1,Goto(dial,${EXTEN:1:-1},1)
exten => _*XXXXXXXX*!,1,Goto(dial,${EXTEN:1:-1},1); continue upto max number length
[dial]
exten =>_.,1,Dial(SIP/${EXTEN}#oneProvider,,);
But i not fully sure that will work. If works, will be less load(but more lines)