Help With Dialplan GotoIF condition

All Viewers I am new in Asterisk Dialplan, Can anyone help me with below dialplan

exten => _X.,n,GotoIf($[${CheckMode} = {0:1:2:3}]?mode1:mode2:mode3)

I want to make whatever will be my variable output dialplan will go through that like if CheckMode = 1 then goto mode1 if CheckMode = 2 then go to mode2 like this, please help me out, hope I will get replay soon, Thanks…

Assuming CheckMode will only contain a valid mode number (1-3) and you have labels that correspond as ‘mode1’ ‘mode2’ ‘mode3’

exten => s,1,Goto(mode${CheckMode})
same => n,NoOp(Error, Fell through Mode Check)
same => n,Hangup()
same => n(mode1),NoOp(Mode is Mode 1)
same => n,Hangup()
same => n(mode2),NoOp(Mode is Mode 2)
same => n,Hangup()
same => n(mode3),NoOp(Mode is Mode 3)
same => n,Hangup()

GotoIf only takes truth values, so there can only be two destinations. I believe {0:1:2:3} will be treated as a literal string.

If CheckMode can only possibly contain 0, 1, 2, or 3, you could use Goto(Mode${CheckMode})

1 Like

Sir Thanks for your replay I am using odbc to get using mode from db like this way

exten => _X.,n,Set(CheckMode=${ODBC_CheckMode(${dialout})})
exten => _X.,n,GotoIf($[${CheckMode} = {0:1:2:3}]?mode1:mode2:mode3)

from db I get info about mode but dont understand how to using mode

You can do it on one line.
exten => _X.,n,Goto(mode${ODBC_CheckMode(${dialout})})

thanks a lot sir I have done it

now I need one more small help hope you can do it too

I am storing full callerid which looks like this “Google” " & when I try to check by MySQL it’s giving me a syntax error, how can I get it from MySQL & search full callerid even user changed it

Please mark code as pre-formatted text ( </> )!

This sounds like a MySQL question.

how to do that? can you please explain ?

Drag the mouse over the text, whilst holding the left mouse button down Release the mouse button. Move the mouse over </> . Single click the left mouse button.

Thanks, David I have done it…

now I am facing the problem with PlayBack IVR by nothing is playing I have used also others like Background, BackgroundDetect & others but the result is same

exten => _X.,n(hangupivr),Playback(invalid&,[noanswer])
exten => _X.,n(hangupivr),Playback(invalid)

it answers the call & Hangup immediately. I am using SVN-branch-1.8-r331578

-- Executing [923452369@simpro:50] Playback("SIP/rutest-000000d4", "invalid&,[noanswer]") in new stack
-- Executing [923452369@simpro:51] Playback("SIP/rutest-000000d4", "invalid") in new stack
-- Executing [923452369@simpro:52] Playback("SIP/rutest-000000d4", "invalid&,[noanswer]") in new stack
-- Executing [923452369@simpro:53] Playback("SIP/rutest-000000d4", "invalid") in new stack
-- Executing [923452369@simpro:54] Hangup("SIP/rutest-000000d4", "") in new stack

Asterisk 1.8 is over two years beyond end of life.

The caller ID is still not being displayed correctly in the forum.

There seem to be more lines in the dialplan than you have included here.

You can’t have two priorities for the same extension with the same label and expect the label to work properly.

As you screen scraped, rather than using the logfiles, I can’t see any time stamps. Also, the debugging level is not high enough to show anything going wrong.

I’m not sure what the error recovery for the longer Playback line would be, but I’d expect the shorter one to answer the call and announce “invalid”, once for priority 51 and once for priority 53. Priority 54 will terminate the call.

Your first Playback call has lots of syntax errors, e.g & without a following file name, and square brackets around the parameter. The meta syntax used is at least 50 years old.

exten => _X.,1,Answer()
exten => _X.,n,Playback(aaa) ; This is GSM Format
exten => _X.,n,Playback(bbb) ; This is G722 Format
exten => _X.,n,Playback(ccc) ; This is WAV Format
exten => _X.,n,Playback(ddd) ; This is Ulaw/WAV Format
exten => _X.,n,Hangup()

-- Executing [111@IVR:1] Answer("SIP/simpro-000000e2", "") in new stack
-- Oooh, SIP/simpro-000000e2 format changed to ulaw
-- Executing [111@IVR:2] Playback("SIP/simpro-000000e2", "aaa") in new stack
-- Executing [111@IVR:3] Playback("SIP/simpro-000000e2", "bbb") in new stack
-- Executing [111@IVR:4] Playback("SIP/simpro-000000e2", "ccc") in new stack
-- Executing [111@IVR:5] Playback("SIP/simpro-000000e2", "ddd") in new stack
-- Executing [111@IVR:6] Hangup("SIP/simpro-000000e2", "") in new stack

== Spawn extension (IVR, 111, 6) exited non-zero on ‘SIP/simpro-000000e2’

Caller using G.711 mu-law, can you tell please where I am wrong sir?

You cannot specify the file format in the Playback parameters. You must not include the “.” or the extension. Asterisk will choose from the files with the given base name that have the extension corresponding to the format that is present and least expensive to covert to a codec acceptable to the device.

Sir I didn’t specify I just write to make you understand but in config is like this

exten => _X.,1,Answer()
exten => _X.,n,Playback(aaa)
exten => _X.,n,Hangup()

isn’t it the correct way?


Please return the result of running “ls /var/lib/asterisk//aaa.

Please uncomment the full line in /etc/asterisk/logger.conf, and run “core set debug 9” on the CLI and provide all the lines from /var/log/asterisk/full relating to the call.

I have tried with other installation of asterisk, its working fine with my config, all that I was config it was good might be in this asterisk has some problem, but thanks for your fast reply.

and now I want to know something else if you can

is there any way to get current active call value like 5, 10 of the specific IP, using extensions.conf if yes then how please explain me, thanks…

Please see the other current thread.

Note Asterisk will not track anything about a particular IP address, only about declared end points.

I have done but bit a confused if I am on right track, please guide me if you can,

same => n,Set(currcall=${SIPPEER(${CHANNEL(peername)}:curcalls)})
same => n,Set(DBOrigLimit=${ODBC_DBOrigLimit(${orig_ip})})
same => n,GotoIf($[${DBOrigLimit} > ${currcall}]?orignext:failed)
same => n(orignext),NoOp(Here Is Your Current Calls: ${currcall}

There is an obvious mis-use of the “:” operator on the first line (one doesn’t need to know the specific correct syntax to see this).

I have done it sir…