[macro-record-on]
; This routine is called as a macro before a “Dial” statement, in order
; to record a call into a set of files. It is used hand-in-hand with
; the “macro-record-cleanup” routine.
; I use an AGI to get the base filenames, which are created using the
; date in form YYYYMMDD-HHMMSS which is then added to the ${EXTEN} and
; ${CALLERIDNUM} strings to form the complete filename.
;
; Call this routine with Macro(record-on,${EXTEN},${CALLERIDNUM})
;
; Note that I set CALLERIDNUM=foo up in my [globals] section, due
; to the inability of Asterisk to compare against the null case.
; Long story, but you really should have that variable set up in
; [globals] if you use this.
;
; Note: Legality of call recording varies by nation and state. Consult
; a very good lawyer before turning this on, or preface all your in/out
; calls with ‘This call may be recorded.’ to give yourself some minimal
; grounds to stand on (though that may not be enough.)
;
; Contents of the file /var/lib/asterisk/agi-bin/set-timestamp.agi:
;
; #!/bin/sh
; longtime=`date +%Y%m%d-%H%M%S`
; echo SET VARIABLE timestamp $longtime
;
; I could just use the built in ${DATETIME} to create a timestamp,
; but I really hate the date format used (DDMMYYYY) since it is
; silly. (least specific to most specific, left to right is the
; best way to create timestamps, IMHO)
;
exten => s,1,AGI(set-timestamp.agi)
exten => s,2,SetVar(CALLFILENAME=${timestamp}-${ARG2}-${ARG1})
exten => s,3,Monitor(wav,${CALLFILENAME})
[macro-record-cleanup]
;
;
; If we have recorded a call, it is to our advantage to change the
; format of the call from a two-file system (blah-in.wav blah-out.wav)
; into a single file that contains both legs of the call, and then
; compress the call into some reasonably small filesize using gsm
; compression. This routine should be called out of the “h” priority
; in a context. If the call was not recorded, this macro will
; not cause any harm, so calling it on each hangup isn’t a problem.
;
;
; First, did we record this call? If ${CALLFILENAME} is equal to
; the variable ${FOO} (remember, we set them to be equal to “foo”
; up in the [globals] section) then we can be fairly certain that
; this call wasn’t recorded, so just jump to the end of this macro
; and return out of routine. Otherwise, post-process the sound
; files into something more space efficient (one gsm file)
;
exten => s,1,SetVar(MONITORDIR=/var/spool/asterisk/monitor)
exten => s,2,GotoIf($[${CALLFILENAME} = ${FOO}]?6:3)
;
;
; This part of the routine mixes the in and out .wav files into one .wav, and then
; cleans up the original files (removes them)
;
; wmix is part of Wavetools-1.0 (http://tph.tuwien.ac.at/~oemer/tgz/wavetools-1.0.tgz)
;
; Turn the two in/out .wav files into a single .wav file with both channels
exten => s,3,System(/usr/local/bin/wmix ${MONITORDIR}/${CALLFILENAME}-in.wav ${MONITORDIR}/${CALLFILENAME}-out.wav > ${MONITORDIR}/${CALLFILENAME})
;
; Remove the old .wav files – we don’t need them anymore.
exten => s,4,System(/bin/rm ${MONITORDIR}/${CALLFILENAME}-in.wav ${MONITORDIR}/${CALLFILENAME}-out.wav)
;
; This part of the routine compresses the .wav files into a .gsm file for
; better storage (about 1/5 the size of a .wav file). Use “untoast” to restore
; to normal wav file format. (toast and untoast are fairly standard on Linux systems)
;
exten => s,5,System(/usr/bin/toast -F ${MONITORDIR}/${CALLFILENAME})
;
; End of routine, return to calling point (note: NoOp required for GotoIf
; called from priority 2)
exten => s,6,NoOp
; The [intern] context is where I pass all calls
; that are dialed by the SIP phones in my house/office.
; I name these phones in the sip.conf file when I define the
; SIP peers.
;
; This context is the “main” context that gets used for outbound
; calls out of the house. It, in turn, calls other contexts
; which contain bits and pieces of other places that it’s possible
; to dial from my house phone. I’ve split them up into many sub-segments
; so that they are re-usable if I should decide to allow other
; persons or organizations access some of those dialplan parts
; in some future configuration. My older extensions.conf had many
; fewer contexts, but I have opted to build this version with more
; flexible use of “include” commands to make my life easier for
; future configuration chores.
;
; First, I set up the configurations for call recording here, and then
; due to programmatical reasons I use a “Goto” to reset my priority
; and jump to the “real” context of [intern-post]. At the moment, I
; simply have a NoOp in priority 1, but I could just as easily put
; a pre-call answer, or call the record-on macro, or whatever.
;
[intern]
exten => _.,1,NoOp
;exten => _.,1,Macro(record-on,${EXTEN},${CALLERIDNUM})
exten => _.,2,Goto(intern-post,${EXTEN},1)
; After we set up some initial housekeeping things in the [intern] context,
; the [intern-post] context is jumped to, which is where the true dialplans
; are kept.
;


