Asterisk-AMI
view release on metacpan or search on metacpan
lib/Asterisk/AMI/Common.pm view on Meta::CPAN
db_del ( FAMILY, KEY [, TIMEOUT ])
Requires Asterisk 1.8+.
Support for Asterisk 1.4 is provided through CLI commands.
Deletes the Asterisk database for FAMILY/KEY. Returns 1 on success, 0 if it failed
or undef on error or timeout. TIMEOUT is optional.
db_deltree ( FAMILY [, KEY, TIMEOUT ])
Requires Asterisk 1.8+.
Support for Asterisk 1.4 is provided through CLI commands.
Deletes the entire Asterisk database tree found under FAMILY/KEY. KEY is optional. Returns 1 on success, 0 if it failed
or undef on error or timeout. TIMEOUT is optional.
get_var ( CHANNEL, VARIABLE [, TIMEOUT ])
Returns the value of VARIABLE for CHANNEL, or undef on error or timeout. TIMEOUT is optional.
set_var ( CHANNEL, VARIABLE, VALUE [, TIMEOUT ])
Sets VARIABLE to VALUE for CHANNEL. Returns 1 on success, 0 if it failed, or undef on error or timeout.
TIMEOUT is optional.
hangup ( CHANNEL [, TIMEOUT ])
Hangs up CHANNEL. Returns 1 on success, 0 if it failed, or undef on error or timeout. TIMEOUT is optional.
exten_state ( EXTEN, CONTEXT [, TIMEOUT ])
Returns the state of the EXTEN in CONTEXT, or undef on error or timeout. TIMEOUT is optional
States:
-1 = Extension not found
0 = Idle
1 = In Use
2 = Busy
4 = Unavailable
8 = Ringing
16 = On Hold
park ( CHANNEL, CHANNEL2 [, PARKTIME, TIMEOUT ] )
Parks CHANNEL and announces park information to CHANNEL2. CHANNEL2 is also the channel the call will return to if
it times out.
PARKTIME is optional and can be used to control how long a person is parked for. TIMEOUT is optional.
Returns 1 if the call was parked, or 0 if it failed, or undef on error and timeout.
parked_calls ( [ TIMEOUT ] )
Returns a hash reference containing parking lots and their members, or undef if an error/timeout or if no calls
were parked. TIMEOUT is optional.
Hash reference structure:
$hashref->{lotnumber}->{'Channel'}
{'Timeout'}
{'CallerID'}
{'CallerIDName'}
sip_peers ( [ TIMEOUT ] )
Returns a hash reference containing all SIP peers, or undef on error or timeout. TIMEOUT is optional.
Hash reference structure:
$hashref->{peername}->{'Channeltype'}
{'ChanObjectType'}
{'IPaddress'}
{'IPport'}
{'Dynamic'}
{'Natsupport'}
{'VideoSupport'}
{'ACL'}
{'Status'}
{'RealtimeDevice'}
sip_peer ( PEERNAME [, TIMEOUT ] )
Returns a hash reference containing the information for PEERNAME, or undef on error or timeout.
TIMEOUT is optional.
Hash reference structure:
$hashref->{'SIPLastMsg'}
{'SIP-UserPhone'}
{'Dynamic'}
{'TransferMode'}
{'SIP-NatSupport'}
{'Call-limit'}
{'CID-CallingPres'}
{'LastMsgsSent'}
{'Status'}
{'Address-IP'}
{'RegExpire'}
{'ToHost'}
{'Codecs'},
{'Default-addr-port'}
{'SIP-DTMFmode'}
{'Channeltype'}
{'ChanObjectType'}
{'AMAflags'}
{'SIP-AuthInsecure'}
{'SIP-VideoSupport'}
{'Callerid'}
{'Address-Port'}
{'Context'}
{'ObjectName'}
{'ACL'}
{'Default-addr-IP'}
{'SIP-PromiscRedir'}
{'MaxCallBR'}
{'MD5SecretExist'}
{'SIP-CanReinvite'}
{'CodecOrder'}
{'SecretExist'}
lib/Asterisk/AMI/Common.pm view on Meta::CPAN
}
return;
}
sub get_var {
my ($self, $channel, $variable, $timeout) = @_;
my $action = $self->action({ Action => 'GetVar',
Channel => $channel,
Variable => $variable }, $timeout);
if ($action->{'GOOD'}) {
return $action->{'PARSED'}->{'Value'};
}
return;
}
sub set_var {
my ($self, $channel, $varname, $value, $timeout) = @_;
return $self->simple_action({ Action => 'Setvar',
Channel => $channel,
Variable => $varname,
Value => $value }, $timeout);
}
sub hangup {
my ($self, $channel, $timeout) = @_;
return $self->simple_action({ Action => 'Hangup',
Channel => $channel }, $timeout);
}
sub exten_state {
my ($self, $exten, $context, $timeout) = @_;
my $action = $self->action({ Action => 'ExtensionState',
Exten => $exten,
Context => $context }, $timeout);
if ($action->{'GOOD'}) {
return $action->{'PARSED'}->{'Status'};
}
return;
}
sub park {
my ($self, $chan1, $chan2, $parktime, $timeout) = @_;
my %action = ( Action => 'Park',
Channel => $chan1,
Channel2 => $chan2 );
$action{'Timeout'} = $parktime if (defined $parktime);
return $self->simple_action(\%action, $timeout);
}
sub parked_calls {
my ($self, $timeout) = @_;
my $action = $self->action({ Action => 'ParkedCalls' }, $timeout);
return unless ($action->{'GOOD'});
my $parkinglots;
foreach my $lot (@{$action->{'EVENTS'}}) {
delete $lot->{'ActionID'};
delete $lot->{'Event'};
my $lotnum = $lot->{'Exten'};
delete $lot->{'Exten'};
$parkinglots->{$lotnum} = $lot;
}
return $parkinglots;
}
sub sip_peers {
my ($self, $timeout) = @_;
my $action = $self->action({ Action => 'Sippeers' }, $timeout);
return unless ($action->{'GOOD'});
my $peers;
foreach my $peer (@{$action->{'EVENTS'}}) {
delete $peer->{'ActionID'};
delete $peer->{'Event'};
my $peername = $peer->{'ObjectName'};
delete $peer->{'ObjectName'};
$peers->{$peername} = $peer;
}
return $peers;
}
sub sip_peer {
my ($self, $peername, $timeout) = @_;
my $action = $self->action({ Action => 'SIPshowpeer',
Peer => $peername }, $timeout);
if ($action->{'GOOD'}) {
return $action->{'PARSED'};
}
return;
}
sub sip_notify {
my ($self, $peer, $event, $timeout) = @_;
return $self->simple_action({ Action => 'SIPnotify',
Channel => 'SIP/' . $peer,
Variable => 'Event=' . $event }, $timeout);
}
sub mailboxcount {
my ($self, $exten, $context, $timeout) = @_;
my $action = $self->action({ Action => 'MailboxCount',
Mailbox => $exten . '@' . $context }, $timeout);
if ($action->{'GOOD'}) {
return $action->{'PARSED'};
}
return;
}
sub mailboxstatus {
my ($self, $exten, $context, $timeout) = @_;
my $action = $self->action({ Action => 'MailboxStatus',
Mailbox => $exten . '@' . $context }, $timeout);
if ($action->{'GOOD'}) {
return $action->{'PARSED'}->{'Waiting'};
}
return;
}
sub chan_timeout {
my ($self, $channel, $chantimeout, $timeout) = @_;
return $self->simple_action({ Action => 'AbsoluteTimeout',
Channel => $channel,
Timeout => $chantimeout }, $timeout);
}
sub queues {
my ($self, $timeout) = @_;
my $action = $self->action({ Action => 'QueueStatus' }, $timeout);
return unless ($action->{'GOOD'});
my $queues;
foreach my $event (@{$action->{'EVENTS'}}) {
my $qevent = $event->{'Event'};
my $queue = $event->{'Queue'};
delete $event->{'Event'};
delete $event->{'ActionID'};
delete $event->{'Queue'};
if ($qevent eq 'QueueParams') {
while (my ($key, $value) = each %{$event}) {
$queues->{$queue}->{$key} = $value;
}
} elsif ($qevent eq 'QueueMember') {
my $name = $event->{'Name'};
delete $event->{'Name'};
$queues->{$queue}->{'MEMBERS'}->{$name} = $event;
} elsif ($qevent eq 'QueueEntry') {
my $pos = $event->{'Position'};
delete $event->{'Position'};
$queues->{$queue}->{'ENTRIES'}->{$pos} = $event;
}
}
return $queues;
}
sub queue_status {
my ($self, $queue, $timeout) = @_;
my $action = $self->action({ Action => 'QueueStatus',
Queue => $queue }, $timeout);
return unless ($action->{'GOOD'});
my $queueobj;
foreach my $event (@{$action->{'EVENTS'}}) {
lib/Asterisk/AMI/Common.pm view on Meta::CPAN
my $ver = $self->amiver();
if (defined $ver && $ver >= 1.1) {
return $self->simple_action({ Action => 'ModuleCheck',
Module => $module }, $timeout);
} else {
my $resp = $self->action({ Action => 'Command',
Command => 'module show like ' . $module }, $timeout);
return unless (defined $resp && $resp->{'GOOD'});
if ($resp->{'CMD'}->[-1] =~ /(\d+)\ .*/x) {
return 0 if ($1 == 0);
return 1;
}
return;
}
}
sub module_load {
my ($self, $module, $timeout) = @_;
return $self->simple_action({ Action => 'ModuleLoad',
LoadType => 'load',
Module => $module }, $timeout );
}
sub module_reload {
my ($self, $module, $timeout) = @_;
return $self->simple_action({ Action => 'ModuleLoad',
LoadType => 'reload',
Module => $module }, $timeout );
}
sub module_unload {
my ($self, $module, $timeout) = @_;
return $self->simple_action({ Action => 'ModuleLoad',
LoadType => 'unload',
Module => $module }, $timeout );
}
sub originate {
my ($self, $chan, $context, $exten, $callerid, $ctime, $timeout) = @_;
my %action = ( Action => 'Originate',
Channel => $chan,
Context => $context,
Exten => $exten,
Priority => 1,
);
$action{'CallerID'} = $callerid if (defined $callerid);
if (defined $ctime) {
$action{'Timeout'} = $ctime * 1000;
if ($timeout) {
$timeout = $ctime + $timeout;
}
}
return $self->simple_action(\%action, $timeout);
}
sub originate_async {
my ($self, $chan, $context, $exten, $callerid, $ctime, $timeout) = @_;
my %action = ( Action => 'Originate',
Channel => $chan,
Context => $context,
Exten => $exten,
Priority => 1,
Async => 1
);
$action{'CallerID'} = $callerid if (defined $callerid);
$action{'Timeout'} = $ctime * 1000 if (defined $ctime);
my $actionid = $self->send_action(\%action);
#Bypass async wait, bit hacky
#allows us to get the intial response
delete $self->{RESPONSEBUFFER}->{$actionid}->{'ASYNC'};
return $self->check_response($actionid, $timeout);
}
1;
( run in 1.777 second using v1.01-cache-2.11-cpan-97f6503c9c8 )