Asterisk Recording deliver "monitored" calls?

Discussion in 'General' started by MarkosJal, Mar 19, 2009.

  1. MarkosJal

    Joined:
    Aug 9, 2007
    Messages:
    83
    Likes Received:
    0
    I have a client that wants to record all calls with call monitoring and deliver them by email.

    He has a programmer working to do this , but it seems that it is probably quite easy if one knows the modification to make to ARI . Has anyone done this and how?

    Thanks,

    Mark
     
  2. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    In general options-> call recording, there is a box to call a script after each call is recorded, just call "mutt" with -a (the file to be mime encoded) and an email address which you could get from the voicemail.conf i.e.
    grep <exten> voicemail.conf|cut -d ',' -f 3 )
     
  3. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    MarkosJal:

    More Specifically

    In "Run after record"

    /var/lib/asterisk/bin/sendrecordingbyemail ^{CHANNEL} ^{CALLFILENAME}.^{MIXMON_FORMAT}

    contents of /var/lib/asterisk/bin/sendrecordingbyemail
    Code:
    #!/bin/bash
    EXTENSION=`echo $1|cut -d '-' -f 1|cut -d '/' -f 2`
    EMAIL=` grep $EXTENSION /etc/asterisk/voicemail.conf|cut -d ',' -f3`
    echo "Call Recording from channel $1 file $2 " |mutt -x -a /var/spool/asterisk/monitor/$2 -s recording $EMAIL
    
    Please be aware that you need mutt (yum install mutt), you need an email address in the extension voicemail settings, permissions must be correct on the sendrecordingnyemail.
    There is absolutely NO error checking performed, I wrote this solely for your "programmer" to save him 5 minutes but mostly because I got stood up tonight, so what else to do. :p

    p.s. there are only 4 lines in the script, (This forum software still SUCKS!)
     
  4. MarkosJal

    Joined:
    Aug 9, 2007
    Messages:
    83
    Likes Received:
    0
    Dicko

    I tried this and no luck. I never got the email.

    Was wondering if you could see if the code maybe had a typo or anything.

    Is there no PM on this board? I could not find it at least.

    Can you contact me at markosjal AT Gmail

    Mark
     
  5. des_14

    Joined:
    Jul 22, 2009
    Messages:
    3
    Likes Received:
    0
    I tried this and got it half working.

    I managed to send recordings to a single email address by changing the $EMAIL to my email address

    echo "Call Recording from channel $1 file $2 " |mutt -x -a /var/spool/asterisk/monitor/$2 -s recording myemail@mydomain.com

    I think the problem is here

    EXTENSION=`echo $1|cut -d '-' -f 1|cut -d '/' -f 2`

    Any ideas (Please help :huh: )
     
  6. MarkosJal

    Joined:
    Aug 9, 2007
    Messages:
    83
    Likes Received:
    0
    des_14 please contact me markosjal AT gmail
     
  7. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    The ^{CHANNEL} variable looks something like:

    SIP/2001-b7c19928 (but always the extension is delimited by "/" at the front, and "-" at the end, so it works for IAX2 and ZAP also.)

    pipe that through

    cut -d '-' -f 1|cut -d '/' -f 2

    and it will extract 2001 from that string ( to EXTENSION )

    grep $EXTENSION /etc/asterisk/voicemail.conf|cut -d ',' -f3

    will extract the email adress of extension 2001 (if it has one) (uniquely if EXTENSION is a unique string in the voicemail.conf file, in retrospect "^$EXTENSION" might be better for the grep "search string" argument, (^ is startof line))

    ^{MIXMON_DIR} is by default :
    /var/spool/asterisk/monitor, Freepbx allows you to over-ride if you fill in the box, if you neglect to do that, it is null so I was explicit as to the default location and figured a sentient FreePBX'er would fix that if necessary.


    ^{CALLFILENAME}.^{MIXMON_FORMAT}
    is the name of the recording in that directory

    string it all together with mutt syntax,
    (Call Recording from channel $1 file $2
    might look better just as
    "Recorded Call by $EXTENSION" as a Subject Line)

    and "what can I say?", IWFM and has for months.
    but the software here reformat things to it's own whim,

    I hope the dissection was enough for you to reconstruct my steps.
    (Just try it step by step in bash so you see how it works)
     
  8. des_14

    Joined:
    Jul 22, 2009
    Messages:
    3
    Likes Received:
    0
    Will this also work for incoming calls?

    The ^{CHANNEL} variable looks something like this for incoming

    DAHDI/5-1

    I am very new at linux/elastix/voip and very confused :(
     
  9. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    des_14 :

    Don't be intimidated,

    you say:
    DAHDI/5-1

    and I say:
    . . . .but always the extension is delimited by "/" at the front, and "-" at the end,

    so yes,in this case the E$XTENSION is 5. (and you will have to do the email another way, as you did)

    Please hang in there, after a period of study, the confusion evaporates and you can view a whole new world with the satisfaction and comfort of understanding.
     
  10. des_14

    Joined:
    Jul 22, 2009
    Messages:
    3
    Likes Received:
    0
    I have about 65 extensions, But when a incoming call is emailed
    it comes in as

    DAHDI/1-1 up to DAHDI/30-1

    Out going have SIP/13XX-xxxxxxxx (no problem here)

    I have a T1 line (30 lines hence DAHDI 1 to 30, i think)

    is there any way I can see the scripts running from a SSH terminal?
     
  11. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    There is a system variable ^{UNIQUEID} that can be passed to your script that can indirectly provide more granularity with a call to the mysql CDR database:

    /usr/bin/mysql -h 127.0.0.1 -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e "SELECT * FROM cdr WHERE uniqueid = $UNIQUEID "

    for debugging just snip one of the calls to your script from /var/log/asterisk/full:

    and run it from bash (or putty or ssh, they all largely synonyms for the same thing)

    the call in the log looks something like:

    Executing [/var/lib/asterisk/bin/recordcalls.sh 1248443878.5540 /var/spool/asterisk/monitor/ 20090724-065820-1248443878.5540 wav


    (in this case recordcalls.sh is my script called with
    /var/lib/asterisk/bin/recordcalls.sh ^{UNIQUEID} ^{MIXMON_DIR} ^{CALLFILENAME} ^{MIXMON_FORMAT} )

    you can further append any console output from your script to a log file that you can watch in realtime by

    changing to:
    Code:
    /var/lib/asterisk/bin/recordcalls.sh ^{UNIQUEID} ^{MIXMON_DIR} ^{CALLFILENAME} ^{MIXMON_FORMAT}  >> /var/spool/asterisk/monitor/log.txt[

    and then tail -f /var/spool/asterisk/monitor/log.txt
     
  12. snowspeeder

    Joined:
    Aug 13, 2008
    Messages:
    20
    Likes Received:
    0
    Im sorry to revive an old topic..

    Would it be possible to use this script to envoke only after a user issues a keypress during a call.

    I know we can use the feature map...

    Something like below to call a macro that would record the steam, convert it to wav then email it with the address from the voicemail.conf?

    Code:
    [applicationmap] 
    record => *5,caller,Macro,recordapp
    
     
  13. fozzygomad

    Joined:
    Aug 21, 2008
    Messages:
    23
    Likes Received:
    0
    Re: Asterisk Recording deliver

    Hey Guys.

    I was looking arround the net for this exact script and found it. I have dusted it off and made some modifications. The script as it is works well for outgoing calls but not incoming. I am using info from the asteriskcdrdb and using some IF conditions to send the recording by email based on the users extension for incoming and outgoing. Thanks for pointing me in the write direction and here is my 2 cents worth to hopefully help others! :D

    Add the following command to FreePBX > Settings > Advance Settings:
    Post Call Recording Script:
    Code:
    /var/lib/asterisk/bin/sendrectoemail ^{UNIQUEID} ^{CALLFILENAME}.^{MIXMON_FORMAT} 
    
    Create a script file in /var/lib/asterisk/bin/sendrectoemail
    Permissions must be:
    Code:
    chown asterisk:asterisk /var/lib/asterisk/bin/sendrectoemail
    
    chmod 774 /var/lib/asterisk/bin/sendrectoemail
    
    Content of sendrectoemail
    Code:
    #!/bin/bash
    ## Get and create the variable for the uniqueID of the call.
    UNIQUEID="$1"
    ## Set an extension variable based on the CDR record in the MySQL database for the src column. 
    EXTENSION=`/usr/bin/mysql -h 127.0.0.1 -u root -p(yourdbpassword remove the brackets obviously and no space after -p) -N -B -D asteriskcdrdb -e "SELECT src FROM cdr WHERE uniqueid = $UNIQUEID "`
    ## The above variable is based on outgoing calls to get the extension number that the call originated from. If you want to get the extension number for a incoming call then you need the dst column
    ## from the database. The bellow statement checks if src does not begin with your extension range. My extension range starts with 1. You can also add other ranges with 
    ## a -o for a (or) option: if [[ "$EXTENSION" != 1* -o "$EXTENSION" != 2*  ]]; then
    if [[ "$EXTENSION" != 1* ]]; then
    EXTENSION=`/usr/bin/mysql -h 127.0.0.1 -u root -pyourdbpassword -N -B -D asteriskcdrdb -e "SELECT dst FROM cdr WHERE uniqueid = $UNIQUEID "`
    fi
    
    ## Create your own variables to your needs so you can pass this info into your body of the email. I like to use the info from the DB because its got everything I would need.
    SRC=`/usr/bin/mysql -h 127.0.0.1 -u root -pyourdbpassword -N -B -D asteriskcdrdb -e "SELECT src FROM cdr WHERE uniqueid = $UNIQUEID "`
    DST=`/usr/bin/mysql -h 127.0.0.1 -u root -pyourdbpassword -N -B -D asteriskcdrdb -e "SELECT dst FROM cdr WHERE uniqueid = $UNIQUEID "`
    CALLDATE=`/usr/bin/mysql -h 127.0.0.1 -u root -pyourdbpassword -N -B -D asteriskcdrdb -e "SELECT calldate FROM cdr WHERE uniqueid = $UNIQUEID "`
    
    ## Extract the email address from the extensions voicemail settings. Obviously you must setup voicemail with an email address under each extension.
    EMAIL=` grep $EXTENSION /etc/asterisk/voicemail.conf|cut -d ',' -f3`
    
    ## This just checks if the EMAIL variable is empty and will just echo a message of your choice. You can also use this to send an email to your PBX administrator to 
    ## correct the problem.
    if [ -z "$EMAIL" ]; then
    echo "No email address configured for extension $EXTENSION. Please setup voicemail in FreePBX for this extension and add an email address"
    else
    
    ## My recordings are stored in date order so I use this variable to get the correct recording from the /var/spool/asterisk/monitor folder. Would look something like this
    ## /var/spool/asterisk/monitor/2013/01/20/xxx-rec-file.wav
    DATE=$(date +"%Y/%m/%d")
    
    ## Here we use mutt to send and attach the recording to the user that made or received the call.
    echo "Call Recording on $CALLDATE from $SRC to $DST. The recoring is attached." |mutt -s "New recording on $CALLDATE from $SRC to $DST." $EMAIL -a /var/spool/asterisk/monitor/$DATE/$2
    fi
    
     

Share This Page