I can’t easily post a complete solution, because my system updates the whitelist outside of FreePBX, in an app whose primary purpose is displaying recent calls in a small window, with click-to-call functionality.
However, the basic filtering code was posted in [SOLVED]Inbound routing - #9 by gdesilva .
The overall algorithm is described in Can spam call problems really be solved techically? - VOIP Tech Chat | DSLReports Forums .
Ward Mundy made various changes (some of which I don’t agree with) but posted complete code. See Spam Phone Call Blocker and CNAM Caching for FreePBX – Nerd Vittles .
I hope that at least some of the above is useful.