[asterisk-users] Recording just first part of call?

Anselm Martin Hoffmeister anselm at hoffmeister-online.de
Tue Nov 6 06:39:58 CST 2007


Am Dienstag, den 06.11.2007, 11:49 +0000 schrieb Tony Mountifield:
> I know that I can record the contents of a call by calling Monitor()
> or MixMonitor() from the dialplan just before invoking Dial().
> 
> I have a potential customer who wants only the first minute of each
> call recorded (for identification purposes, without the storage overhead
> of keeping the complete call).
> 
> Can anyone here think of the easiest way to do this? The only possibilities
> I can think of are:
> 
> a) Add a new option to Monitor() or MixMonitor() to stop recording after
> a specified length of time.
> 
> b) Record the whole call and post-process the recording file to discard
> all except the required first part.

The asterisk manager API seems to offer a "StopMonitor" command, which
is basically the same as the StopMonitor() extensions.conf command,
afaik.

A quick ugly hack (and well, I did not have my coffee yet, so caveat
emptor):

Before calling the "Monitor()" in extensions.conf, call an AGI that kind
of starts a timer. This AGI would have to know about the Channel used
(you surely figure how to do that, I am to lazy to look it up right
now).

Something like
8<====
#!/usr/bin/php -q
    GLOBAL $stdin, $stdout;
    ob_implicit_flush(false);
    set_time_limit(30);
    error_reporting(0);
    $stdin = fopen( 'php://stdin', 'r' );
    $stdout = fopen( 'php://stdout', 'w' );
    while ( !feof($stdin) )
    {
        $temp = fgets( $stdin );
        $temp = str_replace( "\n", "", $temp );
        $s = explode( ":", $temp );
        $agivar[$s[0]] = trim( $s[1] );
        if ( ( $temp == "") || ($temp == "\n") )
        {
            break;
        }
    }
    $channel = $agivar[agi_channel];
    system ("screen -d -m /usr/local/bin/stop-recording ".$channel);
    exit(0);
====>8

The script at /usr/local/bin/stop-recording could be a bash script:
8<====
#!/bin/bash
sleep 60
# Before Stopping the monitor, you want to make sure that
# about 60 seconds went past
# Perhaps add some leeway if the other party answered
# after ring no. 5 or so

# The following should all be on one line, but emails tend to break...
( echo -e "Action: login\nUsername: foo\nSecret: bar\nEvents: off\n\n" ;
sleep 1 ; echo -e "Action: StopMonitor\nChannel: $1\n\n" ; sleep 1 ) |
netcat localhost 5038 >/dev/null 2>/dev/null
====>8

You would want to add a check that the original call is the one to be
StopMonitored() - e.g. if the caller hangs up and redials within a few
seconds, the second call would possibly be terminated. You could manage
this by writing the "channel" to a temporary file in the AGI, removing
the file after call termination. The Bash script would then read the
channel from the file, or just silently terminate if the file is not
there.

This is just an idea. It needs some tweaking here and there, and there
probably are way more elegant methods for solving the task... :-)

BR
Anselm




More information about the asterisk-users mailing list