Automated Call Recording Uploader in Dial Plan

Hello everybody, i have an issue regarding call recording.
What i wanted to do is automatically upload the call recording after hangup

My extensions.conf looks some like this

exten => _!,n,System(mkdir “/var/spool/asterisk/${CALLERID(number)}”)
exten => _!,n,Set(FILENAME=CallingTime(${EPOCH})-Called(${EXTEN}))
exten => _!,n,Set(MONITOR_EXEC_ARGS=&& mv “/var/spool/asterisk/monitor/${FILENAME}.wav” “/var/spool/asterisk/${CALLERID(number)}/”)
exten => _!,n,Monitor(wav,${FILENAME},mb)
exten => _!,n,Dial(SIP/100,r)
exten => _!,n,Hangup()

I’ve tried adding
exten => _!,n,System( uploader ${CALLERID(number)} /var/spool/asterisk/${CALLERID(number)}/ ${FILENAME}.wav)
but the recording is not available yet

I’ve tried adding it after hangup
exten => h,1,System( uploader ${CALLERID(number)} /var/spool/asterisk/${CALLERID(number)}/ ${FILENAME}.wav )
but the recording is not available yet

i’ve tried appending the uploader function into the MONITOR_EXEC_ARGS which look something like this
exten => _!,n,Set(MONITOR_EXEC_ARGS=&& mv “/var/spool/asterisk/monitor/${FILENAME}.wav” “/var/spool/asterisk/${CALLERID(number)}/” && uploader ${CALLERID(number)} /var/spool/asterisk/${CALLERID(number)}/ ${FILENAME}.wav )
But the recording fails to merge the two leg files

If you can point me to the right direction or find what i am doing wrong here it would be very helpful.
Thanks in anticipation

Asterisk will merge the call legs, but only after the call has finished. The updater program will only fire if it’s in the path of the user running asterisk, or if you fully qualify it. Even by adding this in the hangup, I don’t believe it starts to merge both audio files until the hangup is fired. You’d probably be better off scheduling a cron job to look for files that have already been merged, and handle them outside of asterisk.

If it helps, Here’s what my MONITOR_EXEC looks like.

Set(MONITOR_EXEC=/usr/local/bin/mailer.sh ${MonDir}/${MONITOR_FILENAME}.wav ${Email} ${CALLERID(NUM)} ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})

2 Likes

My question is why dont you use Mixmonitor to have a single file ?

Thanks for you answer @mkozusnik . You are correct that the call legs are merged only after the call has finished.
In fact the following code works after the call has finished.

exten => _!,n,Set(MONITOR_EXEC_ARGS=&& mv “/var/spool/asterisk/monitor/${FILENAME}.wav” “/var/spool/asterisk/${CALLERID(number)}/”)

This code just moves the recording file to another folder
So what i did is appended my custom uploader script to it.

exten => _!,n,Set(MONITOR_EXEC_ARGS=&& mv “/var/spool/asterisk/monitor/${FILENAME}.wav” “/var/spool/asterisk/${CALLERID(number)}/” && uploader ${CALLERID(number)} /var/spool/asterisk/${CALLERID(number)}/ ${FILENAME}.wav )

In theory it should work since i am just appending my script to a previous working script.
But for some reason it fails and the call legs are not merged

Hi @johnkiniston thanks for you reply. I will try this one. Maybe i will prioritize my script instead of moving the recording to a specific folder first.

@ambiorixg12 thanks for your reply. I tried using MixMonitor but i was not able to execute the command since it also fails at some point

@All Thank you for your inputs. It helped me get on the right track.
What i ended up using is MixMonitor and then added my uploader script on the command parameter.
This way, i don’t have to move the recording to a new folder since i can create the recording file on the destination folder
which simplifies my use case.

Best Regards