Copying [macro-vm]

I want to call Sox after every voicemail message, for every extension, in order to do some post audio processing.

I believe I need to take the entire [macro-vm] context and copy it from extensions_additional.conf where it currently resides and paste it in either extensions_custom.conf or. extensions_override_freepbx.conf.

Does it matter which file I put it in? I’m unclear on the distinction between the two files. Also, if you were me, would you put the call to sox at the end of [macro-vm] or somewhere else? Since it needs to happen after the voicemail is left, I don’t think I can leverage a custom destination, correct?

Thanks in advance for any insight.

You might want consider editing/adding your own

externnotify in “VoiceMail Settings” , it is a script that is called every time a voicemail message finishes.

That’s an excellent answer - Thank you!!

A follow-up question…

If this was within vm-macro, my command would have been the following:

exten => exit-SUCCESS,n,System(sox ${VM_MESSAGEFILE}.wav ${VM_MESSAGEFILE}-old.wav)
exten => exit-SUCCESS,n,System(sox ${VM_MESSAGEFILE}-old.wav ${VM_MESSAGEFILE}.wav compand 0.3,1 6:-70,-60,-20 -5 -90 0.2 vad reverse vad reverse)
exten => exit-SUCCESS,n,System(rm ${VM_MESSAGEFILE}-old.wav)

I see in the current externotify file (/var/lib/asterisk/agi-bin/vmnotify-newvm.php) it has the following variables.

$context = $argv[1];
$mailbox = $argv[2];

Do you know if in the PHP script I can reference the ${vmnu_dstdir}, ${vmnu_mbx}, and ${VM_MESSAGEFILE} variables like I would have in the dialplan? I basically want to execute the sox command on the wav file, that was left, as well as copy files from that directory into another directory and I want to make sure I can get a handle on those things within the PHP script.

Thanks for your continued insight!

the message file would be a concatanation of

$astspooldir /voicemail/ $arv[1] / $argv[2] INBOX/msg0000.wav

if $argv[3] was > 0 (there is a new message)

in whatever language you write your script in (it doesn’t have to be php :wink: )

where $astspooldir is whatever is defined in the [globals] section of /etc/asterisk/extensions_additional.conf , almost always /var/spool/asterisk

(well the msg0000.wav bit might not be there but only if you arranged that yourself by changing in /etc/asterisk/voicemail.conf maxmsg= or format= )

Thanks again for the response… There’s only one problem…

It looks like with the externotify option to call an external program, the only parameters available are:the ones below, I can’t act on the recording without knowing the recording path and file name of the last recording. Would I be forced to use the $newvmcount to somehow string together the last part of the filename (e.g… INBOX/msg $arg[3] .wav? I assume there’s a way to pad $argv[3] with leading zeroes in PHP? Thanks again in advance.

$context = $argv[1];
$mailbox = $argv[2];
$newvmcount = $argv[3];
$oldvmcount = $argv[4];
$urgvmcount = $argv[5];

the newest recording is always msg0000.wav all files are renumbered each time.

I don’t think that’s correct… I just checked a mailbox that has 105 recordings, and the most recent recording has the highest number. 0000 is always the first recording in the folder and so I need to retrieve the most recent recording and work with that.

Oops I apparently “misremembered”, however with bash

printf “%s/%s/%s/INBOX/msg%0.4d.wav” /var/spool/asterisk $1 $2 $(expr $3 - 1)

would be the name of the file, use the appropriate printf syntax of the language of your choice. But because the script is called every time comedian mail exits , like checking your own voicemail, you should test the age of that file to be new enough to need processing.

Excellent - I appreciate the printf example. That really points me in the right direction. Thanks for the help!!


cat yourscript

test  $3 -ge  1 && \
FILE=$(printf "/var/spool/asterisk/voicemail/%s/%s/INBOX/msg%0.4d.wav " $1 $2 $(expr $3 - 1) ) && \
test $(expr $(date +%s) - $(date -r $FILE +%s)) -le 5  && \
echo "sox file $FILE here"
echo "call oldprogram $1 $2 $3 $4 $5 here if you know what it does and you need it"