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.

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;
# add event handlers
$voice->add_handler('BUSY_TONE', 'finish',sub { $voice->stop; exit 0; });
$voice->add_handler('RECEIVED_DTMF', 'readnum',\&read_dtfm);
# enable event handlers
# dial the number, play the message, and wait for feedback
print "Dialing $number\n";
# waiting for an answer
print "Waiting for answer...\n";
# dial extension
print "Dialing extension...\n";
# wait for answer from extension
print "Waiting for extension pickup...\n"; 
until ($dtfm) {
sub play_menu {
    my $self = shift;
    print "Playing menu...\n";
sub read_dtfm {
    my ($self,$input,$mydtmf) = @_;
    print "Reading DTFM...$mydtmf\n";
    $dtmf = $mydtmf;
    if ($dtmf == 1) {
	print "$number is confirmed.\n";
    } else {
	print "$friend cannot attend\n";
    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.

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