How to use gotoif cluase in my dialplan

exten=>.,1,Set(CALLERID(num)=${cid})
exten=>
.,n,Gosub(monitor,${EXTEN},1)
exten=> _X!,1,Answer()
same => n,WaitForSilence(1500,1)

same => n,Playback(voice0.wav)
same => n,WaitForSilence(1500,1)
same => n,Read(dtmfno,voice0.wav,20)
same => n,NoOp(${dtmfno})
same => n,AGI(cx_agi/dtmf.py,${CALLERID(number)},${dst},${dtmfno})
same => n,WaitForSilence(1500,1)
same => n,Read(dtmfno,oice0.wav,20)
same => n,NoOp(${dtmfno})
same => n,AGI(cx_agi/dtmf.py,${CALLERID(number)},${dst},${dtmfno})
same => s,n,GotoIf($[ “${dtmfno}” = “” ]?endcall,1)

same => n,Playback(voice1.wav)
same => n,Read(dtmfno,voice1.wav,20)
same => n,NoOp(${dtmfno})
same => n,AGI(cx_agi/dtmf.py,${CALLERID(number)},${dst},${dtmfno})
same => n,WaitForSilence(1500,1)
same => n,Read(dtmfno,voice1.wav,20)
same => n,NoOp(${dtmfno})
same => n,AGI(cx_agi/dtmf.py,${CALLERID(number)},${dst},${dtmfno})
same => n,WaitForSilence(1500,1)

same => endcall,1,set(endcall=1)
same => n,hangup()

my goal is if first section —voice0 part, if dont receive anything about dtmf code, will skip second voice1 part and will hangup.
to do this, I made above dialplan.
what is wrong?
please help me.

Try this:
same => n,GotoIf($[“${dtmfno}” = “”]?endcall)

And where you have endcall, replace with:

same => n(endcall),set(endcall=1)

Although it is an unusual way of coding dialplans, the parameters of the GotoIf were correct for the dialplan as originally coded.

so my code was correct?

same => s,n,GotoIf($[ “${dtmfno}” = “” ]?endcall,1)

this is correct?

That is not correct, but the GotoIf part appears to be correct.

then could you guide me about this code?
what is correct gotoif using in my code?

Look for warnings when you load the dialplan and also use “dialplan show” to see how it is being interpreted.

Or simply look at the suggestion you have already been given and try to understand what it is doing.

current if I run my above plan, I can see dont running this plan part.

someone know the reason?
if know, please tell me
due to gotoif clause?
otherwise?

Take a look at Asterisk 18 Application_GotoIf - Asterisk Project - Asterisk Project Wiki

Sometimes it’s best to visualize some samples.

Example 1:
same => s,n,GotoIf($[ “${dtmfno}” = “” ]?endcall)
Will lookup for:
same => n(endcall),NoOp...

Example 2:
same => s,n,GotoIf($[ “${dtmfno}” = “” ]?endcall,1)
Will lookup for:
exten => endcall,1,NoOp...

Example 3:
same => s,n,GotoIf($[ “${dtmfno}” = “” ]?endcall,start,5)
Will lookup for:

exten => start,5,NoOp...

No. They will do one of:

  • fail to parse at load time;
  • not be run because they have duplicate extension patterns and priorities (alternatively the AGI may fail to run for that reason);
  • try to run application n, or at least an application beginning with n.

A combination of the error messages produced and the dialplan show output should indicate which of these.

nrjchnd’s solution fixed this, but also changed the structure of the program in a way that was not necessary to solve the problem, although likely to be better practice.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.