Call recording (that old chestnut)

Hi all,

I have managed to get call recording working via an app call in features.conf and all is fine (sort of).

The key press (as defined in features.conf) calls a macro (yes - still using v1.4.22) that starts and stops the recording as it should. I then have a little script that sends the recorded call to the user via. e-mail.

This is where it gets ‘odd’. If I initiate the call AND the recording - the recording goes to me. However, if I am called and then initiate the recording - the call doesn’t come to me.

I know it’s to do with my script - but how can Asterisk tell me who it was that actually pressed the ‘*1’ (record) button in the first place? Is there a ‘this person called the feature’ type variable I’m not seeing?

Thanks.

(features.conf)

[applicationmap]
record => *1,caller,Macro,apprecord

(extensions.conf)

[macro-apprecord]
exten => s,1,GotoIf($["${rec}" = “0” | “${rec}” = “”]?startrec:stoprec)
exten => s,n(startrec),Playback(beep)
exten => s,n,Set(rec=1)
exten => s,n,set(callTime=${STRFTIME(,%d%m%y%H%M%S)})
exten => s,n,Set(filename=recording-${CALLERID(ANI)}-${CALLERID(number)}-${MACRO_EXTEN}-${calltime})
exten => s,n,Set(MONITOR_EXEC=/usr/local/bin/rec2vm.php)
exten => s,n,Monitor(wav,${filename},m)
exten => s,n,MacroExit
exten => s,n(stoprec),StopMonitor
exten => s,n,Set(rec=0)
exten => s,n,Playback(recorded)
exten => s,n,MacroExit
exten => h,1,StopMonitor
exten => h,n,Set(rec=0)
exten => h,n,Playback(recorded)
exten => h,n,MacroExit

Never-mind - I’ve fixed it with some manipulation of ${CHANNEL} :smiley:.

anyway I could get you to post your fix? I’ve been trying to do some stuff with the built in call recording but it doesn’t provide me with some of the functionality that I need. Particularly the ability to play different sounds when the recording starts and finishes.

The ability to play start/stop sounds is in the above (Playback(beep) for start and Playback(recorded) for end).

The ‘clever’ bit is the rec2vm.php script I created. Even though the Monitor application has an ‘m’ in it - it gets ignored.

So, my script simply runs soxmix on the in and out files - then e-mails the user the resultant file (it does other things as well now - but that’s the main function).

Which bit are you struggling with?

This is the ‘revised’ version of the macro:

[macro-apprecord]
exten => s,1,GotoIf($["${rec}" = “0” | “${rec}” = “”]?startrec:stoprec)
exten => s,n(startrec),Playback(beep)
exten => s,n,Set(rec=1)
exten => s,n,set(callTime=${STRFTIME(,%d%m%y%H%M%S)})
exten => s,n,Set(type=${CUT(CHANNEL,/,1)})
exten => s,n,Set(user=${CUT(CHANNEL,/,2)})
exten => s,n,Set(filename=recording-${CALLERID(ANI)}-${CALLERID(number)}-${MACRO_EXTEN}-${calltime}-${type}-${user})
exten => s,n,Set(MONITOR_EXEC=/usr/local/bin/rec2vm.php)
exten => s,n,Monitor(wav,${filename},m)
exten => s,n,MacroExit
exten => s,n(stoprec),StopMonitor
exten => s,n,Set(rec=0)
exten => s,n,Playback(recorded)
exten => s,n,MacroExit
exten => h,1,StopMonitor
exten => h,n,Set(rec=0)
exten => h,n,MacroExit

It would be so cool if you would post the rec2vm.php script! :smile:

#!/usr/bin/php

<?php $in = $argv[1]; $out = $argv[2]; $file = $argv[3]; $recopts = 0; system ("soxmix $in $out $file"); system ("rm $in"); system ("rm $out"); $link = mysql_connect("localhost","username","password"); $query = "SELECT * FROM `system`"; $result = mysql_db_query("database", $query); if ($result) { while ($r = mysql_fetch_array($result)) { $mailserv = $r["email-server"]; $servname = $r["server-name"]; } } list($label, $extn, $ddi, $dialled, $datetime, $type, $user, $id) = explode("-", $file); $date = substr($datetime,0,2) . "/" . substr($datetime,2,2) . "/" . substr($datetime,4,2); $time = substr($datetime,6,2) . ":" . substr($datetime,8,2) . ":" . substr($datetime,10,2); $query = "SELECT * FROM `users` WHERE `extn` = '$user'"; $result = mysql_db_query("database", $query); if ($result) { while ($r = mysql_fetch_array($result)) { $recemail = $r["rec-email"]; $recopts = $r["rec-opts"]; system ("mkdir /var/www/recordings/$user"); } } mysql_close($link); $from = "Recordings@" . $servname . ".pbx"; $reply = $recemail; $filename = "/tmp/rec2vm.txt"; $url = "http://" . $servname . "/recordings/index.php"; switch ($recopts) { case 0: exit; break; case 1: $subject = "Recorded message alert"; $fh = fopen ($filename, 'w'); fwrite ($fh, "This is an automated message from $servname.\n\n"); fwrite ($fh, "You have the following recorded file on the server:\n\n"); fwrite ($fh, "Party 1 : $extn.\n"); if ($dialled) { fwrite ($fh, "Party 2 : $dialled.\n"); } fwrite ($fh, "Date recorded : $date.\n"); fwrite ($fh, "Time recorded : $time.\n\n"); fwrite ($fh, "NOTE : The recording can be reached by logging in here : $url.\n\n"); fwrite ($fh, "Thanks,\n$servname.\n"); fclose ($fh); system ("sendEmail -f $from -t $recemail -s $mailserv -u $subject -o reply-to=$reply -o message-file=/tmp/rec2vm.txt"); system ("rm $filename"); system ("mv $file /var/www/recordings/$user/"); break; case 2: $subject = "Recorded message copied"; $fh = fopen ($filename, 'w'); fwrite ($fh, "This is an automated message from $servname.\n\n"); fwrite ($fh, "You have the following recorded file attached:\n\n"); fwrite ($fh, "Party 1 : $extn.\n"); if ($dialled) { fwrite ($fh, "Party 2 : $dialled.\n"); } fwrite ($fh, "Date recorded : $date.\n"); fwrite ($fh, "Time recorded : $time.\n\n"); fwrite ($fh, "NOTE : The recording can also be reached by logging in here : $url.\n\n"); fwrite ($fh, "Thanks,\n$servname.\n"); fclose ($fh); system ("sendEmail -f $from -t $recemail -s $mailserv -a $file -u $subject -o reply-to=$reply -o message-file=/tmp/rec2vm.txt"); system ("rm $filename"); system ("mv $file /var/www/recordings/$user/"); break; case 3: $subject = "Recorded message forwarded"; $fh = fopen ($filename, 'w'); fwrite ($fh, "This is an automated message from $servname.\n\n"); fwrite ($fh, "You have the following recorded file attached:\n\n"); fwrite ($fh, "Party 1 : $extn.\n"); if ($dialled) { fwrite ($fh, "Party 2 : $dialled.\n"); } fwrite ($fh, "Date recorded : $date.\n"); fwrite ($fh, "Time recorded : $time.\n\n"); fwrite ($fh, "NOTE : The server file has been deleted.\n\n"); fwrite ($fh, "Thanks,\n$servname.\n"); fclose ($fh); system ("sendEmail -f $from -t $recemail -s $mailserv -a $file -u $subject -o reply-to=$reply -o message-file=/tmp/rec2vm.txt"); system ("rm $filename"); system ("rm $file"); break; } ?>

It’s a crude rough-and-ready solution - but it works for me. If anyone ‘improves’ on it - please post up :smile:.

The ‘index.php’ bit is simply a file that lists the contents of the extensions directory (to retrieve old recordings etc.)

Oh, and it uses MySQL tables of course (you could simply put static values in here if you wish).

cheers

You’re awesome!! Thanks!

Hi
I’m no expert on Asterisk, and I’m trying to record conversation with Monitor()
I followed example from The Futur Of Telephony

exten => s,1,Answer()
exten => s,n,Monitor(wav,monitor_test,mb)
exten => s,n,SayDigits(12345678901234567890)
exten => s,n,StopMonitor()

  1. Output files contains nothing, should it contain digit ?
  2. How can I modify the function SayDigit() by a wait, until I hangup conversation ?
  3. Ahy all the pppd
    Thanks