How to use # key as Input in sip

Dear Team,

As im using asterisk agi but when im tring to use # kay as a input then it wont take as input it only tak as a termination key. can you hepl me how to use # key as input key.

Please post your relevant code snippet wrapped in preformatted text tags.

You can use the AGI command ‘wait for digit’ to read all keys. Here’s a snippet from one of my AGIs:

// accumulate digits
        memset(entered_digits, 0, sizeof(entered_digits));
        entered_digits_pointer = entered_digits;
        length = sizeof(entered_digits);
        while   (0 != length)
                {
                if      (0 != agi_environment.result)
                        {
                        if      ((*termination_key == agi_environment.result)
                        ||       ('*' == agi_environment.result))
                                {
                                break;
                                }
                        *entered_digits_pointer++ = agi_environment.result;
                        --length;
                        }
                agi_exec("wait for digit 5000");
                if      (0 == agi_environment.result)
                        {
                        break;
                        }
                }

This snippet, executed after playing a prompt, accumulates digits until the ‘termination key’ or ‘asterisk’ is pressed. The ‘asterisk’ is the ‘pause’ key in this application.

AGI means you re using an external programming language so post the code to check of the application accept any parameter to modify this behavior

Dear Team,

AGI Means im working on PHPAGI.
I created an asterisk IVR library File.
I want to achieve If the customer presses # key it should not read as termination key it should read as input value.

public function input($inputSoundFileName, $timeout, $retryLimit = 0, $inputSize, $validInputs = ‘’, $invalidSoundFileName = ‘’, $noInputSoundFileName = ‘’, $maxTriesSoundFileName = ‘’) {
$response = null;
if($this->isInitialised){
$startTime = date(“Y-m-d H:i:s”, time());
$this->initNode(‘INPUT’, $inputSoundFileName, ‘OPTION’, $startTime);
$retryCount = 1;
labelInput:
$this->executeAGI(‘EXEC SET RETRY_COUNT=’ . $retryCount);
if($retryCount > ($retryLimit)){
if($maxTriesSoundFileName != null){
$this->executeAGI('EXEC Playback '.$this->currentSoundPath.$maxTriesSoundFileName);
}
$response = $this->STATUS_MAX_TRIES_EXCEEDED;
Goto labelEnd;
}
$enteredInput = $this->executeAGI('GET DATA ’ .$this->currentSoundPath.$inputSoundFileName. ’ ’ . $timeout . ’ ’ . $inputSize);
$input = $enteredInput[‘result’];
if($input == null){
if($noInputSoundFileName != null){
$this->executeAGI('EXEC Playback '.$this->currentSoundPath.$noInputSoundFileName);
}
$retryCount++;
Goto labelInput;
}
if($validInputs != null){
$input = intval($input);
if (validInputs!=null && !in_array($input, $validInputs)){
if($invalidSoundFileName != null){
$this->executeAGI('EXEC Playback '.$this->currentSoundPath.$invalidSoundFileName);
}
$retryCount++;
Goto labelInput;
}
}
$response = $input;
labelEnd:
$endTime = date(“Y-m-d H:i:s”, time());
$this->createIVRNodeTraversalLogs(‘INPUT’, $inputSoundFileName, ‘OPTION’, $response, $retryCount, $startTime, $endTime, ‘NODEEXIT’);

} else{
$this->showInConsole(‘NotInitilisedException: Please initialise the API before using it’);
throw new Exception(‘NotInitilisedException: Please initialise the API before using it’);
}
return $response;
}

public function executeAGI($command) {
fwrite(STDOUT, “$command\n”);
fflush(STDOUT);
$result = trim(fgets(STDIN));
$response = array(‘code’=> -1, ‘result’=> -1, ‘timeout’=> false, ‘data’=> ‘’);
if (preg_match("/^([0-9]{1,3}) (.*)/", $result, $matches)) {
$response[‘code’] = $matches[1];
response['result'] = 0; if (preg_match('/^result=([0-9a-zA-Z]*)\s?(?:\(?(.*?)\)?)?/’, $matches[2], $match)) {
$response[‘result’] = $match[1];
$response[‘timeout’] = ($match[2] === ‘timeout’) ? true : false;
$response[‘data’] = $match[2];
}
}
self::writeLogs($command, $result, $response);
return $response;
}

If using the phpagi class for an IVR and tusing the method get_data (), You must be aware Pressing the # key has the same effect as the timer running out: the command ends and any previously keyed digits are returned. A side effect of this is that there is no way to read a # key using this command.

Try with exec method and background()

i already try with background but it is not working.
Do you have any other option or any code ?

  1. Please post code snippets with preformatted text tags.

  2. Did you try ‘wait for digit’?

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