Asterisk DO-NOT-CALL list generator

As a telecom engineer for a company that does telesales (yes, I know, I've gone over to the dark side of the force) we have to honor requests from people we call when we're asked not to call them.

We used to send people who call us to make this request to a voicemail box. They would leave their phone number (well, most times. sometimes they just scream at us) and we would listen to the message to create a database of phone numbers along with the dates the callers made their request. It was a very manual process, and when the caller didn't co-operate and leave their number, or when someone makes a transcription error, calls continue to annoy people.

This is an uber simple extensions.conf file that collects digits of a phone number from a caller, and stores them in a file with the date of the call.

The sound files called greet-and-enter, and confirm are just concatenated sound files. All of the sound files used are available in the various standard sound file packages, except area-code. That was just a clipped part of another sound file that has the words "area code" in it.

To retrieve the file, we just added ftp to the Asterisk server, and an ftp routine that runs on another machine collects the file weekly. It also archives last weeks file to another directory.

Please excuse any obviously stupid methods I've employed. I don't get to play with Asterisk as much as I'd like, so I may not be up on the latest methods for coding .conf files. Yes, I know, each routine could have been it's own context. But like I said, this was meant to be ultra simple to implement.

;  Set a few timeouts to keep the system from waiting for callers indefinitely.
exten => s,1,DigitTimeout(6)
exten => s,2,ResponseTimeout(6)
;  Answer the call, then wait one second before playing a greeting.
;  Waiting keeps the front end of the greeting playback from getting
;  clipped off.
exten => s,3,Answer()
exten => s,4,Wait(1)
exten => s,5,Playback(thank-you-for-calling,s)
;  Create a variable to check when looping through the collect digits routine.
;  Increment the digit each time to limit the number of times through
;  the collect digit routine to only three loops.  Set the variable
;  to 0 to give callers three more chances if necessary. 
exten => s,6,SetVar(dialanything=0)
exten => s,7,SetVar(dialanything=$[${dialanything} + 1])
;  Check to see if we've been through the collect
;  digits loop three times already.  If this is the fourth trip, 
;  branch to a "sorry" message.
exten => s,8,GotoIf($[${dialanything} = 4]?31)
;  We want a 10 digit phone number, but collect up to 11 digits.  
;  If a caller enters 11 digits, the # key is ignored. 
exten => s,9,Read(dncdigits,greet-and-enter,11,s)
;  Give callers a with touch tone pads in the handset of their phone
;  a chance to return the phone to their ear before beginning to speakback
;  the entered digits or error messages.
exten => s,10,Wait(1.8)
;  Before we speakback the entered digits, check them over.
;  If there's less than ten digits or no digits, go back and
;  ask for the phone number again.  (Limited to three loops)
exten => s,11,GotoIf($[${LEN(${dncdigits})} < 10]?7)
;  If there's 10 digits, continue normally.
exten => s,12,GotoIf($[${LEN(${dncdigits})} = 10]?15)
;  If there's 11 digits entered, assume that the caller entered
;  a 1 before their phone number, and strip it off before 
;  continuing.
exten => s,13,GotoIf($[${LEN(${dncdigits})} = 11]?14:15)
exten => s,14,SetVar(dncdigits=${dncdigits:1})
;  Check to see if the digits entered match a North American
;  number scheme.  NXX-NXX-XXXX.  If not, branch to a message
;  to inform the caller that they have entered an unrecognized
;  number.
exten => s,15,GotoIf($[${dncdigits:0:1} = 1]?29)
exten => s,16,GotoIf($[${dncdigits:0:1} = 0]?29)
exten => s,17,GotoIf($[${dncdigits:3:1} = 1]?29)
exten => s,18,GotoIf($[${dncdigits:3:1} = 0]?29)
;  Check for an all asterisks entry.  SQL searches would match 
;  any database entry to this, and erase the entire database,
;  instead of an individual entry.
exten => s,19,GotoIf($[${dncdigits} = **********]?29)
;  Future use "command code".  Can call a reboot routine,
;  or any other automated task.  Currently plays system 
;  date and time when entered.
exten => s,20,GotoIf($[${dncdigits} = 9119111111]?35)
;  Speakback digits entered.  Label the area code digits
;  and pause between the area code and exchange, and again
;  between the exchange and extension for a more natural  
;  sounding speakback of the phone number.
;  When finished speaking, branch to the confirmation routine.
exten => s,21,Playback(you-entered,s)
exten => s,22,Playback(area-code,s)
exten => s,23,Saydigits(${dncdigits:0:3})
exten => s,24,Wait(.5)
exten => s,25,Saydigits(${dncdigits:3:3})
exten => s,26,Wait(.5)
exten => s,27,Saydigits(${dncdigits:6:4})
exten => s,28,Goto(37)
;  Play message to inform the caller they have entered a number
;  that does not match the NXX-NXX-XXXX format.  Send them back
;  through the collect digits routine to try again.
exten => s,29,Playback(that-is-not-rec-phn-num,s)
exten => s,30,Goto(6)
;  Play these messages if the caller has been through the collect
;  digits routine three consecutive times and has not entered 
;  at least 10 digits any of those times, then hangup the line.
exten => s,31,Playback(sorry-youre-having-problems,s)
exten => s,32,Playback(please-hang-up-and-try-again,s)
exten => s,33,Playback(goodbye,s)
exten => s,34,Hangup()
;  Play system date and time.  More of a place holder than anything else.
exten => s,35,Datetime()
exten => s,36,Hangup()
;  Play a prompt and collect one digit to confirm the digits 
;  the caller entered.  Any key pressed, other than 1, sends the caller 
;  back through the collect digits routine to try again.
;  Loop indefinitely playing the caller entered digits and 
;  asking for confirmation each time through the loop.  
;  (This could be limited to three loops as well.)
exten => s,37,Read(correct,confirm,1,s)
exten => s,38,GotoIf($[${LEN(${correct})} = 0]?21)
exten => s,39,GotoIf($[${correct} = 1]?40:6)
;  If the caller presses 1, touch the data file, (to ensure it exists)
;  then store the digits entered and todays date in the data file in 
;  the format NNNNNNNNNNYYYYMMDD, where NNNNNNNNNN is the caller entered
;  digits, YYYY is the year of the entry, MM is the month, and DD is todays
;  day.
exten => s,40,System(touch /var/log/asterisk/dnc/dncvru.txt)
exten => s,41,System(echo "${dncdigits}${TIMESTAMP:0:8}" >> /var/log/asterisk/dnc/dncvru.txt)
;  Pause to give callers a with touch tone pads in the handset of their phone
;  a chance to return the phone to their ear before beginning to playback
;  the thank you for calling message.
;  Thank the caller, say goodbye, and hangup.
exten => s,42,Wait(1.8)
exten => s,43,Playback(thank-you-for-calling,s)
exten => s,44,Playback(goodbye,s)
exten => s,45,Hangup()


This one deletes data from your call list rather than maintaining another list:

exten => s,1,Flite(Hello enter your ten digit phone number followed by pound)
exten => s,n,Read(dncdigits,,11,,3)
exten => s,n,Goto(${dncdigits},1)
exten => s,n,Hangup
exten => _X.,1,Flite(that number is not recognized please try again)
exten => _X.,n,Goto(s,1)
exten => _NXXNXXXXXX,1,Flite(you enered area code)
exten => _NXXNXXXXXX,n,SayDigits(${EXTEN:0:3})
exten => _NXXNXXXXXX,n,Wait(.5)
exten => _NXXNXXXXXX,n,SayDigits(${EXTEN:3:3})
exten => _NXXNXXXXXX,n,Wait(.5)
exten => _NXXNXXXXXX,n,SayDigits(${EXTEN:6:4})
exten => _NXXNXXXXXX,n,Flite(confirm by pressing one)
exten => _NXXNXXXXXX,n,Read(correct,,1,,3)
exten => _NXXNXXXXXX,n,GotoIf($["${correct}x" != "1x"]?s,1)
exten => _NXXNXXXXXX,n,MYSQL(Clear ${resultid})
exten => _NXXNXXXXXX,n,MYSQL(Query resultid ${connid} SELECT\ number\ FROM\ TABLE\ WHERE\ SUBSTRING(number\,-10\,10)=${EXTEN})
exten => _NXXNXXXXXX,n,MYSQL(Fetch fetchid ${resultid} num)
exten => _NXXNXXXXXX,n,MYSQL(Clear ${resultid})
exten => _NXXNXXXXXX,n,GotoIf($["${fetchid}x" = "0x"]?notfound)
exten => _NXXNXXXXXX,n,MYSQL(Query resultid ${connid} DELETE\ FROM\ TABLE\ WHERE\ number=${num})
exten => _NXXNXXXXXX,n,Flite(your number has been deleted)
exten => _NXXNXXXXXX,n,Goto(end)
exten => _NXXNXXXXXX,n(notfound),Flite(that number is not found)
exten => _NXXNXXXXXX,n(end),Flite(thanks for calling)
exten => _NXXNXXXXXX,n,Hangup
exten => h,1,GotoIf(${ISNULL(${connid})}?:$[${PRIORITY}+2])
exten => h,n+1,MYSQL(Clear ${resultid})
exten => h,n,MYSQL(Disconnect ${connid})

See also

34999 views strong.

Created by: dufus, Last modification: Thu 04 of Nov, 2010 (06:36 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+