Code below tested in Asterisk 11 (Issabel and Elastix). Its not self building. I needed this code for a customer (government!) and they still use it after years!
[macro-survey]
exten => s,1,answer()
;asks question1 (based on your recording file named as "question1")
exten => s,n(question1),Read(answer1,/var/lib/asterisk/sounds/en/atlantic,1,,1,2)
exten => s,n,GotoIf($["${answer1}" !=""]?question2:question1)
;asks question2 (based on your recording named 'question2")
exten => s,n(question2),Read(answer2,/var/lib/asterisk/sounds/en/pacific,1,,1,2)
exten => s,n,GotoIf($["${answer2}" !=""]?finish:question2)
;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 "accountcode"
exten => s,n,Set(CDR(accountcode)=${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.
exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/thankyouforyourtime)
exten => s,n,hangup()
If you make a call, and then look at the CDR table, you'll see something like this:
I selected "5" and then "3" in the IVR.
Date Destination Account Code Status Duration Uniqueid
2019 SIP/1000-00000444 5,3 ANSWERED 4s 1551227850.1893