Freepbx Survey

Here’s a demo, let me know if this is what you are looking for? If so I’ll build in some more logic checks around wrong answers.
Again, this code atm is DEMO for you to try out and see if it will do what you want:

What this does:
When activated, it will ask a question, then allow the user to place an answer. This demo asks 2 questions.
Once the caller answers the questions and hangs up, the values entered are written to the “USERFIELD” in the CDR table.

You can go to the CDR module in freepbx and see the values for each caller in this database.

TODO
Some code around the values entered to make sure they are in range IE 1-3 valid, but user enter 5
Having it automatically triggered at end of agent call.

INSTALLATION
create your ‘questions’ in system recordings. I called mine “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: (noted the portion /custom/questionX the last bit is your file name, so if you saved them differently, you’ll need to update the filename name in the code)

[macro-survey]
exten => s,1,answer()

;this asks the first question (based on your recording) 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) 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 protected] < /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() 

SAVE changes

In FreePBX goto CUSTOM DESTINATIONS and create a new custom destination
TARGET= macro-survey,s,1
Description=enter something so you know what this dos. “queuesurvey” for example

Save Changes

Create a ring group number
(we’ll use a ring group failover destination as a way to trigger this code)
Extension list = put in a dummy number that doesnt’ exist in your pbx. I usually put in “1”.
go down to “Destination if no answer” and select CUSTOM DESTINATION -> queuesurvey

save your changes and apply them with the red button.

TEST CODE
Call your ring group.
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.

1 Like