I realized after posting the above, that if you are going to add and delete using star-codes, you proably want to be able see what is in the blacklist using star-codes.
So I added a 4th star-code (*73) which, when used, will tell the caller how many numbers are blacklisted and then playback the list of actual CallerIDs that are in the blacklist. (And yes, the user can hang up any time during the playback if they have heard enough … )
In the xivo-extrafeatures.conf file in /etc/asterisk/extensions_extra.d I now have
;
; These contexts work with the new star-codes added in /etc/asterisk/extensions_extra.d/xivo-extrafeatures.conf
; *70 = Add the last caller's CallerID Number to the blacklist
; *71 = Add a number to the blacklist, by entering the number through the phone's keypad
; *72 = Delete a number from the blacklist, by entering the number through the phone's keypad
; *73 = Read back over the phone the count of numbers blacklisted and then read each number blacklisted
;
; The additions to the global incall context [xivo-subrgbl-did] will do two things:
; 1) Store the CallerdID Number of the current caller to the system
; (which will be used by the *70 star-code to blacklist that number if *70 is used
; 2) Use a built-in Wazo application to check the current caller's CallerID Number to see if it is in the blacklist
; and if so, play a (silly, zombie apocalypse) message and hangup on the caller
;
; The remaining contexts are to enable the functionality of the new star-codes
;
[xivo-subrgbl-did]
exten => s,1,NoOp(Store the CallerID of the caller - replaced by the next caller - in the Asterisk database)
same => n,Set(DB(LastCaller/CallerIDnum)=${CALLERID(num)})
same => n,NoOp(Check incoming calls to see if the caller is in the blacklist - if so, play nonsense and hangup)
same => n,GotoIf(${BLACKLIST()}?blacklisted)
same => n,Return()
same => n(blacklisted),Playback(zombies)
same => n,Hangup()
;
[blacklist-manage-add-last]
exten => blacklist-add-last-number,1,NoOp(Add the number of the last CallerID to the blacklist)
same => n,Answer()
same => n,Wait(1)
same => n,Set(TIMEOUT(absolute)=60)
same => n,Set(TIMEOUT(response)=10)
same => n,Set(TIMEOUT(digit)=10)
same => n,Set(LastCallerIDnum=${DB(LastCaller/CallerIDnum)})
same => n,GotoIf($[ $[ "${LastCallerIDnum}" = "" ] | $[ "${LastCallerIDnum}" = "unknown" ] ]?blacklist-error,InvalidNumber,1)
same => n,Playback(privacy-to-blacklist-last-caller&telephone-number)
same => n,SayDigits(${LastCallerIDnum})
same => n,Background(if-correct-press&digits/1)
same => n,WaitExten()
exten => t,1,NoOp(The user did not provide any response before the response timeout set above)
same => n,Goto(blacklist-error,SorryBye,1)
exten => i,1,NoOp(The user either waited longer than the digit timeout between key presses or input an invalid number)
same => n,Goto(blacklist-error,SorryBye,1)
exten => T,1,NoOp(The user did not finish the input - press # - before the absolute timeout)
same => n,Goto(blacklist-error,SorryBye,1)
exten => e,1,NoOp(A Catch-all error handler in case the above 3 conditions did not catch the fail)
same => n,Goto(blacklist-error,InvalidNumber,1)
exten => 1,1,NoOp(The user confirmed the number with an acceptable input within the allowed time limit)
same => n,Set(ReasonForBlacklist=Added by star-codes)
same => n,Set(DB(blacklist/${LastCallerIDnum})=${ReasonForBlacklist})
;same => n,SayDigits(${LastCallerIDnum})
same => n,Playback(num-was-successfully&added)
same => n,Hangup
;
[blacklist-manage-add]
exten => blacklist-add-number,1,NoOp(User manually adds a new number to the blacklist)
same => n,Answer()
same => n,Wait(1)
same => n,Set(TIMEOUT(absolute)=60)
same => n,Set(TIMEOUT(response)=10)
same => n,Set(TIMEOUT(digit)=10)
same => n,Read(IncomingCallerNumber,enter-num-blacklist&then-press-pound,0,s,1,)
same => n,GotoIf($[ ${READSTATUS} != OK ]?blacklist-error,InvalidNumber,1)
same => n,SayDigits(${IncomingCallerNumber})
same => n,Background(if-correct-press&digits/1)
same => n,WaitExten()
exten => t,1,NoOp(The user did not provide any response before the response timeout set above)
same => n,Goto(blacklist-error,SorryBye,1)
exten => i,1,NoOp(The user either waited longer than the digit timeout between key presses or input an invalid number)
same => n,Goto(blacklist-error,SorryBye,1)
exten => T,1,NoOp(The user did not finish the input - press # - before the absolute timeout)
same => n,Goto(blacklist-error,SorryBye,1)
exten => e,1,NoOp(A Catch-all error handler in case the above 3 conditions did not catch the fail)
same => n,Goto(blacklist-error,InvalidNumber,1)
exten => 1,1,NoOp(The user confirmed the number with an acceptable input within the allowed time limit)
same => n,Set(ReasonForBlacklist=Added by star-codes)
same => n,Set(DB(blacklist/${IncomingCallerNumber})=${ReasonForBlacklist})
;same => n,SayDigits(${IncomingCallerNumber})
same => n,Playback(num-was-successfully&added)
same => n,Hangup
;
[blacklist-manage-delete]
exten => blacklist-delete-number,1,NoOp(User manually deletes an existing number from the blacklist)
same => n,Answer()
same => n,Wait(1)
same => n,Set(TIMEOUT(absolute)=60)
same => n,Set(TIMEOUT(response)=10)
same => n,Set(TIMEOUT(digit)=10)
same => n,Read(CallerNumberToDelete,entr-num-rmv-blklist&then-press-pound,0,s,1,)
same => n,GotoIf($[ ${READSTATUS} != OK ]?blacklist-error,InvalidNumber,1)
same => n,SayDigits(${CallerNumberToDelete})
same => n,GotoIf($[${DB_EXISTS(blacklist/${CallerNumberToDelete})}]?:blacklist-error,InvalidNumber,1)
same => n,Background(if-correct-press&digits/1)
same => n,WaitExten()
exten => t,1,NoOp(The user did not provide any response before the response timeout set above)
same => n,Goto(blacklist-error,SorryBye,1)
exten => i,1,NoOp(The user either waited longer than the digit timeout between key presses or input an invalid number)
same => n,Goto(blacklist-error,SorryBye,1)
exten => T,1,NoOp(The user did not finish the input - press # - before the absolute timeout)
same => n,Goto(blacklist-error,SorryBye,1)
exten => e,1,NoOp(A Catch-all error handler in case the above 3 conditions did not catch the fail)
same => n,Goto(blacklist-error,InvalidNumber,1)
exten => 1,1,NoOp(The user confirmed the number with an acceptable input within the allowed time limit)
same => n,Set(VarValue=${DB_DELETE(blacklist/${CallerNumberToDelete}}))
same => n,GotoIf($[${EmptyCheck} == "" ]?blacklist-error,InvalidNumber,1)
;same => n,SayDigits(${CallerNumberToDelete})
same => n,Playback(num-was-successfully&removed)
same => n,Hangup
;
[blacklist-manage-list]
exten => blacklist-list-numbers,1,NoOp(Read the numbers stored in the blacklist over the phone)
same => n,Answer()
same => n,NoOp(Get the number of entries in the blacklist)
same => n,Set(BlacklistArray=${DB_KEYS(blacklist)})
same => n,Set(NumberInBlacklist=0)
same => n(CountLoopStart),While( $[ $["${SET(BlacklistEntry=${SHIFT(BlacklistArray)})}" != ""] ] )
same => n,Set(NumberInBlacklist=$[ ${NumberInBlacklist} + 1 ] )
same => n,NoOp(Current count of Number in Blacklist is ${NumberInBlacklist})
same => n(CountLoopEnd),EndWhile()
same => n,Playback(privacy-blacklisted&the-num-i-have-is)
same => n,SayNumber(${NumberInBlacklist})
same => n,GotoIf($[${NumberInBlacklist} == 0 ]?Hangup)
same => n,Wait(.5)
same => n,NoOp(Speak each number in the blacklist)
same => n,Playback(for-a-list-of&privacy-blacklisted)
same => n,Set(BlacklistArray=${DB_KEYS(blacklist)})
same => n,Set(LoopCounter=0)
same => n(LoopStart),While( $[ ${LoopCounter} < ${NumberInBlacklist} ] )
same => n,Set(LoopCounter=$[ ${LoopCounter} + 1 ] )
same => n,Wait(.5)
same => n,SayNumber(${LoopCounter})
same => n,Playback(is)
same => n,Wait(.5)
same => n,SET(BlacklistEntry=${SHIFT(BlacklistArray)})}
same => n,SayDigits(${BlacklistEntry})
same => n(LoopEnd),EndWhile()
same => n(Hangup),Hangup
;
[blacklist-error]
exten => InvalidNumber,1,NoOp(The user tried to add delete an invalid number)
same => n,Playback(pm-invalid-option)
same => n,Goto(SorryBye,1)
exten => SorryBye,1,NoOp(Play apology and hangup)
same => n,Playback(sorry-youre-having-problems&goodbye)
same => n,Hangup
And of course, the instructions would need to be updated to include the *73 star-code