using AMI and Telnet to place calls

Home » Asterisk Users » using AMI and Telnet to place calls
Asterisk Users 1 Comment

Hello,
I am using a perl script to pull call info from a DB and place calls via
telnet and AMI, all on local machine of course. My problem is that I
need to capture any response from the carier, such as this taht appears
in the CLI:
[Mar 1 12:55:50] == Using SIP RTP CoS mark 5
[Mar 1 12:55:50] — Got SIP response 503 “No Circuit Available”
back from xxx.xxx.xxx.xxx:5060
[Mar 1 12:55:50] > Channel SIP/ was never answered
and be able to relate that back to the dialed number for that call. Is
this possible?
I am using async in the AMI command. Do I need to do something such as
adding and event id to the AMI originate action then listen for response
from AMI?
Obviously I am a bit lost here.
Thanks for any pointers toward the solution.
JohnM

One thought on - using AMI and Telnet to place calls

  • Since you are using AMI, I would assume you are using one of the AMI
    interfaces from CPAN or somewhere. If this is the case you could do
    something like this:

    my $astman = new Asterisk::Manager;

    $astman->user(‘mickey’);

    $astman->secret(‘mouse’);

    my $man_addr=’192.168.23.172′;

    my $man_ok=1;

    open (my $man_in, “/etc/asterisk/manager.conf”) or
    $man_ok=undef;

    if ($man_ok) {

    while (< $man_in>) {

    if ($_ =~ /^bindaddr/) {

    (undef,$man_addr) = split /=/, $_;

    }

    }

    close $man_in;

    }

    $man_addr =~ s/s//g;

    ( $man_addr )=( $man_addr =~ /(.*)/ );

    $astman->host($man_addr);

    $astman->connect || die “Could not connect to ” .
    $astman->host . “!n”;

    my %resp = $astman->sendcommand( Action => ‘Originate’,

    Channel =>
    $extval,

    Variable =>
    “ARG1=$fileval”,

    Exten => $extval,

    Context =>
    ‘playit’,

    priority => 1,

    Number => 5551212

    );

    sleep 2;

    n Do a while here to interrogate %resp

    %resp = $astman->sendcommand( Action => ‘Logoff’);

    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of John Millican
    Sent: Thursday, March 01, 2012 12:07 PM

    Hello,
    I am using a perl script to pull call info from a DB and place calls via
    telnet and AMI, all on local machine of course. My problem is that I need
    to capture any response from the carier, such as this taht appears in the
    CLI:
    [Mar 1 12:55:50] == Using SIP RTP CoS mark 5
    [Mar 1 12:55:50] — Got SIP response 503 “No Circuit Available” back
    from xxx.xxx.xxx.xxx:5060
    [Mar 1 12:55:50] > Channel SIP/ was never answered
    and be able to relate that back to the dialed number for that call. Is this
    possible?
    I am using async in the AMI command. Do I need to do something such as
    adding and event id to the AMI originate action then listen for response
    from AMI?
    Obviously I am a bit lost here.
    Thanks for any pointers toward the solution.
    JohnM