Cannot playback recorded message to a mailbox

I need help finishing this dialplan. I was graciously given a dialplan that will record a number of messages with a users responses and it will put them together and play it into a mailbox. It works just fine if I have a 'static" named file at the end to playback into the voicemailbox. As it turns out I need to be able to have multiple callers at the same time. So it was suggested that I use ${CALLERID(num)} to differentiate which caller and the ultimate message to play. But when I implement this the message can’t be found, I get this from the log file. For instance is extension 124 places the call, the responses are aggregated and played back, and the file is saved in the /tmp directory as msg124.wav The msg124.wav is in the directory but the error says the file msg in any format is unfound. Can someone point out what I need to do to get this working?? Thanks ALOT!

; Script to elicit audio responses from callers and send to a voicemail box.
exten => 1234,1,Answer
exten => 1234,n(startagain),Playback(custom/script_intro)
exten => 1234,n,Playback(custom/script_name_dob)
exten => 1234,n,Set(RANDFILE1=${RAND(8000,8599)})
exten => 1234,n,Set(CALLER=${CALLERID(num)})
exten => 1234,n,Record(/tmp/${RANDFILE1}.wav,3,10)
exten => 1234,n,NoOp(File name: /tmp/${RANDFILE1})
exten => 1234,n,Playback(custom/script_phone_number)
exten => 1234,n,Set(RANDFILE2=${RAND(8000,8599)})
exten => 1234,n,Record(/tmp/${RANDFILE2}.wav,10,20)
exten => 1234,n,NoOp(File name: /tmp/${RANDFILE2})
exten => 1234,n,Playback(custom/script_drug)
exten => 1234,n,Set(RANDFILE3=${RAND(8000,8599)})
exten => 1234,n,Record(/tmp/${RANDFILE3}.wav,10,20)
exten => 1234,n,NoOp(File name: /tmp/${RANDFILE3})
exten => 1234,n,Playback(custom/script_strength_refills)
exten => 1234,n,Set(RANDFILE4=${RAND(8000,8599)})
exten => 1234,n,Record(/tmp/${RANDFILE4}.wav,10,20)
exten => 1234,n,NoOp(File name: /tmp/${RANDFILE4})
exten => 1234,n,Playback(custom/script_pharmacy)
exten => 1234,n,Set(RANDFILE5=${RAND(8000,8599)})
exten => 1234,n,Record(/tmp/${RANDFILE5}.wav,10,20)
exten => 1234,n,NoOp(File name: /tmp/${RANDFILE5})
exten => 1234,n,System(/usr/bin/sox /tmp/${RANDFILE1}.wav /tmp/${RANDFILE2}.wav /tmp/${RANDFILE3}.wav /tmp/${RANDFILE4}.wav /tmp/${RANDFILE5}.wav /tmp/msg${CALLER}.wav)
exten => 1234,n,System(rm -f /tmp/8*.wav)
exten => 1234,n,Set(TIMEOUT(response)=10)
exten => 1234,n(askagain),Playback(/tmp/msg${CALLER})
exten => 1234,n,Playback(to-rerecord-yr-message)
exten => 1234,n,Playback(press)
exten => 1234,n,Playback(digits/star)
exten => 1234,n,Playback(otherwise-press)
exten => 1234,n,Playback(digits/1)
exten => 1234,n,Read(MYCHOICE,beep,1)
exten => 1234,n,GotoIf($["${MYCHOICE}" = "1"]?notagain)
exten => 1234,n,GotoIf($["${MYCHOICE}" = "*"]?startagain)
exten => 1234,n,Goto(askagain)
exten => 1234,n(notagain),System(echo "Channel: local/*124@from-internal" > /tmp/
exten => 1234,n,System(echo "MaxRetries: 0" >> /tmp/
exten => 1234,n,System(echo "RetryTime: 0" >> /tmp/
exten => 1234,n,System(echo "WaitTime: 30" >> /tmp/
exten => 1234,n,System(echo "Context: from-internal-custom" >> /tmp/
exten => 1234,n,System(echo "Extension: 12345" >> /tmp/
exten => 1234,n,System(echo "Priority: 1" >> /tmp/
exten => 1234,n,System(mv /tmp/ /var/spool/asterisk/outgoing)
exten => 1234,n,Playback(your-msg-has-been-saved)
exten => 1234,n,Playback(goodbye)
exten => 1234,n,Hangup()

exten => 12345,1,Answer
exten => 12345,n,Wait(10)
exten => 12345,n,Playback(/tmp/(msg${CALLER}))
exten => 12345,n,Hangup

In your second call (The one you originate) ${CALLER} will not be set, Therefor your Playback command is just going to be Playback /tmp/msg without any filename.

Yeah that is what is happening. How do I get around that? I used ${CALLER} to make the message unique enough so I could have multiple calls at the same time.

You need to pass the variable as part of your callfile creation.

I believe you can do this with the Setvar option to your call files.

I tried this:

exten => 1234,n,System(echo "Setvar recording=msg${CALLER}")

exten => 12345,1,Answer
exten => 12345,n,Wait(10)
exten => 12345,n,Playback(/tmp/recording)
exten => 12345,n,Hangup

Still no joy with two callers. Only one message is sent to the voicemailbox. I guess that makes sense since there is only one “recording.wav” file. I can create multiple msg$(CALLER).wav files in the tmp file. How can I step through those files in the exten 12345 call to play them into the voicemail box.

Your 12345 extension should probably be Playback(/tmp/${recording}) then the file that is being played would be uniquely named based on your earlier sox command in extension 1234.