Soporte & Consultoria

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

sábado, 11 de enero de 2025

getting read variable value from agi GET VAARIABLE

 #!/usr/bin/php

<?php


// Send the Read command to capture user input

echo "EXEC Read opt,demo-thanks,1\n";

flush(); // Ensure the command is sent to Asterisk


// Capture the response for EXEC Read

while (!feof(STDIN)) {

    $line = trim(fgets(STDIN));

    if (strpos($line, '200 result=') === 0) {

        break; // Stop reading after receiving the result

    }

}


// Send the GET VARIABLE command to retrieve the value of 'opt'

echo "GET VARIABLE opt\n";

flush(); // Ensure the command is sent to Asterisk


// Initialize a variable to store the result

$userInput = null;


// Capture the response for GET VARIABLE

while (!feof(STDIN)) {

    $line = trim(fgets(STDIN));

    if (preg_match('/^200 result=1 \((.*)\)$/', $line, $matches)) {

        $userInput = $matches[1]; // Store the captured value

        break;

    }

}


// Use the captured value

if ($userInput !== null) {

    echo "VERBOSE \"Captured user input: $userInput\"\n"; // Debug output to Asterisk CLI

    flush();

}


?>