Up until now they were using the .call files functionality to make automatic calls at specific intervals.
But now, they need a bit more control over the generated call. They need to provide a source number, an specific action to perform over the channel once connected, etc.
On a few minutes I prepared an small sample script in perl (derived from taci.pl) demonstrating how to make calls from within asterisk thru it's administration interface (AMI).
As this is a thing a few people have asked me in the past.. I will let the sample script here so I can refer new questions to this post.
#!/usr/bin/perl -w
use Net::Telnet ();
use File::Basename;
#Pop in your asterisk server manager interface information here
$mgrUSERNAME='caller';
$mgrSECRET='pene';
$server_ip='127.0.0.1';
### End Basic Configuration Settings
$destination = $ARGV[0];
$callerid = $ARGV[1];
$duration = $ARGV[2];
if (!$destination || !$callerid || !$duration) {
print "Usage: caller.pl channel callerid duration";
exit 1;
}
#First we have the variable needed to make a call
print qq|
Attempting to call...
From $callerid to $destination (while $duration)
|;
#Make the file handle hot to print out the above HTML
$| = 1;
$tn = new Net::Telnet (Port => 5038,
Prompt => '/.*[\$%#>] $/',
Output_record_separator => '',
Errmode => 'return'
);
#Uncomment and make sure your apache user has access to write this file, good for debugging
#$tn->dump_log("./taci.log");
$tn->open("$server_ip");
$tn->waitfor('/0\n$/');
$tn->print("Action: Login\nUsername: $mgrUSERNAME\nSecret: $mgrSECRET\n\n");
$tn->waitfor('/Authentication accept*/')
or die "Asterisk Manager Interface login failed, verify username and password: ", $tn->lastline;
### Make a call now
# build the variable that holds the call out command, play with the Channel for IAX or Zap to Zap calls.
$tn->print("Action: originate\nChannel: $destination\nCallerid: $callerid\nApplication: Wait\nData: $duration\n\n");
$tn->waitfor('/Event: Newchannel.*/') or die "Unable to determine call status\n", $tn->lastline; # wait for asterisk to process
$tn->print("Action: Logoff\n\n");
#Timeout means it is broken, if we get here Asterisk took it. An invalid ext or account will make it not work though
print "Call information accepted by Asterisk.\n";
exit 0;

No comments:
Post a Comment