Friday, September 8, 2017

Record the digits selected in an asterisk IVR for surveys

This records answers from a customer survey, but this one does it by modifying an existing IVR code.  For demo purposes it shows how to modify an IVR dialplan.

DESCRIPTION

This records the IVR selections and save them into a file called survey.txt
The comma delimited file contain each IVR selection broken up in this manner:
DATE,CallerID,UniqueID,FreepbxIVRid,QuestionFilename,Selection

Example output:

07092017-22:35:03,Jane Doe <5551238811>,1504834501.1207,ivr-7,custom/question1,1

DATE
=DDMMYYY-HH:MM:SS
CallerID=The callers CLID if available "Jane Doe <5551238811>"
UniqueID=This is the unique value for each call. This will help you sort indvidual calls that are in this file.
FreepbxIVRid=Each IVR you create is assigned an IVR. FreePBX doesn't store the descriptive name, this is here to help you know which one is which.
QuestionFilename=This is the sound file that you play for each IVR. This is to help you know what question was asked
Selection=This is the DTMF value they pick for their answer.

INSTALLATION

Don't throw this into production, put it in a test system, or just change 1 IVR.

Test in FreePBX Distro 10.13.66-64bit

You can either modify existing IVRs, or create some net new ones.
I suggest that your recorded questions file names allow you to reflect the question being asked because the way FreePBX builds the dialplans and references each IVR a unique ID number, the voicefile name is the only thing that easily lets you see which IVR is which.

open up /etc/asterisk/extensions_additional.conf
Copy all your IVR CONTEXT entries in this file that are relative to your IVR questions, and paste them into

/etc/asterisk/extensions_override_freepbx.conf


If you have other production IVRs, I wouldn't copy them into this file. They will still work, but any changes in the GUI will not reflect in your production sytem, as the override file will do just that, override changes made by the GUI.

So below is a 'snipped' version of the 30 or 40 lines of code you would see. If you had 5 Ivrs, you would have to copy them all.
[ivr-7] ; ivr1
include => ivr-7-custom
include => from-ivr-directory-Disabled
........
exten => s,1,Set(TIMEOUT_LOOPCOUNT=0)
exten => hang,1,Playback(vm-goodbye)
exten => hang,n,Hangup
;--== end of [ivr-7] ==--;

copy everything from
[ivr-X] through to ;-== end of [ivr-X] ==--;

Paste it into
extensions_override_freepbx.conf

Now that you have all the IVRs that belong to your survey, you can now edit them. We move them here because manual changes in their home file location would be over written by future changes in the GUI.
Now go to each IVR in the _override.conf file and look for the entries that look similar to this:
[ivr-X]
.....
exten => 1,1(ivrsel-1),Goto(ivr-8,s,1)
exten => 2,1(ivrsel-2),Goto(ivr-8,s,1)
These are the valid selections in each IVR you've configured in FreePBX. So in the above example callers in IVRx can press 1 or 2, and will take them to the next ivr for further questions.
We are going to modify each one of these lines with the same piece of code:
system(echo "${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)},${CALLERID(all)},${UNIQUEID},${IVR_CONTEXT},${IVR_MSG},${EXTEN}" >> /tmp/survey.txt)
We'll insert this into the exsting code
This:
exten => 1,1(ivrsel-1),Goto(ivr-8,s,1)
turns into this:
exten => 1,1,system(echo "${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)},${CALLERID(all)},${UNIQUEID},${IVR_CONTEXT},${IVR_MSG},${EXTEN}" >> /tmp/survey.txt)
exten => 1,2(ivrsel-1),Goto(ivr-8,s,1)
This:
exten => 2,1(ivrsel-2),Goto(ivr-8,s,1)
turns into this:
exten => 2,1,system(echo "${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)},${CALLERID(all)},${UNIQUEID},${IVR_CONTEXT},${IVR_MSG},${EXTEN}" >> /tmp/survey.txt)
exten => 2,2(ivrsel-2),Goto(ivr-8,s,1)
You'll need to repeat this entry for each entry you have in the IVRS.
Save your changes
in the CLI type
core reload
This will load these entries into your PBX.
Make a call to the IVR and test the functionality.
Look in /tmp/surevey.txt, there should be entries like:
07092017-22:35:03,Jane Doe <8862>,1504834501.4403,ivr-7,custom/question1,1
07092017-22:35:03,Jane Doe <8862>,1504834501.4403,ivr-5,custom/question2,2
07092017-22:35:03,Jane Doe <8862>,1504834501.1207,ivr-7,custom/question1,1
07092017-22:35:03,Jane Doe <8862>,1504834501.1207,ivr-5,custom/question2,2

No comments:

Post a Comment