Reputation: 2426
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?
Upvotes: 0
Views: 3173
Reputation: 20540
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
Upvotes: 5
Reputation: 11
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
Upvotes: 0
Reputation: 3080
Dialplan must be consecutive. Ext 1000 is never hit - hence asterisk falls through to the h exten.
Upvotes: 0