+1 for that.
Basically dialplan hooks.
- Incoming call hook on the Trunk level
- Pre extension dial hook
- Pre outgoing call hook
These hooks can look something like:
;Incoming calls hook for Trunk 1
same => n,GoSubIf($[${DIALPLAN_EXISTS(sub-incoming-${TRUNK_ID}-hook,${EXTEN},1)}]?sub-incoming-${TRUNK_ID}-hook,${EXTEN},1)
;General incoming calls hook
same => n,GoSubIf($[${DIALPLAN_EXISTS(sub-incoming-hook,${EXTEN},1)}]?sub-incoming-hook,${EXTEN},1)
;Pre extension dial hook
same => n,GoSubIf($[${DIALPLAN_EXISTS(sub-local-predial-hook,s,1)}]?sub-local-predial-hook,s,1)
;External outgoing calls hook
same => n,GoSubIf($[${DIALPLAN_EXISTS(sub-out-predial-hook,s,1)}]?sub-out-predial-hook,s,1)
What it does is, that is that context and dialplan exists it sends the call there, otherwise, it just continues with the call.
So to intercept all incoming calls, it would look like this:
[sub-incoming-hook]
exten => _NXXNXXXXXX,1,Noop(Checking if the caller ID is backlisted)
same => n,Set(block=${SHELL(curl https://api.myblackist.com/number/${CALLERID(num)})})
same => n,GoToIf($["${block}"="true"]?block-number,s,1)
same => n,Return()
This would basically check the caller ID if it is blocked via a API and handle accordingly, if it is not blocked then it would resume the dialplan.