Recipe, Tips
Recording Phone Calls
Recording calls on a PBX is easy, since the audio is already in digital form. The quality is the same as what you hear, so while it’s not radio broadcast quality, it’s good enough for note taking or simply to document a call.
There are various commands to record calls on asterisk, but the easiest is MixMonitor. It records both sides of the conversation and then merges them together into a single wav file.
Below are some ways to use MixMonitor in your PBX. All of these approaches rely on the following macro in your dialplan.
[macro-automon]
exten => s,1,Set(MONITOR_FILENAME=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)})
; exten => s,n,Playback(beep) ; optional - hear when recording starts
exten => s,n,MixMonitor(${MONITOR_FILENAME}.wav,b)
1. Record All Calls
This might be overkill - and could be dangerous/expensive/embarassing if a hacker gets into your server gets access to your business or personal phone calls. To minimize the risk, and reduce diskspace, you should remove all recorded calls that are older than a week.
To record you need to call the macro for all incoming and outgoing calls. Assuming you want to record all calls from the phone ‘aastra1′, your dialplan would look like…
[aastra1]
exten => _XX.,1,Noop(Outbound call to: ${EXTEN})
exten => _XX.,n,Macro(automon) ; start monitor
exten => _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN})
For incoming calls, you need to call the macro before ringing the local extension with the Dial command.
[incoming]
exten => 2,1,Noop(Dialing aastra1);
exten => 2,n,Macro(automon) ; start monitor
exten => 2,n,Dial(SIP/aastra1,20) ; 20 secs
exten => 2,n,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => 2-NOANSWER,1,Voicemail(20,us) ; If unavailable, send to voicemail w/ unavail announce
exten => 2-NOANSWER,n,Playback(vm-goodbye)
exten => 2-NOANSWER,n,Hangup
exten => 2-BUSY,1,Voicemail(${MACRO_EXTEN},bs) ; If busy, send to voicemail w/ busy announce
exten => 2-BUSY,n,Playback(vm-goodbye)
exten => 2-BUSY,n,Hangup
exten => _2-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
To clear out files that are older than 7 days, you’ll need a cronjob.
# remove old recordings at 8am
0 8 * * * /usr/bin/find /var/spool/asterisk/monitor/ -mtime +7 -exec /bin/rm '{}' \;
Note: you can edit your crontab with the command:
2. Record on Demand
The idea is that if you want to record, you can press a key combination such as * 1 to start recording.
First, You activate the key combination in the features configuration file.
[applicationmap] automon =>*1,self,Macro,automon
Next, you need to set the DYNAMIC_FEATURES variable before dialing and pass the ‘w’ or ‘W’ option to the Dial command. (Note: The documentation says a capital ‘W’ allows the caller to start monitoring and the lowercase ‘w’ allows the callee to start monitoring. I’ve found that both ‘w’ and ‘W’ allow the caller to start monitoring and the callee cannot start monitoring. If you have more insight into this, I’d love to hear it.)
[incoming]
exten => 2,1,Noop(Dialing aastra1);
exten => 2,n,Set(DYNAMIC_FEATURES=automon) ;; enable monitoring
exten => 2,n,Dial(SIP/aastra1,20,w) ; w = callee can start monitoring ; note: doesn't work!
[aastra1]
exten => _XX.,1,Noop(Outbound call to: ${EXTEN})
exten => _XX.,n,Set(DYNAMIC_FEATURES=automon) ;; enable monitoring
exten => _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN},W) ;; W = caller can start monitoring
The main drawback to this approach is that you need to be speaking with the person before recording, so you might miss a few seconds at the start. Also, if you don’t have the beep in the automon macro, you can’t be sure if the recording is actually working unless you’re looking at the asterisk console output while talking.
3. Use a dialing prefix to Trigger Recording
To automatically record a call, I found that adding a prefix to the dialed number was a simple solution. All that is required is a simple modification of the dialplan to handle the prefix. (I used ‘00′).
[aastra1]
exten => _XX.,1,Noop(Normal Outbound call to: ${EXTEN}")
exten => _XX.,n,Dial(SIP/lesnet_peer/1${EXTEN})
exten => _00X.,1,Noop(Recording outbound call to: ${EXTEN})
exten => _00X.,n,Macro(automon)
exten => _00X.,n,Dial(SIP/lesnet_peer/1${EXTEN:2},60) ; :2 = removes 00 prefix from number
exten => _00X.,n,Hangup
The recording files can all be found in /var/spool/asterisk/monitor/. For example:
20080917-120735-4165551212.wav 20080917-122353-4165551212.wav 20080917-120746-4165551212.wav 20080917-125437-4165551212.wav
Have fun. Oh, and you might want to read up on the legal issues surround recording phone calls in your area before rolling out this feature on your PBX.