Search code examples
asteriskpbx

Asterisk & Freepbx : Multiple Day Night Toggles?


I am in a situation where I often need to change the active call flow control (which can only be one..right?). I find that netsting call flow controls is very unhandy if you have 4 different scenarios. So what I would like to do is to create an 4 different extensions that set the appropriate call flow as the inbound route destination.

To make an example: I have

  • CALL FLOW NR 1
  • CALL FLOW NR 2
  • CALL FLOW NR 3
  • CALL FLOW NR 4

I would like to create:

  • extension *881 -> Toggles Call Flow nr 1 and sets it as destination of the inbound route
  • extension *882 -> Toggles Call Flow nr 2 and sets it as destination of the inbound route
  • extension *883 -> Toggles Call Flow nr 3 and sets it as destination of the inbound route
  • extension *884 -> Toggles Call Flow nr 4 and sets it as destination of the inbound route

Is something like that possible? If so...how would you achieve it? My system is based asterisk 11 and freepbx 2.11. Thank you in advance for your time and effort.


Solution

  • I figured it out

    edit /etc/asterisk/extensions_custom.com and paste the following

    [from-internal-custom]
    include => enable-switch
    
    [check-active-switch]
    exten => s,1,NoOp("This context loops through all the switches and checks which one is ON. Than it follows its destination")
    exten => s,n,GoSub(sub-get-nr-of-switches,s,1)
    exten => s,n,Set(nrofs=${GOSUB_RETVAL})
    exten => s,n,Set(i=0)
    exten => s,n,Set(default-dest=app-daynight,${switchnr},1)
    exten => s,n,Set(switchnr="NULL")
    exten => s,n,While($[$[${i} < ${nrofs}] & $[${switchnr} = "NULL"]])
    exten => s,n,Set(switchnr=${IF($["${DB(DAYNIGHT/C${i})}" = "NIGHT"]?${i}:"NULL")})
    exten => s,n,Set(i=$[${i} + 1])
    exten => s,n,EndWhile
    exten => s,n,GotoIf($[${switchnr}!="NULL"]?app-daynight,${switchnr},1:${default-dest})
    exten => s,n,Hangup()
    
    [sub-get-nr-of-switches]
    exten => s,1,Set(nr_of_s=0)
    exten => s,n,Set(exten_state="NOT_ACQUIRED")
    exten => s,n,While($[${exten_state}!=0])
    exten => s,n,Set(exten_state=$[${VALID_EXTEN(app-daynight,${nr_of_s},1)}])
    exten => s,n,NoOp(Exten nr ${nr_of_s} of app-daynight is ${exten_state})
    exten => s,n,Set(nr_of_s=${IF($[${exten_state}=1]?$[${nr_of_s}+1]:${nr_of_s})})
    exten => s,n,EndWhile
    exten => s,n,NoOp(${nr_of_s} switches found)
    exten => s,n,Return(${nr_of_s})
    
    [enable-switch]
    exten =>_*20X,1,NoOp("Abilita Switch selezionato e disabilita altre")
    same => n,GoSub(sub-get-nr-of-switches,s,1)
    same => n,Set(nrofs=${GOSUB_RETVAL})
    same => n,Set(switchtoactivate=${EXTEN:3})
    same => n,NoOp(Activated Switch nr ${switchtoactivate})
    same => n,Set(i=0)
    same => n,While($[${i}<${nrofs}])
    same => n,Set(DB(DAYNIGHT/C${i})=DAY)
    same => n,Set(i=$[${i}+1])
    same => n,EndWhile
    same => n,Set(freepbx_toggle_dest=*28${switchtoactivate})
    same => n,Goto(app-daynight-toggle,${freepbx_toggle_dest},1)
    same => n,Hangup
    

    Next go to freepbx and create a custom destination -> check-active-switch,s,1 and set it as destination of the inbound route