0
votes

I can get the call running the AGI, but I am not able to continue running the extensions.conf dial plan while my Perl script runs its loop.

So I need away to run this AGI in the background when the call is dialed.

The part of my AGI that is screwing up:

{
    my $linestatus = $agi->channel_status();

    ###THIS PART NEEDS TO LOOP UNTIL $linestatus == 6
    ###But It is also stopping the number from dialling.
    do{
    }
    until($linestatus == 6);

    my $query  = $collection->insert({
        caller     => $num,
        callername => $name,
        linestatus => $linestatus,
        extension  => $ext,
        call_start => $time }, {safe => 1});

    $agi->verbose("ANSWERED\n", 1);
}

My extensions.conf dial plan:

exten => _08.,1,AGI(bTel.agi)
exten => _08.,n,Dial(SIP/61${EXTEN:1}@SIPINTERNAL,,tTor)
exten => _08.,n,Hungup
1

1 Answers

3
votes

If

do{
}
until($linestatus == 6);

is a verbatim copy of your code, then the loop cannot terminate if $linestatus begins in the wrong state because its value does not change within the loop.

Instead, use code along the lines of

my $linestatus;
do {
    $linestatus = $agi->channel_status();
    sleep 1;  # or some other delay
} until (defined $linestatus && $linestatus == 6);