OK, here is the whole solution I ended up using. Most of this came from the link above - thanks to Ben Willcox for posting his solution.
Note - I used *3 so it would not interfere with the *1 Automon recording
In extensions.conf
Code:
[macro-recordtovm]
exten => s,1,Set(MONITOR_FILENAME=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)})
exten => s,n,Set(DYNAMIC_FEATURES=recordtovm)
exten => s,n,MixMonitor(${MONITOR_FILENAME}.wav,b,/etc/asterisk/recordtovm.pl ${CALLERID(num)} ${MONITOR_FILENAME}.wav "${STRFTIME(${EPOCH},,%a %b %d %T %p %Z %G)}" ${EPOCH})
In features_applicationmap_custom.conf
Code:
recordtovm =>*3,self,Macro,recordtovm
In globals_custom.conf
Code:
DYNAMIC_FEATURES=>recordtovm
And create /etc/asterisk/recordtovm.pl
Code:
#!/usr/bin/perl -w
#
use strict;
my $monitordir="/var/spool/asterisk/monitor/";
my $vmdir="/var/spool/asterisk/voicemail/default/";
my $vmfolder="INBOX";
my $vmbox=$ARGV[0];
my $vmpath=$vmdir."$vmbox/"."$vmfolder";
my $monitorfilename=$ARGV[1];
my $calldate=$ARGV[2];
my $origtime=$ARGV[3];
opendir (DIR, $vmpath);
my @files = grep(/\.txt$/,readdir(DIR));
closedir(DIR);
my @sortedfiles = sort {$b cmp $a} @files;
my $vmid;
if ($sortedfiles[0] =~ /^(msg)(\d\d\d\d)(.txt)/)
{
$vmid=$2;
$vmid++;
}
else
{
$vmid="0000";
};
open VMFILE,"> $vmpath/msg$vmid.txt";
print VMFILE ";\n";
print VMFILE "; Message Information file\n";
print VMFILE ";\n";
print VMFILE "[message]\n";
print VMFILE "origmailbox=$vmbox\n";
print VMFILE "context=\n";
print VMFILE "macrocontext=\n";
print VMFILE "exten=s\n";
print VMFILE "priority=\n";
print VMFILE "callerchan=\n";
print VMFILE "callerid=\n";
print VMFILE "origdate=$calldate\n";
print VMFILE "origtime=$origtime\n";
print VMFILE "category=\n";
print VMFILE "duration=\n";
close VMFILE;
if ($ARGV[1])
{
system("mv $monitordir"."$monitorfilename $vmpath/msg$vmid.wav");
};
The kicker for me was that on outbound calls it used the CID of the trunk in the variable ${CALLERID(num)}. Go to each extension and put the extension number as the outbound CID for the extension. This gives it the correct value for recording to work. On outbound calls the phone provider here seems to overwrite this value anyway.
Times may not be exact, I don't know if EPOCH is current (when the file gets copied over) or when the call started. AFIAK, only the origtime is really needed. I only left origdate in there since I took the time to figure out the formatting.
I may go back someday and figure out how to stamp the start and stop recording times to get a recording duration.