Attached is the latest version of my blacklist and anonymous caller handling
in my dialplan which I thought might be useful to others.
This implements Privacy Manager to let an anonymous caller leave an
introductory message for callee to listen to and decide whether to accept
the call or not.

Also handles blacklisted callers with all the default actions available
through the AstLinux web interface... No Answer, Zapateller, Voicemail.
Requires Asterisk EXTRA_SOUNDS_EN  -- either manually added to your astlinux
system, or custom compiled into your Astlinux build (you must use GSM
versions of both extra and core sounds for them to fit in a custom build).

Tested on astlinux trunk (pre 0.7).  For explanation of the code,
see embedded comments.

David.
[globals]
; Append to your [globals] section in extensions.conf
; These are examples only, change to suit your specific purposes.
PRIVACY_MGR_VOICEMAIL = voicemenu-custom-3
PRIVACY_MGR_EXTEN = local/6...@ringgroups
PRIVACY_MGR_PIN = 1234
PRIVACY_MGR_NAME = Caller Name

[default]
; your inbound context
exten = _X.,1,Gosub(check-private,s,1)
exten = _X.,n,Goto(where-ever-you-normally-go,s,1)
exten = s,1,Gosub(check-private,s,1)
exten = s,n,Goto(where-ever-you-normally-go,s,1)

[check-private]
exten = s,1,NoOp(PrivacyManager)
; exten = s,n,Log(NOTICE,${CALLERID(num)})
; Subroutine to check callerID number against whitelist, blacklist, anonymous 
callers
; and to implement Privacy Manager.  Blacklist actions; No Answer(0), 
Zapateller(1),
; Voicemail(2) and Privacy Manager(3) are handled here.  Whitelist actions 
should be
; handled elsewhere in dialplan.
; Constants must be set in [globals] section of this file...
;    PRIVACY_MGR_VOICEMAIL = context to handle voicemail, will branch to s,1
;    PRIVACY_MGR_EXTEN = internal extension to ring, eg. local/6...@ringgroups
;    PRIVACY_MGR_PIN = 4-digit PIN code to bypass Privacy Manager
;    PRIVACY_MGR_NAME = name to set Caller ID to if PIN entered
; If caller presses 0 (zero) during prompt to leave name, then they can enter 
PIN to bypass
; leaving an introduction message. Useful for family members.
;
; First lookup number in asterisk DB for a Caller ID name.
exten = s,n,Set(CALLERID(name)=${IF(${DB_EXISTS(cidname/${CALLERID(num)})} ? 
${DB_RESULT} : ${CALLERID(name)} )} )
; Now check against whitelist.
exten = s,n,GotoIf(${DB_EXISTS(whitelist/${CALLERID(num)})}?onwhitelist)
; Not on whitelist, check it against blacklist
exten = s,n,GotoIf(${DB_EXISTS(blacklist/${CALLERID(num)})}?onblacklist)
; Not on blacklist either, check Caller ID number for anonymous conditions...
; If all zeros (with or without international dialing + sign) then caller is 
anonymous. 
; If Caller ID is not a number at least 4 digits long (with or without + sign)
; then caller is assumed to be anonymous. Alphabetic Caller ID "numbers"
; will therefore be considered anonymous. Common numbers for anonymous callers
; are: "asterisk, unknown, anonymous, private, unavailable" which may be upper, 
lower
; or mixed case. The regular expression catches everything non-numeric.
; If you want to permit a specific non-numeric Caller ID "number" add it to 
whitelist.
exten = s,n,GotoIf($[${REGEX("^[+]?0+$" ${CALLERID(num)})} = 1]?unknown)
exten = s,n,GotoIf($[${REGEX("^[+]?[0-9]{4\,}$" ${CALLERID(num)})} != 
1]?unknown)
; Caller ID looks good. Indicate ringing and "return" to continue with dialplan 
processing.
exten = s,n(onwhitelist),Ringing()
exten = s,n,Return() 
; If blacklist says Zapateller (1), then don't even indicate Ringing
exten = s,n(onblacklist),GotoIf($[${DB_RESULT}=1]?zap)
; For everything else, send Ringing signal
exten = s,n,Ringing()
; If blacklist says No Answer (0), then branch to handle that
exten = s,n,GotoIf($[${DB_RESULT}=0]?noanswer)
; Else let ring tone sound for two seconds and answer the call
exten = s,n,Wait(2)
exten = s,n,Answer()
; If blacklist says Voicemail (2), then branch to handle that
exten = s,n,GotoIf($[${DB_RESULT}=2]?${PRIVACY_MGR_VOICEMAIL},s,1)
; If blacklist says Privacy Manager (3), then branch to handle that
exten = s,n,GotoIf($[${DB_RESULT}=3]?blacklistpriv)
; No answer action, let it ring for 30 seconds then hangup
exten = s,n(noanswer),wait(30)
exten = s,n,Hangup()
; Zapatteler action, send tones then hangup
exten = s,n(zap),Zapateller(answer)
exten = s,n,Playback(discon-or-out-of-service)
exten = s,n,Hangup()
; Anonymous caller. Set Caller ID name to "Privacy Manager", ring for two 
seconds, 
; answer the call and invite caller to record their name to introduce 
themselves.
exten = s,n(unknown),Set(CALLERID(name)="Privacy Manager")
exten = s,n,Ringing();
exten = s,n,Wait(2)
exten = s,n,Answer()
; While playing message in background, caller can press a key. We handle 0 
(zero).
exten = s,n(blacklistpriv),Background(privacy-unident&vm-rec-name,m)
exten = s,n,Wait(1)
exten = s,n,Record(/tmp/asterisk-stranger:gsm,4,5)
exten = s,n,Background(priv-introsaved,m)
; Caller has recorded a message. Dial inbound extension. If extension answers 
then pass
; control to macro-call-screen that will inform callee of the Anonymous caller.
exten = 
s,n,Dial(${PRIVACY_MGR_EXTEN},20,gmM(call-screen^/tmp/asterisk-stranger))
; If we get here then Dial() failed and macro-call-screen did not execute.
; If it is a case of NOANSWER then send anonymous caller to an IVR menu with
; more options (which may include leaving a voicemail for example).
exten = s,n,GotoIf($[${DIALSTATUS}=NOANSWER]?${PRIVACY_MGR_VOICEMAIL},s,1)
exten = s,n,Hangup()
; Handle invalid key pressed
exten = i,1,Playback(call-terminated&goodbye)
exten = i,n,Hangup()
; Handle timeout situation
exten = t,1,Playback(call-terminated&goodbye)
exten = t,n,Hangup()
; Caller interrupted prompt to record their name by pressing 0 (zero)
; This is an escape to let caller authenticate themselves with a PIN, thereby
; bypassing need to record their name. Caller ID is set to known caller
; and we return to continue with dialplan.
exten = 0,1,Authenticate(${PRIVACY_MGR_PIN},,4)
exten = 0,n,Set(CALLERID(name)="${PRIVACY_MGR_NAME}")
exten = 0,n,Return() 

[macro-call-screen]
; This macro executes when an internal extension answers a call from an 
anonymous caller
; handled by check-private subroutine (Privacy Manager)
exten = s,1,Set(TIMEOUT(response)=5)
exten = s,n,Background(priv-callpending,m,en,macro-call-screen)
exten = s,n(repeat-screen),Background(${ARG1},m,en,macro-call-screen)  
;playback recording callee made
exten = s,n(repeat-options),Read(ACCEPT-CALL,followme/options,1)
exten = s,n,GotoIf($["${ACCEPT-CALL}" = ""] ?t,1)  ;timeout, no digit pressed
exten = s,n,GotoIf($[${ACCEPT-CALL} = 1] ?call-accepted)
exten = s,n,GotoIf($[${ACCEPT-CALL} = 2] ?call-declined:repeat-options)
; If callee rejects the call they are thanked and the caller is passed onto an 
IVR
; menu with more options, like leaving a voicemail
exten = s,n(call-declined),Playback(privacy-thankyou)
exten = s,n,Set(MACRO_RESULT=GOTO:${PRIVACY_MGR_VOICEMAIL}^s^1)  ;send caller 
to voicemail menu
exten = s,n,MacroExit()
; If callee accepts the call then they are thanked and the macro exits, which 
will
; automatically bridge the caller and callee together.
exten = s,n(call-accepted),Playback(privacy-thankyou)
exten = s,n,MacroExit()  ;call will connect on exit
; Handle timeout situation.
exten = t,1,Playback(connection-timed-out)
exten = t,n,Goto(s,call-declined)
; Handle hangup situation.
exten = h,1,Set(MACRO_RESULT=CONTINUE)  ;on hangup, continue with original 
dialplan
exten = h,n,MacroExit()
; Press 1 to accept the call.
exten = 1,1,Goto(macro-call-screen,s,call-accepted)
; Press 2 to reject the call.
exten = 2,1,Goto(macro-call-screen.s,call-declined)
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Astlinux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/astlinux-users

Donations to support AstLinux are graciously accepted via PayPal to 
[email protected].

Reply via email to