title: Asterisk - macro GotoIf or operator
body: <pre><code>Asterisk 16.13.0 
  </code></pre>
  <p>Want to switch action between (primo, secondo, terzo and bo) based on the caller number.</p>
  <pre><code>[macro-gigi]
  exten =&gt; s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;207&quot;]?primo)
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;205&quot;|&quot;206&quot;]?secondo:terzo)
  
  exten =&gt; s,n(bo),NoOp(caller not managed: ${CALLERID(num)} - ${EXTEN} - ${CALLERID(all)} - ${CHANNEL})
  exten =&gt; s,n,MacroExit
  
  exten =&gt; s,n(primo),NoOp(primo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
  exten =&gt; s,n,MacroExit
  
  exten =&gt; s,n(secondo),NoOp(secondo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
  exten =&gt; s,n,MacroExit
  
  exten =&gt; s,n(terzo),NoOp(terzo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;203&quot;|&quot;204&quot;]?:bo)
  exten =&gt; s,n,NoOp(terzo: ${CALLERID(num)} - ${CALLERID(all)} - ${CHANNEL})
  exten =&gt; s,n,MacroExit
  </code></pre>
  <p>If the caller is 207 it run primo and this is fine.</p>
  <p>If the caller is 203 or 204 it run secondo and this is wrong.</p>
  <p>If the caller is 206 or 205 it run secondo and this is fine.</p>
  <p>If the caller is someone else it run secondo and this is wrong.</p>
  <p>I don't get if it is wrong the use of OR opeator <code>=&quot;205&quot;|&quot;206&quot;</code> or the gotoif sequences.</p>
  <pre><code>-- Executing [s@macro-gigi:1] NoOp(&quot;SIP/206-00000042&quot;, &quot;macro-gigi: 206 - SIP/206-00000042&quot;) in new stack
  -- Executing [s@macro-gigi:2] GotoIf(&quot;SIP/206-00000042&quot;, &quot;0?primo&quot;) in new stack
  -- Executing [s@macro-gigi:3] GotoIf(&quot;SIP/206-00000042&quot;, &quot;&quot;206&quot;?secondo:terzo&quot;) in new stack
  -- Goto (macro-gigi,s,8)
  -- Executing [s@macro-gigi:8] NoOp(&quot;SIP/206-00000042&quot;, &quot;secondo: 206 - SIP/206-00000042&quot;) in new stack
  -- Executing [s@macro-gigi:9] MacroExit(&quot;SIP/206-00000042&quot;, &quot;&quot;) in new stack
  
  
  
  -- Executing [s@macro-gigi:1] NoOp(&quot;SIP/203-00000044&quot;, &quot;macro-gigi: 203 - SIP/203-00000044&quot;) in new stack
  -- Executing [s@macro-gigi:2] GotoIf(&quot;SIP/203-00000044&quot;, &quot;0?primo&quot;) in new stack
  -- Executing [s@macro-gigi:3] GotoIf(&quot;SIP/203-00000044&quot;, &quot;&quot;206&quot;?secondo:terzo&quot;) in new stack
  -- Goto (macro-gigi,s,8)
  -- Executing [s@macro-gigi:8] NoOp(&quot;SIP/203-00000044&quot;, &quot;secondo: 203 - SIP/203-00000044&quot;) in new stack
  -- Executing [s@macro-gigi:9] MacroExit(&quot;SIP/203-00000044&quot;, &quot;&quot;) in new stack
  
  -- Executing [s@macro-gigi:1] NoOp(&quot;SIP/204-00000045&quot;, &quot;macro-gigi: 204 - SIP/204-00000045&quot;) in new stack
  -- Executing [s@macro-gigi:2] GotoIf(&quot;SIP/204-00000045&quot;, &quot;0?primo&quot;) in new stack
  -- Executing [s@macro-gigi:3] GotoIf(&quot;SIP/204-00000045&quot;, &quot;&quot;206&quot;?secondo:terzo&quot;) in new stack
  -- Goto (macro-gigi,s,8)
  -- Executing [s@macro-gigi:8] NoOp(&quot;SIP/204-00000045&quot;, &quot;secondo: 204 - SIP/204-00000045&quot;) in new stack
  -- Executing [s@macro-gigi:9] MacroExit(&quot;SIP/204-00000045&quot;, &quot;&quot;) in new stack
  
  
  -- Executing [s@macro-gigi:1] NoOp(&quot;SIP/205-00000043&quot;, &quot;macro-gigi: 205 - SIP/205-00000043&quot;) in new stack
  -- Executing [s@macro-gigi:2] GotoIf(&quot;SIP/205-00000043&quot;, &quot;0?primo&quot;) in new stack
  -- Executing [s@macro-gigi:3] GotoIf(&quot;SIP/205-00000043&quot;, &quot;1?secondo:terzo&quot;) in new stack
  -- Goto (macro-gigi,s,8)
  -- Executing [s@macro-gigi:8] NoOp(&quot;SIP/205-00000043&quot;, &quot;secondo: 205 - SIP/205-00000043&quot;) in new stack
   -- Executing [s@macro-gigi:9] MacroExit(&quot;SIP/205-00000043&quot;, &quot;&quot;) in new stack
  
  
  -- Executing [s@macro-gigi:1] NoOp(&quot;PJSIP/102-00000050&quot;, &quot;macro-gigi: 102 - PJSIP/102-00000050&quot;) in new stack
  -- Executing [s@macro-gigi:2] GotoIf(&quot;PJSIP/102-00000050&quot;, &quot;0?primo&quot;) in new stack
  -- Executing [s@macro-gigi:3] GotoIf(&quot;PJSIP/102-00000050&quot;, &quot;&quot;206&quot;?secondo:terzo&quot;) in new stack
  -- Goto (macro-gigi,s,8)
  -- Executing [s@macro-gigi:8] NoOp(&quot;PJSIP/102-00000050&quot;, &quot;secondo: 102 - PJSIP/102-00000050&quot;) in new stack
  -- Executing [s@macro-gigi:9] MacroExit(&quot;PJSIP/102-00000050&quot;, &quot;&quot;) in new stack
  </code></pre>
  <p><strong>EDIT:</strong></p>
  <p>With this change it works everything but it isn't DRY:</p>
  <pre><code>exten =&gt; s,1,NoOp(macro-gigi: ${CALLERID(num)} - ${CHANNEL})
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;205&quot;]?secondo)
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;206&quot;]?secondo)
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;207&quot;]?primo)
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;203&quot;]?terzo)
  exten =&gt; s,n,GotoIf($[&quot;${CALLERID(num)}&quot;=&quot;204&quot;]]?terzo:bo)
  </code></pre>