[SOLVED] How To Email Call Recordings Post Call Recording Script


#1

I would really like to be able to have the call recordings emailed out after the call is ended. Is there a way to do this through a dialplan? otherwise I could watch the directory for new recordings and then email them out. I feel like the dialplan is a better option. Any ideas?

UPDATE: There is a solution, the guide is posted at the bottom of this page.


#2

There is a setting(in the newest version i dont know where) to execute a command after the MixMonitor ended you can create a bash script to get the name of recording and pass it to the script and then use mutt or mail to send that file.


#3

Would that be in the dialplan? I am perfectly capable of writing a bash script, however where would I get the variable filename of the recording?


#4

Generally in the GUI -> advanced settings -> Post Call Recording Script

The variables are in the hover over popup help.


#5

Thank you very much!


#6

I have figured out how to successfully figured out how to email call recordings, and there wasn’t a guide so I wanted to make one for anyone else who is trying to email their call recordings.

Here is my bash script for emailing out the call recording that includes who called, and the number that was called, as well as the date and time of the call.

#!/bin/bash
#This script emails the recorded call right after the call is hung up. Below are    the variables passed through asterisk
# $1 - year
# $2 - month
# $3 - day
# $4 - Time String
# $5 - Source
# $6 - File
# $7 - Destination
# $dt - Date and Time


dt=$(date '+%m/%d/%Y %r');


echo -e "You have a new call recording to listen to \n\n
 The call date and time was $dt \n\n 
 The call was from $5 \n\n
 The call was to $7 \n\n
 
 Please see the attached file \n\n" | mail -a /var/spool/asterisk/monitor/$1/$2/$3/$6 -s "New Call Recording" email@domain.com

Save that file in /var/lib/asterisk/bin I saved it as emailrecording.sh

cd /var/lib/asterisk/bin
chown asterisk:asterisk emailrecording.sh
chmod 774 emailrecording.sh

Then go into the FreePBX Web UI -> Advanced Settings

Be sure to mark Display Readonly Settings as True and then mark Override Readonly Settings as True so you can change what needs to be changed.

Scroll down to Post Call Recording Script

Now comes the tricky part, it took me a little trial and error to get the variables to pass through correctly

bash /var/lib/asterisk/bin/emailrecording.sh ^{YEAR} ^{MONTH} ^{DAY} ^{TIMESTR} ^{FROMEXTEN} ^{CALLFILENAME}.^{MIXMON_FORMAT} ^{ARG3}

There is a space in between the } and ^ however in between the ^{CALLFILENAME} and ^{MIXMON_FORMAT} there is a period so it will be passed as filename.fmt so in my example it would be callfilename.wav

Once you have that added, go ahead an make sure call recording is enabled on one of your routes and test it out.

Below is what the email should look like (I have Zimbra)

Hopefully this guide was able to help you, if you have any questions please ask me.


IVR Change destination after call ending
#7

Thank you so much for sharing this! Do you know how I might be able to pull the extension dialed into the email template?

I have a bunch of remote people that will be getting calls through follow-me on virtual extensions and the way this is setup now the inbound and outbound calls show the number of the party dialing in when the recording arrives in an inbox for their manager.


(Zamin) #8

Thanks dear Its a good and Pretty good feature i tried its to much good


(Zamin) #9

dear i try Asterisk 11.14 its not working kindly plz tell can i install mail server in centos then it will work now


#10

I installed this script and there are no emails. I have a question the email@domain.com entry what is that for? Is that supposed to be the email that the system is using? Or the smtp server for the system? Sorry for the noob question.


#11

I suspect that @dslauter might have aliased mail to mutt for the -a to work

man mail
man mutt

If you don’t have mutt then

yum|apt-get install mutt


Email on demand recording
#12

+1
This should be included in the wiki pages.


(Ian Plain) #13

In case anyone comes across this post I have extened teh script to convert the recording to mp3 before emailing it.

  #!/bin/bash
#This script emails the recorded call right after the call is hung up. Below are    the variables passed through asterisk
# $1 - Time String
# $2 - Source
# $3 - File
# $4 - unique id
# $5 - Destination
# $dt - Date and Time

/bin/nice /bin/sleep 3

dy=$(date '+%Y')
dm=$(date '+%m')
dd=$(date '+%d')
file_age=35
dtpath=/var/spool/asterisk/monitor/$dy/$dm/$dd/

/bin/nice /usr/local/bin/lame -b 16 -m m -q 9-resample $dtpath$3.wav  $dtpath$3.mp3
/bin/nice /bin/chown  asterisk:asterisk $dtpath/$3.mp3

dt=$(date '+%m/%d/%Y %r');

echo $dt

echo -e "You have a new call recording to listen to \n\n
 The call date and time was $dt \n\n
 The call was from $2 \n\n
 The call was to $5 \n\n
 And the unique call id was $4\n\n

Please see the attached file \n\n" | mail -a $dtpath$3.mp3 -s "New Call Recording" mail@domain.com

/bin/nice /usr/bin/find /var/spool/asterisk/monitor/  -type f -mtime +"$file_age" |grep wav | \
        while read I; do
               /bin/rm  "$I"
        done

The post record string in freepbx is as below

/usr/local/sbin/postrecord.sh ^{TIMESTR} ^{FROMEXTEN} ^{CALLFILENAME} ^{UNIQUEID} ^{ARG3}

Finally remember to set the masquerade in sendmail so that the email correctly addressed

Enjoy


Converting recorded wav calls to mp3
(Aaron Gustafson) #14

Sorry I’m a bit of a noob, can you explain this?

Also is there any chance someone could explain or add the code so that this would then DELETE the recording? I have a limited storage space…

Thx


(Ian Plain) #15

Hi the last but one deletes file sover a certain age $file_age which is defined up the top in this case as 35 days but could change that to say 2

Ian


(Vlad) #16

For some reason my ^{TIMESTR} ^{FROMEXTEN} ^{CALLFILENAME} ^{UNIQUEID} ^{ARG3}
are blank for the script, which runs fine and sends test email etc


#17

You would have to state better your problem, that is the the interpreted ( by asterisk/Comedian mail) string that would be passed to your script as the first argument, be that a bash, perl, php whatever script.


(Vlad) #18

turns out it only happens with on demand recording (*1)
if whole session is recorded it transfers parameters to .sh fine
it is clear in logs

[2016-09-30 00:59:20] VERBOSE[2265] app_mixmonitor.c: Executing [/var/lib/asterisk/bin/emailrecording.sh]

[2016-09-30 00:50:50] VERBOSE[27016][C-00000017] app_mixmonitor.c: Executing [/var/lib/asterisk/bin/emailrecording.sh 20160930-005041 007 internal-008-007-20160930-005041-1475211041.43 1475211041.43 008]

might be a bug
can someone check if on demand recording sends?


Post Call Recording Script not sent correctly to MixMonitor
(Vlad) #19

had another minute for this
It does not because MixMonitor call is happening in /var/lib/asterisk/bin/one_touch_record.php which has no idea and doesn’t read ^ well. With regular recording it calls MixMonitor in extensions_additional.conf

in extensions_additional.conf:
[macro-one-touch-record]
include => macro-one-touch-record-custom
exten => s,1,Set(ONETOUCH_REC_SCRIPT_STATUS=)
exten => s,n,System(/var/lib/asterisk/bin/one_touch_record.php “${CHANNEL(name)}”)

in /var/lib/asterisk/bin/one_touch_record.php:
$astman->mixmonitor($masterChannel, “{$mixMonDir}{$year}/{$month}/{$day}/{$callFileName}.{$mixMonFormat}”, “ai(LOCAL_MIXMON_ID)$beep”, $mixMonPost, rand());

guess we need to fix one_touch_record.php to forward those ^ correctly as it seems they are processed by MixMonitor itself


(Vlad) #20

moved it out of this topic to FreePBX as php one is it