asteriskdialplan

Asterisk 11 match destination extension in macro


Long story short: Fanvil phones don't allow you to change microphone volume (that is too low).

I've created this custom macro, but cannot match the case the phone (exten 131) is receiving a call, it work only when it make a call:

[macro-fanvil]
exten => s,1,NoOp(catch: callerid: ${CALLERID(num)} - exten ${EXTEN}- ${CHANNEL})
;exten => _131,n,Goto(receive)
exten => s,n,GotoIf($[${EXTEN} = 131]?receive)
exten => s,n,GotoIf($[${CALLERID(num)} = 131]?:iscalling)
exten => s,n(iscalling),NoOp(alzachiamante: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,Set(VOLUME(RX)=10)
exten => s,n,MacroExit
exten => s,n(receive),NoOp(alzaricevente: ${CALLERID(num)} - ${CHANNEL})
exten => s,n,Answer()
exten => s,n,Set(VOLUME(TX)=10)
exten => s,n,MacroExit

This is from console:

    -- Executing [s@macro-fanvil:1] NoOp("SIP/195-00000096", "macro-fanvil: callerid: 195 - exten s- SIP/195-00000096") in new stack
    -- Executing [s@macro-fanvil:2] GotoIf("SIP/195-00000096", "0?receive") in new stack
    -- Executing [s@macro-fanvil:3] GotoIf("SIP/195-00000096", "0?:iscalling") in new stack
    -- Goto (macro-fanvil,s,4)

 Executing [s@macro-fanvil:4] NoOp("SIP/195-00000096", "alzachiamante: 195 - SIP/195-00000096") in new stack
    -- Executing [s@macro-fanvil:5] Set("SIP/195-00000096", "VOLUME(RX)=10") in new stack
    -- Executing [s@macro-fanvil:6] MacroExit("SIP/195-00000096", "") in new stack

It seems that ${EXTEN} is always the one that is calling, how can I catch the event of the 131 is the destination of the call?


Solution

  • As you can see ${EXTEN} inside a Macro is always s.
    -- Executing [s@macro-fanvil:1] NoOp("SIP/195-00000096", "macro-fanvil: callerid: 195 - exten s- SIP/195-00000096") in new stack

    You have to tell the Macro the ${EXTEN} when you calling it.
    This is normally done with...
    https://wiki.asterisk.org/wiki/display/AST/Macros
    ...at...
    Calling Macro with arguments
    ...where the Argument from the calling Channel/Context is outputed in: Verbose()

    Long story short: You have to change your Macro to check the Argument

    [macro-fanvil]
    exten => s,1,NoOp(catch: callerid: ${CALLERID(num)} - exten ${ARG1}- ${CHANNEL})
    ;exten => _131,n,Goto(receive)
    exten => s,n,GotoIf($[${ARG1} = 131]?receive)
    exten => s,n,GotoIf($[${CALLERID(num)} = 131]?:iscalling)
    exten => s,n(iscalling),NoOp(alzachiamante: ${CALLERID(num)} - ${CHANNEL})
    exten => s,n,Set(VOLUME(RX)=10)
    exten => s,n,MacroExit
    exten => s,n(receive),NoOp(alzaricevente: ${CALLERID(num)} - ${CHANNEL})
    exten => s,n,Answer()
    exten => s,n,Set(VOLUME(TX)=10)
    exten => s,n,MacroExit
    

    ...and call it with Argument: Macro(fanvil,s,1,(${EXTEN}))