Two-Way Telephone Interaction - Mother of Perl | 4 | WebReference

Two-Way Telephone Interaction - Mother of Perl | 4

Two-Way Telephone Interaction

More Examples

Dialing an Extension

Your mileage may vary, but I wrote a second script that calls my office phone number and extension. It's based on a timing scheme so you'll probably have to tweak it. Again, if the VOICE_DETECTED event was working, I wouldn't have had to do that. Oh well.

#!/usr/bin/perl
use Modem::Vgetty;
# variables
my $number = "3016562262";		 
my $menu1 = "/home/eisen/work/voice/menu1.rmd";
my $pressed1 = "/home/eisen/work/voice/pressed1.rmd";
my $no_pressed1 = "/home/eisen/work/voice/no_pressed1.rmd";
my $dtfm;
# turn on debugging
$Modem::Vgetty::testing = 1;
# create new object
my $voice = new Modem::Vgetty;
$voice->device('DIALUP_LINE');
$voice->autostop(qw(ON));
# add event handlers
$voice->add_handler('BUSY_TONE', 'finish',sub { $voice->stop; exit 0; });
$voice->add_handler('RECEIVED_DTMF', 'readnum',\&read_dtfm);
$voice->add_handler('VOICE_DETECTED','voice',\&play_menu);
# enable event handlers
$voice->enable_events;
# dial the number, play the message, and wait for feedback
print "Dialing $number\n";
$voice->dial($number);
$voice->waitfor('READY');
# waiting for an answer
print "Waiting for answer...\n";
$voice->wait(10);
$voice->waitfor('READY');
# dial extension
print "Dialing extension...\n";
$voice->dial(101);
# wait for answer from extension
print "Waiting for extension pickup...\n"; 
$voice->wait(15);
$voice->waitfor('READY');
until ($dtfm) {
    &play_menu($voice);
    $voice->wait(5);
    $voice->expect('READY');
}
sub play_menu {
    my $self = shift;
    print "Playing menu...\n";
    $self->play_and_wait($menu1);
}
sub read_dtfm {
    my ($self,$input,$mydtmf) = @_;
    print "Reading DTFM...$mydtmf\n";
    $dtmf = $mydtmf;
    $self->stop;
    $self->expect('READY');
    if ($dtmf == 1) {
	$voice->play_and_wait($pressed1);
	print "$number is confirmed.\n";
    } else {
	$voice->play_and_wait($no_pressed1);
	print "$friend cannot attend\n";
    }
    $self->stop;
    $self->shutdown;
    exit 0;
}

Well, since you made it to the bottom of the program, you may have noticed a combination of wait calls and one dial call. Well, waiting is something everyone does on telephones including this program. I've timed it to wait for the phone system to answer, dial my extension, wait for the call to transfer, and then play the menu. It's clunky, but it works most of the time.


http://www.internet.com

Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: October 26, 2000
Revised: October 27, 2000

URL: http://www.webreference.com/perl/tutorial/15/4.html