tl;dr
Remove first three lines from your dialplan and add the following line to your dialplan to block all callers with numbers beginning with "88":
exten => _X./_88.,1,Goto(blacklisted,s,1)
, so your dialplan looks like this:
[default]
exten => _X.,1,Dial(SIP/8.8.8.8/${EXTEN})
exten => _X./_88.,1,Goto(blacklisted,s,1)
[blacklisted]
exten => s,1,Wait(9)
More details
Approach
According to Asterisk Pattern Matching you can define your exten pattern considering the Caller ID.
Write your dialplan
Since your requirement is to blacklist particular Caller ID numbers (in your case numbers starting with "88"), you could add the following line to your context:
exten => _X./_88.,1,Goto(blacklisted,s,1)
, so your extensions.conf looks as shown above.
Reload your dialplan
Type dialplan reload
on your asterisk cli:
asthost*CLI> dialplan reload
Check your dialplan
Type dialplan show
on your asterisk cli:
asthost*CLI> dialplan show
[ Context 'default' created by 'pbx_config' ]
'_X.' (CID match '_88.') => 1. Goto(blacklisted,s,1) [extensions.conf:3]
'_X.' => 1. Dial(SIP/8.8.8.8/${EXTEN}) [extensions.conf:2]
[ Context 'blacklisted' created by 'pbx_config' ]
's' => 1. Wait(9) [extensions.conf:5]
Test your dialplan
For testing, you should be able to manipulate the Caller ID for incoming calls. Start a call from your SIP endpoint or originate a call via callfiles and local channels. As a shortcut, you can generate the contents of the callfile and send it to asterisk's outgoing spool directory by running the echo
linux shell command from the asterisk cli.
Don't forget to set verbose level to 3, so you can see the dialplan output.
asthost*CLI> core set verbose 3
Console verbose was OFF and is now 3.
asthost*CLI> !echo 'Channel: Local/12345@default\nCallerid: "someone" <880123456>\nWaitTime: 20\nApplication: Hangup\n' > /var/spool/asterisk/outgoing/call.file
-- Attempting call on Local/12345@default for application Hangup() (Retry 1)
-- Called 12345@default
-- Executing [12345@default:1] Goto("Local/12345@default-00000023;2", "blacklisted,s,1") in new stack
-- Goto (blacklisted,s,1)
-- Executing [s@blacklisted:1] Wait("Local/12345@default-00000023;2", "9") in new stack
Considerations
Keep in mind that the caller can provide his or her number in different number formats like "+88...", so your Caller ID filter "_88." will not match.