Here is the BETA release 2 of the code.
(added a delete of the recording after its emailed)
I’ve tested this in the FreePBX Distro using 13.0.190.11 worked ok as a beta test. It may need alteration for your own environments, however I am using commands that have been around a long time so should be compatible with most versions.
Code from strangers should never be tested in a production environment.
What this code does.
The system will ask 2 questions, after each it will record the caller for a maximum of 15 seconds (you can change this of course) or until the users presses # key, whichever comes first.
In this example, after the 2nd answer is given, the system will play back both recordings together so you can hear it.
If caller press # the call will stop recording and continue to next questions
If caller either doesn’t say anything for 3 seconds, the system continues to next question (changeable of course)
Again this is just beta code to see if you think it will do what you want and identify tweaks you might like.
A note on email.
Email is a tricky thing with asterisk, linux and email world in general. My code works for our email system, but it might not necessarily work for yours due to security of your email servers or configurations. It took me longer to get through the email nuances than it did to write the code.
INSTALLATION
To make the code simpler, for those not versed in asterisk dialplan, any line starting with a ; semicolon is a remark line and can be safely removed for ease of viewing. Lines with ; are there to either leave a comment, or to have the system not execute that line of code.
STEP 1
ADMIN->CONFIG EDIT
open up "extensions_custom.conf"
Copy the code below between the ------ lines into the bottom of extensions_custom.conf and then save the file.
START OF DIALPLAN CODE
---------------------------------------------------------------------------
[macro-questionanswer]
;Version .2 BETA
exten => s,1,answer()
;system asks a question. ‘question1’ reflects the name of the file that you record or upload to the system.
exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/question1)
;uniqueID is an asterisk value to ensure that multiple recordings dont fall all over each other. in this example.
;3=amount of silence in seconds before system auto stops recording.
;15=max length of recording
;a=append, which means each subsequent recorded question should append to the previous one if any.
exten => s,n,Record(${UNIQUEID}.wav,3,15,a)
;to add questions to your surveys, just copy/paste the next two lines underneath the next.
;increment the “questions2” to “question3” “question4” etc.
;I’ve included a couple of extra questions with a semicolon comment to bypass them for speed of testing
exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/question2)
exten => s,n,Record(${UNIQUEID}.wav,3,15,a)
;exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/question3)
;exten => s,n,Record(${UNIQUEID}.wav,3,15,a)
;exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/question4)
;exten => s,n,Record(${UNIQUEID}.wav,3,15,a)
;comment/remove these 3 lines to remove playback of the recording. This was put in for testing purposes
exten => s,n,wait(1)
exten => s,n,Playback(${UNIQUEID})
exten => s,n,wait(1)
;this plays a generic “THANKYOU”. Comment/delete the line below to remove that feature.
exten => s,n(endcall),playback(thank-you-for-calling)
;system sends the email with the attachment recording.
;change YOURSUBJECT and [email protected] to reflect the needs of your system
exten => s,n,system(mail -s YOURSUBJECT -a /var/lib/asterisk/sounds/${UNIQUEID}.wav [email protected] < /tmp/email.txt)
;delete sound file.
exten => s,n,system(rm /var/lib/asterisk/sounds/${UNIQUEID}.wav)
exten => s,n,hangup()
-----------------------------------------------------------------------------
END OF DIALPLAN CODE
Click on “SAVE”
STEP 2
ADMIN->CUSTOM DESTINATIONS
Create a new custom destination "questionanswer"
Set the target as
macro-questionanswer,s,1
Save those changes
STEP 3
Create a way to trigger the application to run from dialplan.
For example, create a IVR, and set one of the numeric values a caller can enter to Custom Destination -> “questionanswer”"
STEP 4
Save your changes AND apply the configuration.
STEP 5
Create your question files.
Use system recordings, and either record them over your phone, or through a 3rd party sound recording application. If recording with another app, they must be saved as 8000khz MONO 16bit WAV PCM.
The recordings you make, set their name to “recording1” “recording2” “recording3”
STEP 6
in /tmp/ create a file called "email.txt"
In that file put in something like
SUBJECT: NEW RECORDING
Here is a new recording to review.
Save changes.
TESTING IT OUT
Call your PBX script in whatever way you have set up to activate this recording. You SHOULD hear your recording ask you a questions, then there will be “Beep” record your answer. After 3 seconds of silence, you’ll hear the second question followed by a beep. After 3 seconds of recording, the system will playback Answer1 and Answer2 and then hangup the call.