Answer the question
In order to leave comments, you need to log in
How to get a set of DTMF signals in an AGI script with input ending with "*"?
stream_file only waits for 1 DTMF input, wait_for_digit too, get_data waits for multiple inputs, but you can't explicitly specify a DTMF value to interrupt input.
So far the only option is:
while(true){
$button=$agi->wait_for_digit(1000);
if(chr($button['result'])!="*"){
$buttons.=$chr($button)
}elseif(chr($button)=="*" && strlen($buttons)<11){
$agi->exec("Playback","wrong_number");
}else{
break;
}
}
function ask_msisdn($iswrong=false){
global $agi,$main_cfg;
$msisdn='';
//Промт ввода номера
if(!$iswrong){
$agi->exec("Playback",$main_cfg['sound_dir'].MSISDN_INPUT);
}
//допустимые значения
$correct_numbers=array('0','1','2','3','4','5','6','7','8','9');
while(true){
//ждём DTMF полсекунды
$pressed=$agi->wait_for_digit(500);
$digit=chr($pressed['result']);
if(in_array($digit,$correct_numbers)){
//корректное значение, добавляем к массиву
$msisdn[]=$digit;
}elseif($digit=="*"&&count($msisdn)==11){
//Набраны все 11 цифр, завершен набор нажатием звездочки
break;
}elseif($digit=="*"&&count($msisdn)<11){
//Набрано меньше 11 цифр, запрашиваем снова
$agi->exec("Playback",$main_cfg['sound_dir'].MSISDN_WRONG);
$msisdn=ask_msisdn(true);
}else{
//ничего не нажали
continue;
}
if(isset($msisdn[0])&&$msisdn[0]!='8'){
//проверка первой цифры, нужна строго 8, иначе снова запрашиваем ввод номера
$agi->exec("Playback",$main_cfg['sound_dir'].MSISDN_WRONG);
$msisdn=ask_msisdn(true);
}
}
return $msisdn;
}
Answer the question
In order to leave comments, you need to log in
AGI Command "GET OPTION filename digits timeout"
Behaves similar to STREAM FILE but used with a timeout option.
Streams filename and returns when digits is pressed or when timeout has been reached. Timeout is specified in ms. If timeout is not specified, the command will only terminate on the digits set. Filename can be an array of files or a single filename.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question