Neat question and something I’ve devoted some time to for my #FridayFun with FreePBX. Here’s a pretty good start to this problem