This is rough code that is untested (at work, no modem) but I am anxious to see what people think of it. Its goal is to implement a simple scripting interface for vgetty for menu systems and answering machines. I am probably going to add a email notify and a web interface to the messages. This is my first somewhat real perl program so rip it apart :)
this is a sample menu file
play('intro.rmd');
&menu;
option(1,sub {
&menu;
play('menu2.rmd');
option(1, sub {
play('explaination.rmd');
});
option(2, sub {
play('mesage.rmd');
record('messages');#dir to record to
});
});
option(2, sub{
play('blah.rmd');
});
this is the main script that gets run by vgetty
#!/usr/bin/perl -w
#ansService cover under the gpl
#see COPING for licence info
use strict;
use Common;
use Modem::Vgetty;
my %menuHash;
my $config;
my $time;
my $v=&init();
my $dtfm;
#One important thing: for most analog modems,
#you must set the number of RINGs to wait for
#to two (2) or higher (set `rings 2' in
#`vgetty.config'), because the ID code is sent
#between the first and the second RING. If
#mgetty picks up the phone too soon, the modem
#can't get this information.
$SIG{__DIE__} = sub {
# do special handling
my $message = $_[0] . "\n";
$message .= "\n\nUser Agent Information\n";
print LOG ($message);
Common::display_error_page_and_exit();
};
open LOG,">> /var/log/ansService.log"or die "Cannot create logfile: $!
+";
my $caller =$ENV{CALLER_ID};
$time=localtime(time);
$time=~s/(\d\d)\s(\d\d):(\d\d).*\d{2}(\d{2})/$2.$3.'.'.$1.'.'.$4/;
print LOG "$time ansering service startingup"
&menuStart;
until($dtfm|){
}
$v->wait(10);
#**********internal subs**********
###############init###############
#initializes vgetty and
#creates the $v var
##################################
sub init{
my $v = new Modem::Vgetty;
$v->add_handler('BUSY_TONE', 'endh', sub { $v->stop; exit(0); });
local $SIG{ALRM} = sub { $v->stop; };
$v->enable_events;
$v->autostop('ON');
$v->waitfor('READY');
$v->add_handler('RECEIVED_DTMF', 'readnum',\&read_dtmf);
$v->add_handler('HANDSET_OFF_HOOK','picked_up',exit 0);
$v->add_handler('BUSY_TONE', 'finish',sub { $voice->stop;exit 0;})
+;
$v->enable_events;
return $v;
}
############menuStart#############
#load the config file and eval
##################################
sub menuStart{
%menuHash=undef;
open CONFIG , '/etc/ansService/menu' or
die "cant open /etc/ansService/menu:$! \n";
my @file = <CONFIG>;
close CONFIG;
my $file1;
foreach(@file){
$file1.=$_;
}
config=file1;
eval config or die ;
}
############menuChoice############
#do option based on dtfm choice
#by execing something in the menu array
##################################
sub menuChoice{
if $menuHash{$_[0]} {
eval $menuHash{$_[0]};
}else play("notaoption.rmd")
}
############read_dtfm#############
#reads the dtfm and passes it off to menuChoice
#and takes care of most of the error checking
##################################
sub read_dtfm {
my ($self,$input,$mydtmf) = @_;
print "Reading DTFM...$mydtmf\n";
$dtmf = $mydtmf;
$self->stop;
$self->expect('READY');
&menuChoice($dtfm);
$self->stop;
$self->shutdown;
exit 0;
}
#*******control structures********
###############menu###############
#clear old menu array and
#populate the new one by execing the sub
#should do stuff like play a message
#then have options
##################################
sub menu{
%menuHash=undef;
eval @_[0];
}
#############option###############
#put option in menu array
##################################
sub option{
my ($optionNum, $optionSub) = @_;
$menuHash{$optionNum}=$optionSub;
}
################up################
#go up one level... somehow.
##################################
sub up{
}
###############top################
#go to start of menu
##################################
sub top{
&menuStart;
}
#***********opertations***********
##############record##############
#records a message
#no handling for multiple folders
##################################
sub record{
my ($dir,)=@_;
my $filename="/var/lib/ansService/recordings/$dir/$caller-$time.rm
+d";
print LOG "recording to: $filename";
$v->beep(50,10);
$v->waitfor('READY');
$v->record($filename);
alarm(20);
$v->stop;
}
###############play###############
#plays a message
##################################
sub play{
$v->play_and_wait("/var/lib/ansService/".$_[0]);
$v->expect('READY');
}
if you got this far I thank you