All pastes #766 Raw Edit

AGIperl

public text v1 · immutable
#766 ·published 2004-08-27 06:03 UTC
rendered paste body
#!/usr/bin/perl -w

#
# Speaks the text in $ARGV[0].
# Caches text-to-speech conversions as 8-kHz .WAV files.

use Asterisk::AGI; use File::Basename; use Digest::MD5 qw(md5_hex);
use DBI;
#use DateTime::MySql;

use strict;

use constant MENU_HOY =>       1;
use constant MENU_FUTURO =>       2;
use constant MENU_REPEAT =>  3;

my $introduction_audio = 'rnc-events-intro.wav';
my $menuoption = MENU_REPEAT;

#give us an object like thing
my $self = {};

#
my $sounddir = "/var/lib/asterisk/sounds";

#call a main function
&main( $self );


sub main {

    open(foo,">/tmp/foo");
    print foo "something";
    close(foo);

    my $self = shift;

    # set up communications w/ Asterisk

#    $self->{'agi'} = setup_agi;

    my $agi = new Asterisk::AGI;
    my %input = $agi->ReadParse();

#    $agi->verbose('algo',1);

    #make sure we play the introduction
#    introduce_calendar( $self );
    #$menuoption = $agi->stream_file( $introduction_audio );
    $menuoption = $agi->stream_file('event-2');

 #   #conectamos a la base de datos
 #   my $dbh = open_dbi();

 #   my $sqlhoy = qq{ SELECT nombre FROM eventos};# where fecha = $today};
 #   my $sthhoy = $dbh->prepare( $sqlhoy );
 #   $sthhoy->execute();

 #   my $sqlfuturo = qq{ SELECT nombre FROM eventos};# where fecha > $today};
 #   my $sthfuturo = $dbh->prepare( $sqlhoy );
 #   $sthfuturo->execute();

 #   $dbh->disconnect();

 #   event_loop( $self )


}

sub event_loop {
    my $self = shift;

    #lee lo que se ingresa?
    #
    my ($nameh);
   # $sthhoy->bind_columns( undef, \$nameh);
    my ($namef);
    #$sthfuturo->bind_columns( undef, \$namef);
    my $wavefile;

    while ($menuoption){
        if ($menuoption==MENU_HOY){ #voy a repetir los eventos de hoy
#               while( $sthhoy->fetch() ) {
                        $wavefile=$nameh.'wav';
                        #$agi->get_data($wavefile,10_000, 1);
                        $self->{'agi'}->stream_file('beep')
#               }
        }
        elsif ($menuoption==MENU_FUTURO){ #voy a repetir los eventos de maniana
#               while( $sthfuturo->fetch() ) {
                        $wavefile=$namef.'wav';
                        #$agi->get_data($wavefile,10_000, 1);
                        $self->{'agi'}->stream_file('beep')
#               }
        }
        elsif ($menuoption==MENU_REPEAT){ #vuelvo a darle para elegir


                $menuoption = $self->{'agi'}->stream_file($introduction_audio);

                $self->{'agi'}->stream_file('beep')
        }
        else { #me voy pues no apreto nada, le doy gracias
                $self->{'agi'}->stream_file('rnc-thanks');
                $self->{'agi'}->hangup;
        }
    }
}




#sub setup_agi {
#    my $agi = new Asterisk::AGI;

#    $agi->ReadParse();

#    return ($agi);
#}



sub introduce_calendar {
    my $self = shift;

    # first we play the introduction
                                                                                                               $menuoption = $self->{'agi'}->stream_file( $introduction_audio );
    #$menuoption = $self->{'agi'}->get_data( $introduction_audio, 10_000, 1 );

    return 1;
}

# Get our DB connection
sub open_dbi{
    # Declare and initialize variables
    my $host = 'localhost';
    my $db = '';
    my $db_user = '';
    my $db_password = '';

    # Connect to the requested server
    my $dbh = DBI->connect("dbi:mysql:$db:$host", "$db_user", "$db_password");

    return $dbh;
}#end: open_dbi