IVRで処理する際、お客様の電話番号をDB照会する必要などがある場合に使える、CallerIDの基本的な取得方法です。下記のスクリプトをRunscript(スクリプトを実行)コマンドで実行すると、音声で電話番号を案内します。必要に応じて処理を追加してください。
#!/usr/bin/perl
use strict;
use Asterisk::AGI;
###########################################
# 2010 Communication Business Avenue, Inc.
# Caller ID Check Script
###########################################
$|=1;
# Setup some variables
my %AGI; my $tests = 0; my $fail = 0; my $pass = 0;
my $astagi = new Asterisk::AGI;
while(<stdin>) {
chomp;
last unless length($_);
if (/^agi_(\w+)\:\s+(.*)$/) {
$AGI{$1} = $2;
}
}
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++;
}
}
$astagi->say_alpha($AGI{'callerid'});
</stdin>