I’m still reviewing the code snippet @dicko wrote, it looks elegant, mine is like its been written by 3 year old, but it works. (at least it does in the situation it came from)
I’ll add this approach is pretty simplistic. It just does a SQL lookup to see if the CLID number entering the IVR has called previously today. If it has, then the code just changes the sound file the caller hears to a different one that you have recorded. It looks to see that there is no blank callerID and make sure it is 10 digits in length (you might need to alter that depending on your needs). Simplistically trying to avoid people with no number getting a special treatment call.
Give it a try, and message if you have questions.
exten => s,n,ExecIf($["${REALCALLERIDNUM}" = ""]?goto(start)) ;don't count people with no number
exten => s,n,ExecIf($[${LEN(${REALCALLERIDNUM})} != 10]?goto(start)) ;if their CLID isn't 10 digits, ignore.
exten => s,n,Set(dblogin=root) ;database username
exten => s,n,Set(dbpass=) ;database password
exten => s,n,Set(DateCheck=${STRFTIME(${EPOCH},,%Y-%m-%d)}) ;get current date YYYY-MM-DD
exten => s,n,MYSQL(Connect connid localhost ${dblogin} ${dbpass} asteriskcdrdb) ;connect to asterisk CDR
exten => s,n,MYSQL(Query resultid ${connid} SELECT * from cdr where clid like "%${REALCALLERIDNUM}%" and calldate like "%${DateCheck}%") ;see if there has been any calls from the same number on today's date (yyyy-mm-dd)
exten => s,n,MYSQL(Fetch fetchid ${resultid} sqlresult) ;get the sql results (if any)
exten => s,n,MYSQL(Clear ${resultid})
exten => s,n,MYSQL(Disconnect ${connid}) ;close database connection
exten => s,n,ExecIf($["${sqlresult}" != ""]?Set(IVR_MSG=custom/FRIENDLYMESSAGE)) ;message to play database detected a call previous in database
Installation
Open up /etc/asterisk/extensions_additional.conf
Find your IVR. It will have a heading name like “IVR-2”
You’ll see a bunch of lines that looks like this:
[ivr-2] ; testIVR
include => ivr-13-custom
include => from-ivr-directory-Disabled
exten => fax,1,Goto(${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)})
exten => s,1,Set(TIMEOUT_LOOPCOUNT=0)
exten => s,n,Set(INVALID_LOOPCOUNT=0)
exten => s,n,Set(IVR_CONTEXT${CONTEXT}=${IVR_CONTEXT})
exten => s,n,Set(_IVR_CONTEXT=${CONTEXT})
############ SNIP ##################################################
exten => h,1,Hangup
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
;–== end of [ivr-2] ==–;
Copy the entire section, then paste it into the bottom of /etc/asterisk/extensions_override_freepbx.conf
Now insert the code I posted up top between these lines as marked below
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(skip),Set(IVR_MSG=custom/YourNormalIVRannoucment)
######INSERT CODE HERE!#############
exten => s,n(start),Set(TIMEOUT(digit)=3)
exten => s,n,ExecIf($["${IVR_MSG}" != ""]?Background(${IVR_MSG}))
exten => s,n,WaitExten(10,)
Change “FRIENDLYMESSAGE” that is my code to be the name of the sound file you want to play instead if it finds a match. No extensions like .wav or anything.
Save your changes
In the command line type in f
asterisk -rx 'core reload'
give it a test!
If you notice a problem, you can easily restore the original file by simply changing the heading IVR heading in the _override_freepbx.conf file from “IVR-2” to “IVR-2 disabled”, save your changes then issue the reload command. That will instantly restore your original config.