Asterisk - macro GotoIf or operator

Viewed 505
Asterisk 16.13.0 

Want to switch action between (primo, secondo, terzo and bo) based on the caller number.

[macro-gigi]
exten => s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,GotoIf($["${CALLERID(num)}"="207"]?primo)
exten => s,n,GotoIf($["${CALLERID(num)}"="205"|"206"]?secondo:terzo)

exten => s,n(bo),NoOp(caller not managed: ${CALLERID(num)} - ${EXTEN} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit

exten => s,n(primo),NoOp(primo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit

exten => s,n(secondo),NoOp(secondo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit

exten => s,n(terzo),NoOp(terzo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,GotoIf($["${CALLERID(num)}"="203"|"204"]?:bo)
exten => s,n,NoOp(terzo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
exten => s,n,MacroExit

If the caller is 207 it run primo and this is fine.

If the caller is 203 or 204 it run secondo and this is wrong.

If the caller is 206 or 205 it run secondo and this is fine.

If the caller is someone else it run secondo and this is wrong.

I don't get if it is wrong the use of OR opeator ="205"|"206" or the gotoif sequences.

-- Executing [s@macro-gigi:1] NoOp("SIP/206-00000042", "macro-gigi: 206 - SIP/206-00000042") in new stack
-- Executing [s@macro-gigi:2] GotoIf("SIP/206-00000042", "0?primo") in new stack
-- Executing [s@macro-gigi:3] GotoIf("SIP/206-00000042", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s@macro-gigi:8] NoOp("SIP/206-00000042", "secondo: 206 - SIP/206-00000042") in new stack
-- Executing [s@macro-gigi:9] MacroExit("SIP/206-00000042", "") in new stack



-- Executing [s@macro-gigi:1] NoOp("SIP/203-00000044", "macro-gigi: 203 - SIP/203-00000044") in new stack
-- Executing [s@macro-gigi:2] GotoIf("SIP/203-00000044", "0?primo") in new stack
-- Executing [s@macro-gigi:3] GotoIf("SIP/203-00000044", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s@macro-gigi:8] NoOp("SIP/203-00000044", "secondo: 203 - SIP/203-00000044") in new stack
-- Executing [s@macro-gigi:9] MacroExit("SIP/203-00000044", "") in new stack

-- Executing [s@macro-gigi:1] NoOp("SIP/204-00000045", "macro-gigi: 204 - SIP/204-00000045") in new stack
-- Executing [s@macro-gigi:2] GotoIf("SIP/204-00000045", "0?primo") in new stack
-- Executing [s@macro-gigi:3] GotoIf("SIP/204-00000045", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s@macro-gigi:8] NoOp("SIP/204-00000045", "secondo: 204 - SIP/204-00000045") in new stack
-- Executing [s@macro-gigi:9] MacroExit("SIP/204-00000045", "") in new stack


-- Executing [s@macro-gigi:1] NoOp("SIP/205-00000043", "macro-gigi: 205 - SIP/205-00000043") in new stack
-- Executing [s@macro-gigi:2] GotoIf("SIP/205-00000043", "0?primo") in new stack
-- Executing [s@macro-gigi:3] GotoIf("SIP/205-00000043", "1?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s@macro-gigi:8] NoOp("SIP/205-00000043", "secondo: 205 - SIP/205-00000043") in new stack
 -- Executing [s@macro-gigi:9] MacroExit("SIP/205-00000043", "") in new stack


-- Executing [s@macro-gigi:1] NoOp("PJSIP/102-00000050", "macro-gigi: 102 - PJSIP/102-00000050") in new stack
-- Executing [s@macro-gigi:2] GotoIf("PJSIP/102-00000050", "0?primo") in new stack
-- Executing [s@macro-gigi:3] GotoIf("PJSIP/102-00000050", ""206"?secondo:terzo") in new stack
-- Goto (macro-gigi,s,8)
-- Executing [s@macro-gigi:8] NoOp("PJSIP/102-00000050", "secondo: 102 - PJSIP/102-00000050") in new stack
-- Executing [s@macro-gigi:9] MacroExit("PJSIP/102-00000050", "") in new stack

EDIT:

With this change it works everything but it isn't DRY:

exten => s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,GotoIf($["${CALLERID(num)}"="205"]?secondo)
exten => s,n,GotoIf($["${CALLERID(num)}"="206"]?secondo)
exten => s,n,GotoIf($["${CALLERID(num)}"="207"]?primo)
exten => s,n,GotoIf($["${CALLERID(num)}"="203"]?terzo)
exten => s,n,GotoIf($["${CALLERID(num)}"="204"]]?terzo:bo)
1 Answers

205|206 result will be 1

exten => s,n,GotoIf($[ $[ "${CALLERID(num)}"="205"] | $["${CALLERID(num)}"="206"] ]?secondo)

https://www.voip-info.org/asterisk-expressions/

But that is NOT asterisk-way. Asterisk way is like this:

exten => s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CHANNEL})
exten => s/_20[56],n,Goto(secondo);actually really asterisk way is do what needed on this patern
exten => s/207,1,NoOp(primo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
same => n,Nopo(other dialplan for 207)
same => n,MacroExit

exten => s/_20[34],1,Goto(terzo)

exten => s/_2XX,1,Goto(bo);other

https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching

If you need macro-like behavior, use gosub/return. Macro is depricated.

Related