Iterate through predefined group of numbers and execute macro

Hi All,

Pretty new to FreePBX so bear with me (thanks in advance). I’m making progress and have set up a custom dial plan which at the moment, dials to a single static SIP extension, performs some logic (runs a few macros) and exits. I’d like to repeat this process for a predefined group of numbers, maybe through a “ring group” or queue? alternatively, I could create a static group of numbers in the dial plan, but trying to avoid that so that end user can adjust the group of numbers / extensions via web gui.

Ultimately, the logic would look like this - pseudo code:

group_of_numbers = get group
loop (as long as there’s a number to dial or exit condition not reached)
dial number, run macro
end loop

FreePBX doesn’t really lend itself to the “do while” concept, asterisk has a command “while” along with if and all sorts of math/logic but there is no easy way to extract the while condition items. I suggest you explore the AMI and/or AGI interfaces to asterisk along with the easy to use call.file concept and extract a gui defined ring groups from the mysql asterisk database availing yourself of the FreePBX GUI RG’s (which would supply such items), a simple test of your logic could wrap your derived targets within bash pseudo code:-

for TARGET in $(mysql -Bs -D asterisk -ppassword -e “SELECT REPLACE(grplist,’-’,’ ') FROM ringgroups WHERE grpnum=600”); do
rasterisk -x "originate SIP/localhost/$TARGET application macro yourmacro yourarguments"
done

or an appropriate variation on that

(rasterisk -x ‘core show application Originate’;rasterisk -x ‘core show application macro’)

when that works, then tidy it all up with AMI or call.files or even directly in your dialplan :slight_smile: