The thing i like the most about Asterisk is how flexible the dialplan is, and specifically how much creative you can get for dealing with undesired callers.
I use a database to store the call treatment rules and run a lookup query for each incoming call. If a number or caller name matches a rule, it takes the appropriate action for that call.
The database table
The caller_name and caller_num columns are used as regex expression to match the caller phone number and name. You can define either of them or both.
Here are examples of rule syntax :
401[0-9]{7} will match all numbers beginning with the area code 401.
4015551125 will match a single number.
401 will match any numbers containing 401. e.g. (555) 555-0401
.* will match all numbers
The action column contains the action to take if the incoming call matche this rule.
Extension is optional. It defines to which user extension this rules applies to.
Query
Paste the following lines in func_odbc.conf :
You can run the query from the dialplan by using :
Dialplan
This is an excerpt from my dialplan as an example. On an incoming call, the dialplan execute the lookup query. If the number doesn’t match any rules, the call is processed as normal. Otherwise, it jumps to the label treatment- followed by the acion. e.g. treatment-busy. If the label does not exists, the call is then proccessed as usual.