I was already using the macro-dialout-trunk-predial-hook to jump out of
macro-dialout-trunk and insert a Progress Announcement on calls being routed out on GSM Cellphone Trunks, so I decided to try and add the Trunk Rotary Hunting facility by using the same route.
I used gbrook’s code posted in the Trixbox forum as the nuts and bolts and came up with the following macro which so far seems to be performing exactly as I want it to:
[macro-dialout-trunk-predial-hook]
;
; This macro does two things (1) recognises Portech GSM Gateway trunks and inserts a call progress
; announcement (2) recognises calls to trunk groups where each trunk has a separate pool of free
; minutes and alternates outbound calls between trunks to approximately equalize usage across
; all the trunks in the group.
;
; To insert the Progress Announcement edit line 1 to accommodate the trunk name and for Alternating
; Trunk Selection edit line 2 to accommodate the base name of the trunk group and it is necessary
; to setup trunks in the Web GUI bearing the trunk group base name plus sequential line numbers like
; XXXXXXXXXX_1, XXXXXXXXXX_2 etc. It is necessary to edit the variable NUMBER_TRUNKS to the
; actual number of trunks in the group. Access to the trunk group is through an Outbound Route
; set up in the Web GUI.
;
exten => s,1,Gotoif($["${OUT_${DIAL_TRUNK}:0:7}" = “SIP/700”]?callprogress)
exten => s,n,Set(TRUNK_GROUP=${OUT_${DIAL_TRUNK}:0:15})
exten => s,n,Gotoif($["${TRUNK_GROUP}" = “IAX2/XXXXXXXXXX”]?rotaryhunting)
exten => s,n,MacroExit()
exten => s,n,NoOp(Start Call Progress - Using trunk: ${OUT_${DIAL_TRUNK}} Caller: ${REALCALLERIDNUM})
exten => s,n(callprogress),NoOp(Playing Progress Announcement)
exten => s,n,Playback(custom/cell-phone-please-wait,noanswer)
exten => s,n,MacroExit()
exten => s,n(rotaryhunting),NoOp(Start Alternating Hunt - Using group: ${TRUNK_GROUP} Caller: ${REALCALLERIDNUM})
exten => s,n,Set(NUMBER_TRUNKS=2)
exten => s,n(loop),SetGlobalVar(NEXTLINE=$[${NEXTLINE} + 1])
exten => s,n,Gotoif($[${NEXTLINE} <= ${NUMBER_TRUNKS}]?noreset)
exten => s,n,SetGlobalVar(NEXTLINE=1)
exten => s,n(noreset),Dial(${TRUNK_GROUP}_${NEXTLINE}/${OUTNUM},300,${DIAL_TRUNK_OPTIONS})
exten => s,n,NoOp(Trunk busy retrying)
exten => s,n,Set(NUMBER_TRUNKS=$[${NUMBER_TRUNKS} - 1])
exten => s,n,NoOp(Tries left: ${NUMBER_TRUNKS})
exten => s,n,GotoIf($[${NUMBER_TRUNKS} > 0]?loop)
exten => s,n,NoOp(Run out of trunks)
exten => s,n,Playback(all-circuits-busy-now,noanswer)
exten => s,n,NoOp(Exiting Alternating Hunt)
exten => s,n,Macro(hangupcall,)
exten => h,1,Macro(hangupcall,)
;
; end macro-dialout-trunk-predial-hook
Hope this may be of help. As an aside I have posted a feature request to add outgoing trunk hunting methods to the Outbound Route module.