nwbell

Any AGI gurus...?

3 posts in this topic

I want to write an app for Asterisk that I could use to help me record payphones I find. It would go something like this:

Caller dials in on a toll-free DID, which is set to start an AGI app that does the following...

- Answer

- Log the phone's ANI info to a file

- Play a pre-recorded message ("ANI captured. Say phone's location, then press Pound.")

- Record caller until Pound is pressed; save recording

- Play another message ("Location recorded. Press pound again for ringback test, or hang up now.")

If call times out: hang up

If Pound is pressed: do the following...

- Play message ("About to ring back. Hang up now.")

- Hang up

- Wait a little bit (15 seconds?)

- Call back number that was just recorded

- Play another message ("This is the ringback system calling you back. If you can hear this, press Pound.")

If call times out, or the disposition indicates that the fone doesn't take incoming calls: hang up and be done

If Pound is pressed: do the following...

- Append "RingbackCompleted" to the fone's line in the log file

- Play message ("Ringback test compete. Hang up now.")

- Hang up

I'm not really looking for anybody to do it for me, but rather somebody to tell me where to look for info on coding it, or advise where I might streamline the operation a bit.

0

Share this post


Link to post
Share on other sites

I'm not really looking for anybody to do it for me, but rather somebody to tell me where to look for info on coding it, or advise where I might streamline the operation a bit.

The wonderful thing about AGI's is that they simply deal with stdin/stdout. Here's a very simple "Caller ID read back" I did many, many moons ago. It's not hard, and maybe this will help get you going. You can probably do it cleaner as well :)


#!/usr/bin/perl

$|=1;

my %AGI; my $tests = 0; my $fail = 0; my $pass = 0;

while(<STDIN>) {
chomp;
last unless length($_);
if (/^agi_(\w+)\:\s+(.*)$/) {
$AGI{$1} = $2;
}
}

print STDERR "Caller ID Readback [AGI]....";

if (!$AGI{callerid})
{
print STDERR "CLID readback failure.";
print "STREAM FILE clid-failure \"\" \n";
my $results = <STDIN>; checkresult($results);
exit 0;
}

print STDERR "CLID is : $AGI{callerid}";
print "STREAM FILE clid-readback \"\" \n";
my $results = <STDIN>; checkresult($results);
print "SAY DIGITS $AGI{callerid} \"\" \n";
my $results = <STDIN>; checkresult($results);
exit 0;


sub checkresult {
my ($res) = @_;
my $retval;
$tests++;
chomp $res;
if ($res =~ /^200/) {
$res =~ /result=(-?\d+)/;
if (!length($1)) {
print STDERR "FAIL ($res)\n";
$fail++;
} else {
print STDERR "PASS ($1)\n";
$pass++;
}
} else {
print STDERR "FAIL (unexpected result '$res')\n";
$fail++;
}
}

0

Share this post


Link to post
Share on other sites

You might also want to listen back to some of the BRR episodes which discuss asterisk.

Edited by digitalgalileo
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now