Categories
Blog FreePBX Knowledge Base

Running Subroutines on answer for Queues

Some years ago we wrote a post on running macros on queue answer here. this was very useful for integration with backends, At the time we raised a feature request to get it added to Freepbx, But this never happened.

Now the variable QGOSUB is in the dialplan for freepbx queues, But still there is no way of setting this in a default freepbx installation and it requires a snip-it of custom dialplan that is called from freepbx by a ‘custom destination’ . For example at its simplest the dialplan to set it could be :-

[qmacro-set]
exten => .,1,Noop(ians test) 
exten => .,n,Set(_QGOSUB=ians_routine) 
exten => .,n,Goto(app-daynight,1,1)  

and this sets the variable for all channels in this call, and when the Queue command is run in the default freepbx dialplan

Queue(9471,${QOPTIONS},,${QAANNOUNCE},${QMAXWAIT},${QAGI},,${QGOSUB},${QRULE},${QPOSITION})  

This allows simple or more complicated routines to be run. For example sending an email on answer which was a request we had that caused us to revisit this.

[ians_routine]
exten = s,1,Set(origtime=${EPOCH})
exten = s,n,Noop(${CHANNEL})
exten = s,n,Set(Agent11=${CUT(CHANNEL,@,1)})
exten = s,n,Set(Agent12=${CUT(Agent11,/,2)})
exten = s,n,Noop(${Agent11} , ${Agent12} )
exten = s,n,Set(fulltime=${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)})
exten = s,n,system(echo "There has been a call , Callers Details: ${CALLERID(number)} ,  ${CRM_SOURCE} , Date and Time: ${fulltime} ,  Agent: ${Agent12} ,Timestamp: ${origtime} , Queue Number: ${QUEUENUM} " | mail -s "failed recall at ${fulltime}" email@address.com)
same = n,Return()

If you think that you would like to be able to set this variable in the freepbx gui give it a vote https://issues.freepbx.org/browse/FREEPBX-22274