Asterisk getting error Dial argument takes format (technology/resource) == Spawn extension (phones, 1001, 3) exited non-zero on 'SIP/MANISHADHAKAR-0000004c'

Here is my php script::

#!/usr/bin/php -q
<?php
$dbusername = "asterisk";
$dbname     = "myphonesystems";
$dbpass     = "Asterisk@123";
$dbhost     = "127.0.0.1";

// Connect to the database
$conn = mysqli_connect("$dbhost", "$dbusername", "$dbpass", "$dbname");

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Import the PHPAGI library
require_once('/var/lib/asterisk/agi-bin/phpagi.php');

// Create an instance of the AGI class
$agi      = new AGI();
$userName = $agi->request['agi_arg_1'];
$ext      = $agi->request['agi_arg_2'];
$user_id  = $agi->request['agi_arg_3'];
$sip_file = "/etc/asterisk/sip.conf";
$file     = fopen($sip_file, 'r');
// $user_id = null;

// Read the file line by line
while (($line = fgets($file)) !== false) {
Check if the line starts with the user's name in square brackets
    if (preg_match('/^\[' . preg_quote($userName) . '\]/', $line)) {
        // If it does, set the $user_data variable
        $user_data = $line;
        // Extract the user ID from the SIP configuration
        if (preg_match('/^user_id=(\d+)/', $line, $matches)) {
            $user_id = $matches[1];
        }
    }
}

fclose($file);

if ($user_id) {
    if ($ext == "get_number") {
        $extension_query = "SELECT extension_name FROM extensionmps WHERE user_id=?";
        $stmt            = mysqli_prepare($conn, $extension_query);
        mysqli_stmt_bind_param($stmt, "i", $user_id);
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        if ($row = mysqli_fetch_assoc($result)) {
            $cuser = $row['extension_name'];
            $agi->verbose($cuser);
            $agi->set_variable("CALLERID(num)", $userName);
            $agi->set_variable("CALLERID(name)", $userName);
            $agi->set_variable('call_number', $cuser);
        }
        mysqli_stmt_close($stmt);
    }
} else {
    $agi->verbose("User with username $userName is not registered");
}

Dial the extension number
$dial = $agi->exec("Dial", "SIP/${call_number}");

// Hang up the call
$agi->exec("Hangup", "");
?>

extension.conf file::
[phones]
exten => _X.,1,NoOp(Entering my-dialplan)

same => n,Set(userName=${CALLERID(num)})

same => n,AGI(call.php,${userName},get_number)

same => n,Dial(SIP/${userName}, 20)

same => n,Hangup()

You have most likely attempted to dial “SIP/” without specifying anything to dial for SIP.

Thank you…
can you please explain by editing the code. that would be more helpful.

I don’t touch PHP code or change code like that for others.

oh okay. Thanks for the reply.

What do you see in a verbose log file output when that context gets executed?

Antony.

executed.

WARNING[21126][C-000177ef]: app_dial.c:2348 dial_exec_full: Dial argument takes format (technology/resource)
== Spawn extension (phones, 1001, 3) exited non-zero on ‘SIP/MANISHADHAKAR-0000004c’

I think the actual problem is that they have passed ${call_number}, literally, as the resource, so this is PHP error. I won’t provide corrected code, as I don’t do paid consultancy, and there may well be other errors in the longish PHP code. You could try the Jobs forum.

ok. thanks.

You should also note that chan_sip is no longer in the master GIT source code for Asterisk, as it will not be in version 21.