Sunday, April 15, 2018

Customer Survey after a queue call.

This code will allow your asterisk server to play a series of questions questions, then record the digits the caller gives for each question, then save it to the CDR table of asterisk. It will/can also send an email to someone with the digits entered.

This survey can be made to automatically run at the end of a queue call when the agent hangs up, or it can be something your agent or employee can transfer a caller to manually.




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.
There is a line included that will send an email to someone with the data, however its difficult to make work as SMTP is very organizational specific.

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)

Note the path for the recordings.  It MIGHT be different on your system implementation.  You might need to double check your recording location after you save it and adjust the path below accordingly.
[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/custom/question1,1,,1,2)
exten => s,n,GotoIf($[ ${answer1} < 4 ]?question2:question1)

;this asks the second question (based on your recording named 'question2") and stores them in variable
exten => s,n(question2),Read(answer2,/var/lib/asterisk/sounds/custom/question2,1,,1,2)
exten => s,n,GotoIf($[ ${answer2} < 4 ]?finish:question1)

;you can ask more questions by repeating the above code, change the variable "2" and make it "3" then "4" etc.

;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() 

SAVE changes

Now create a "Custom Destination" in the PBX GUI.  Set the "destination to be 
macro-survey,s,1
and give it a description of "After Call Survey"

Save those changes.

Play automatically after an agent in a queue hangs up:
In the GUI settings for the queue(s), set the "Queue Continue Destination" to be "Custom Destination" then select "after call survey" in the subsequent drop box that will appear.

Have agent/employee transfer manually.
If you want to send callers manually, create a ring group. in the extension list put a dummy extension that does not exist, for example "1". Then set the ringgroup failover destination to be the custom destination "after call survey".  Your employees can transfer to the ring group and it will fail through to the survey.

TEST CODE

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.

3 comments:

  1. syntax error: syntax error, unexpected '<', expecting $end; Input:
    < 4
    i'm change this for this

    exten => s,n,GotoIf($[ "${answer1}" < "4" ]?question2:question1)

    this works, but does not send the characters pressed in the mail

    ReplyDelete
  2. Me funciono perfectamente, muchas gracias

    ReplyDelete

Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.