i'm trying to use the Asterisk::AMI package but with a simple example dont works
#!/usr/bin/perl -w
# ami_test.pl
use strict;
use diagnostics;
use Asterisk::AMI;
// use default 127.0.0.1 5038
my $astman = Asterisk::AMI->new(
Username => 'manager',
Secret => 'secret'
);
die "Unable to connect to Asterisk" unless ($astman);
my $response = $astman->({
Action => 'Command',
Command => 'sip show peers'
});
print $response->{'Response'};
Alway i get an error :
Not a CODE reference at ami_test.pl line 17 (#1)
(F) Perl was trying to evaluate a reference to a code value (that is, a
subroutine), but found a reference to something else instead. You can
use the ref() function to find out what kind of ref it really was. See
also perlref.
Uncaught exception from user code:
Not a CODE reference at ami_test.pl line 17.
at ami_test.pl line 17
the documentation see wrong, i've try
my $response = $astman->action({
Action => 'Command',
Command => 'sip show peers'
});
and works fine
The documentation for Asterisk::AMI
is wrong. You should write
my $response = $astman->action({
Action => 'Command',
Command => 'sip show peers'
});
which is equivalent to
my $action = $astman->send_action({
Action => 'Command',
Command => 'sip show peers'
});
my $response = $astman->get_response($action);
By default there is no timeout on actions. To specify a default timeout for all actions, create your AMI object using, for example
my $astman = Asterisk::AMI->new(
Username => 'manager',
Secret => 'secret',
Timeout => 10
);