Queue status

Hi, I am trying to Run the Hangup AGI script in my queue to know which Agent answer the call, and if no one answered, after some days I can now get who answer the call by run the following context
[macro-hangupcall]
exten => s,1,GosubIf($["${CDR(channel)}"=~“from-queue” & “${CDR(disposition)}” = “ANSWERED”]?callAns,1)
exten => callAns,1,AGI(callAns.php,${CDR(dstchannel)},${CALLERID(num)},${CDR(clid)})
exten => callAns,n,Return

but I don’t know how can I run the AGI script if no one answer, the script always run even if the agent answers the call, because the other agents still count as No Answer in ${CDR(disposition)}

Thanks.

This is a good place to start:

After that, you need to provide more details, because honestly it sounds like the system is working exactly the way it’s supposed to.

I already read this article many times, but without any luck, for example, if I used this one and I have 3 extensions in my queue

[macro-dialout-one-predial-hook]
exten = s,1,Noop(Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf)
exten = s,n,Set(CHANNEL(hangup_handler_push)=lgaetz-do-this-on-hangup,s,1)
exten = s,n,MacroExit

[lgaetz-do-this-on-hangup]
exten = s,1,Noop(Entering user defined context lgaetz-do-this-on-hangup in extensions_custom.conf)
exten => s,n,Return

I will get this

[2021-07-07 12:30:22] VERBOSE[32302][C-00005a64] pbx.c: Executing [s@macro-dialout-one-predial-hook:2] Set("Local/987@from-queue-000002e9;2", "CHANNEL(hangup_handler_push)=lgaetz-do-this-on-hangup,s,1") i           n new stack
[2021-07-07 12:30:23] VERBOSE[32301][C-00005a64] pbx.c: Executing [s@macro-dialout-one-predial-hook:2] Set("Local/399@from-queue-000002e8;2", "CHANNEL(hangup_handler_push)=lgaetz-do-this-on-hangup,s,1") i           n new stack
[2021-07-07 12:30:23] VERBOSE[32303][C-00005a64] pbx.c: Executing [s@macro-dialout-one-predial-hook:2] Set("Local/220@from-queue-000002ea;2", "CHANNEL(hangup_handler_push)=lgaetz-do-this-on-hangup,s,1") i           n new stack

for example, if 220 answered,

[2021-07-07 12:30:22] VERBOSE[32302][C-00005a64] pbx.c: Executing [s@macro-dialout-one-predial-hook:2] Set("Local/987@from-queue-000002e9;2", "CHANNEL(hangup_handler_push)=lgaetz-do-this-on-hangup,s,1") i           n new stack
[2021-07-07 12:30:23] VERBOSE[32301][C-00005a64] pbx.c: Executing [s@macro-dialout-one-predial-hook:2] Set("Local/399@from-queue-000002e8;2", "CHANNEL(hangup_handler_push)=lgaetz-do-this-on-hangup,s,1") i           n new stack

I will get the rest of the extensions one by one so my AGI scrip will be fired 2 times, I just want to get the status of the queue if someone answered or no one does.

I find a solution to find if the call was answered or No, I believe it’s not a good solution but it’s worked, please if anyone has a better solution let me know.

my solution is to connect to DB after 4 seconds of hangup the call and check if there is an Answer status ,

#!/usr/bin/php -q
<?php

require('/var/lib/asterisk/agi-bin/phpagi.php');

$AGI = new AGI();

$CHNNEL_ID = $argv[1];

$db_host = "localhost";
$db_username = "root";
$db_password = "";

try {
  $conn = new PDO("mysql:host=$db_host;dbname=asteriskcdrdb", $db_username, $db_password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

} catch(PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
  exit();
}
sleep(4);
$query = 'SELECT * FROM asteriskcdrdb.cdr where linkedid = "'.$CHNNEL_ID.'" and disposition = "ANSWERED"';
$stmt = $conn->prepare($query);
$stmt->execute();


$number_of_rows = $stmt->rowCount();

if ($number_of_rows > 0) {
echo "Call_Answered";
} else {
  echo "Call_Not_Answered";
}
exit();
?>

I already add my AGI code as DeadAGI in [macro-hangupcall] context ,

exten => s,n,DeadAGI(toInternal.php,${CDR(uniqueid)},${CALLERID(num)})

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.