nodus has asked for the wisdom of the Perl Monks concerning the following question:
this is the main script that gets run by vgettyplay('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'); });
if you got this far I thank you#!/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'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Answering Machine scripting engine
by mandog (Curate) on Jul 26, 2004 at 02:46 UTC |