Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

domingo, 1 de diciembre de 2024

Ajax call file

<title>AJAX Timer Example</title>


<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>


<script>


function callAgentConf() {

    // Fetch the session variable via PHP and inject it into the URL

    $.ajax({

        type: "GET",  // Use GET method

        url: "call_file.php",  // Path to the PHP script

        data: { wpExten: "<?= $_SESSION['wpExten']; ?>" },  // Pass the session variable using GET

        success: function(data) {

            console.log(data); // Log the response from the server

            if (data == 'ok') {

                txtCallStatus.innerHTML = "<i><?=$TEXT_Entrato_in_conferenza?></i>"; // Success message

                gotConf = false; // Set a variable (you can modify or use it as needed)

            } else {

                txtCallStatus.innerHTML = "<i><?=$TEXT_Errore_Non_entrato_in_conferenza?></i>"; // Error message

            }

        }

    });

}


// Call the function after 1 second

setTimeout('callAgentConf()', 1000);

</script> </head> <body>

------------

 <?php

session_start();  // Make sure session is started if you are using session variables


// Retrieve the 'wpExten' GET parameter from the URL (passed via AJAX)

if (isset($_GET['wpExten'])) {

    // Use the GET parameter to set $myPaddedUserId

    $myPaddedUserId = "989898" . str_pad($_GET['wpExten'], 6, '0', STR_PAD_LEFT);


    // Debugging: Output the $myPaddedUserId to make sure it was set correctly

    // echo "Using wpExten: " . $myPaddedUserId;


    // Running the system command to kick the user from the conference bridge

    $sysCmd = "/usr/bin/sudo /usr/sbin/asterisk -rx 'confbridge kick ".$myPaddedUserId." all'";

    $foo = `$sysCmd`;  // Execute the system command


    // Prepare the .call file contents

    $callFilePath = "/tmp/" . rand(1000000, 9999999) . ".call";

    $dialString = "Channel: SIP/" . $myPaddedUserId;

    $callFileContents = $dialString . "\n" .

                        "MaxRetries: 0\n" .

                        "Context: sidialConfBridges\n" .

                        "Extension: " . $myPaddedUserId . "\n" .

                        "Set: myExten=" . $myPaddedUserId . "\n" .

                        "CallerID: conf <conf>\n" .

                        "WaitTime: 10";


    // Write the .call file

    $fh = fopen($callFilePath, "w");

    fwrite($fh, $callFileContents);

    fclose($fh);


    // Move the .call file to the outgoing directory

    $sysCmd = "/usr/bin/sudo /bin/mv " . $callFilePath . " /var/spool/asterisk/outgoing/" . rand(1000000, 9999999) . ".call";

    $foo = `$sysCmd`;  // Execute the system command


    // Output 'ok' to indicate success

    echo "ok";

} else {

    // If the 'wpExten' parameter is not provided, return an error

    echo "error: wpExten parameter missing";

}

?>


No hay comentarios:

Publicar un comentario