GotoIf DialPlan question

Hello guys, i’m trying to configure a rule that allow some internal numbers to use a specific trunk, for example 1000 and 1001, what am I doing wrong?

exten => _[02-9].,1,NoOp(${CALLERID(ani)})
exten => _[02-9].,2,GotoIf($["${CALLERID(ani)}"=“1000”] | $["${CALLERID(ani)}"=“1001”]?3:5)
exten => _[02-9].,3,NoOp(“Allow”)
exten => _[02-9].,4,Dial(SIP/${EXTEN:0}@trunk1,tTo)
exten => _[02-9].,5,Hangup

How are you setting the ANI?

What does the log show?

For conditional better to use letter characters instead of numbers (testing dialplan script use verbose command).

exten => _[02-9].,1,NoOp(${CALLERID(ani)})
exten => _[02-9].,2,GotoIf($["${CALLERID(ani)}"=“1000”] | $["${CALLERID(ani)}"=“1001”]?3:5)
exten => _[02-9].,3(3),NoOp(“Allow”)
exten => _[02-9].,4,Dial(SIP/${EXTEN:0}@trunk1,tTo)
exten => _[02-9].,5,Hangup

I.E:

exten => _[02-9].,1,NoOp(${CALLERID(ani)})
exten => _[02-9].,2,GotoIf($["${CALLERID(ani)}"=“1000”] | $["${CALLERID(ani)}"=“1001”]?y)
exten => _[02-9].,3(y),NoOp(“Allow”)
exten => _[02-9].,4,Dial(SIP/${EXTEN:0}@trunk1,tTo)
exten => _[02-9].,5,Hangup

It can summarized if conditional boolean result is true diaplan goes to true condition (y), otherwise it continues with next priority.

Although using literal priority numbers isn’t good practice and:

same => n(truelable),…

would be better, it is still a legal way of coding.

Absolutely agree, the suggested is based on the posted script for make clearly and understandable.

Thanks guys for the answers, I tried but it doesn’t work, the calls start also for the extension that aren’t included. What do you think?

-- Executing [33333333@default:1] NoOp("SIP/9997-000001da", "9997") in new stack
-- Executing [33333333@default:2] GotoIf("SIP/9997-000001da", "0 | 0?y") in new stack
-- Executing [33333333@default:3] NoOp("SIP/9997-000001da", "“Allow”") in new stack
-- Executing [33333333@default:4] AGI("SIP/9997-000001da", "agi://127.0.0.1:4577/call_log") in new stack

-- Executing [33333333@default:1] NoOp("SIP/1000-000001d8", "1000") in new stack
-- Executing [33333333@default:2] GotoIf("SIP/1000-000001d8", "0 | 0?y") in new stack
-- Executing [33333333@default:3] NoOp("SIP/1000-000001d8", "“Allow”") in new stack
-- Executing [33333333@default:4] AGI("SIP/1000-000001d8", "agi://127.0.0.1:4577/call_log") in new stack

The log makes the problem stand out like a sore thumb! You have two logical expressions separated by a literal | character when you actually want a single logical expression, with the | in the middle of it.

The log should look like

GotoIf("SIP/9997-000001da", "1?y")

or

GotoIf("SIP/9997-000001da", "0?y")

depending on whether the expression is true or false.

I have modified and it working (line 2)

exten => _[02-9].,1,NoOp(${CALLERID(ani)})
exten => _[02-9].,2,GotoIf($[${CALLERID(ani)}=1000|${CALLERID(ani)}=1001]?y:n)
exten => _[02-9].,3(y),NoOp(.Allow.)
exten => _[02-9].,4,Dial(SIP/${EXTEN:0})
exten => _[02-9].,5(n),Playback(goodbye)

Dialplan test

Match CallerID

    -- Executing [333333333@default:1] NoOp("PJSIP/6002-00000009", "6002") in new stack
    -- Executing [333333333@default:2] GotoIf("PJSIP/6002-00000009", "1?y:n") in new stack
    -- Goto (default,333333333,3)
    -- Executing [333333333@default:3] NoOp("PJSIP/6002-00000009", ".Allow.") in new stack
    -- Executing [333333333@default:4] Dial("PJSIP/6002-00000009", "SIP/333333333") in new stack

Unmatch CALLERDID

  -- Executing [333333333@default:1] NoOp("PJSIP/6002-00000008", "-------") in new stack
    -- Executing [333333333@default:2] GotoIf("PJSIP/6002-00000008", "0?y:n") in new stack
    -- Goto (default,333333333,5)
    -- Executing [333333333@default:5] Playback("PJSIP/6002-00000008", "goodbye") in new stack
    -- <PJSIP/6002-00000008> Playing 'goodbye.ulaw' (language 'en')
1 Like

Thanks guys for the answers, @Rmcgrath I’ve tried your solution but it doesn’t work and the call doesn’t start.

Strict RTP learning after remote address set to: 192.168.7.183:10036
– Executing [33333333@defaultlog:1] AGI(“SIP/1000-000001f4”, “agi-NVA_recording.agi,BOTH------Y—Y—Y”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/agi-NVA_recording.agi
– AGI Script Executing Application: (Monitor) Options: (wav,/var/spool/asterisk/monitor/MIX/20210925162156_1000_33333333)
– <SIP/1000-000001f4>AGI Script agi-NVA_recording.agi completed, returning 0
– Executing [33333333@defaultlog:2] Goto(“SIP/1000-000001f4”, “default,33333333,1”) in new stack
– Goto (default,33333333,1)
– Executing [33333333@default:1] NoOp(“SIP/1000-000001f4”, “1000”) in new stack
– Auto fallthrough, channel ‘SIP/1000-000001f4’ status is ‘UNKNOWN’

@david551 I tried but it doensn’t work

There is no GotoIf in your log!

There is in the original log, maybe i’ve cut the line with copy and paste

It seems first execute a script which call GotoIf script and it failed by status of SIP/1000-000001f4 state.

Hello @david551 @Rmcgrath thanks for the support, now it works :slight_smile:
I erase and rewrite the dialplan, rebooted the server and now its fine.

Great! thanks, good luck.

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