Pickup Application not working for all extensions Asterisk 18.22

Hi guys,

I have a piece of code in PHP called via the AGI, the function is as follows:

  function exec_callpickup($agi, $custid, $pickup_exten) {
        $callgroup = $agi->get_variable("CHANNEL(callgroup)");

        $exten_string = '';
        $query = "SELECT `exten`,`exten_type` FROM tp_callpickup INNER JOIN `tp_callpickupexten` on  `tp_callpickupexten`.`callpickup_id` =  `tp_callpickup`.`callpickup_id` WHERE `callpickup_code` = '$pickup_exten' AND `customer_id` = '$custid'";

        if ($res = $this->sqlQuery($query, $agi, 'exec_callpickup')) {
            while ($result = mysqli_fetch_assoc($res)) {
                if ($exten_string != '')
                    $exten_string.='&';
                $exten = $result['exten'];
                $exten_type = $result['exten_type'];             
                if ($exten_type == 'DID')
                    $exten_string .= $exten . '@' . $this->context;
            }
        }
         $exten_string = '';
        $agi->exec('PickUp', $exten_string);
        $agi->hangup();
    }

The purpose of this function is to ensure that anyone in the call pickup group who dials *56 from his or her extension can answer a ringing phone from someone who is not at their desk. Also, in this function, the database is queried to see who has the privilege to pick up extensions (who is a member of the call pickup group, which in my case is *56), and those extensions are returned along with the exten_type. Something like this:

exten exten_type
5600 EXTEN
5601 EXTEN

Now, the function works for some extensions but not for others. I’m attaching a screenshot below to show how it works (on the right) and does not work (on the left) for different extensions:

There is no issue with the databsae connection or with the calling of AGI so that’s out of question (pretty sure).

Can anyone please guide me how I fix this to work for all extensions in the *56 call pickup group?

Thanks,
Hisham

That kind of thing always makes me nervous. Get into the habit of properly escaping query parameters to avoid future trouble.

The Pickup application is being called with no arguments, so per the documentation[1] it would pick up channels that match the pickup group of the channel. Is this the case?

[1] Pickup - Asterisk Documentation

Please don’t post pictures of output.

can you please elaborate a little on this?

Hi @jcolp ,

I think the Pickup() application is indeed being called with extesn_string as an argument as seen below…

You’re setting it to empty immediately prior to calling it.

Pick up groups have only relevant people to be able to dial it in order to pickup calls of absentees/unavailable users. If a person who’s not part of the pick up group tries to dial the code to pickup the call won’t be able to do so.