Customer Survey
Here is what we use. No special PHP, just a little dialplan. Might useful for someone.
This code will ask a caller questions, then save it to the CDR table of asterisk under "USERFIELD"
It will also send an email to someone with the digits entered.
This demo asks 2 questions.
INSTALLATION
Record your ‘questions’ in system recordings.
This demo uses “question1” and “question2”
Create a thank you message.
My file was saved as “thankyouforyourtime”.
open up /etc/asterisk/extensions_custom.conf
Go to the bottom of the file, paste in the following:
[macro-survey]
exten => s,1,answer()
;this asks the first question (based on your recording file named as "question1") and stores them in variable
exten => s,n(question1),Read(answer1,/var/lib/asterisk/sounds/en/custom/question1,1,,1,2)
exten => s,n,GotoIf($[ ${answer1} < 4 ]?question2:question1)
;this asks the first question (based on your recording named 'question2") and stores them in variable
exten => s,n(question2),Read(answer2,/var/lib/asterisk/sounds/en/custom/question2,1,,1,2)
exten => s,n,GotoIf($[ ${answer2} < 4 ]?finish:question1)
;this line puts the two answers together and separates them with a | symbol.
exten => s,n(finish),set(answer=${answer1}|${answer2})
;this saves the answers into the CDR field of "userfield"
exten => s,n,Set(CDR(userfield)=${answer})
;This line will send an email with the subject saying "Survey John Smith 555-123-4455 3|2"
exten => s,n,system(mail -s "Survey ${CALLERID(name)} ${CALLERID(number)} ${answer}" EMAIL@ADDRESS.COM < /dev/null)
;play a thankyou message. you can just remove this line for anyone who doesn't want the thankyou.
exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/thankyouforyourtime)
exten => s,n,hangup()
Note the portion /custom/questionX
you will need to update these to reflect the name of your sound file you recorded.
SAVE changes
TEST CODE
Call your IVR
You should hear your first question. Press “2”
You should now hear your second question, Press “3”
Call will hang up
Go to CDR reports and run a report (usually can just hit SEARCH) and it will show the most recent calls. You should see your call, and in “USERFIELD” you’ll see “2|3”
2 is the first answer, “|” (pipe) is a delimiter, and 3 is the second answer.