Using DialPlans to Send Extension Status to Twilio - Sanity Check

We are using Twilio’s TaskRouter as a front-end Call Queue Manager for incoming calls, but we are using FreePBX/Asterisk as our in-house PBX. When FreePBX extensions make/receive calls we need to let Twilio know wether the user is available to receive a call from the TaskRouter queue. We have currently devised the following dialplans in the extensions_custom.conf file.

The script works, but since I’m new to custom dialplans, I’m looking for recommendations or suggestions on how (if) this may be accomplished in a better way.

Basically, the idea is to send the called and calling extension numbers to a PHP script, which in turn calls a script over on Twilio to change the “worker status” accordingly to “call” or “wrapup”.

Thanks for any insight you may provide.

; Extension -> Extension
; PSTN -> Extention

[macro-dialout-one-predial-hook]
exten => s,1,AGI(twilio_announce.php,${FROMEXTEN},"Call","dialout-one-from")
exten => s,n,AGI(twilio_announce.php,${EXTTOCALL},"Call","dialout-one-to")
exten => s,n,Set(CHANNEL(hangup_handler_push)=hangup-handler,${FROMEXTEN},1)
exten => s,n,Set(CHANNEL(hangup_handler_push)=hangup-handler,${EXTTOCALL},1)
exten => s,n,Return

; Extension -> PSTN

[macro-dialout-trunk-predial-hook]
exten => s,1,AGI(twilio_announce.php,${FROMEXTEN},"Call","dialout-trunk-from")
exten => s,n,Set(CHANNEL(hangup_handler_push)=hangup-handler,${FROMEXTEN},1)
exten => s,n,Return

[hangup-handler]
exten => _X.,1,AGI(twilio_announce.php,${EXTEN},"WrapUp","hangup-handler")
exten => _X.,n,Return