A
A
Alexander2015-12-28 14:18:22
PHP
Alexander, 2015-12-28 14:18:22

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;
    }
}

Is there a better solution?
The task is quite simple, you need to get a phone number of the form 8xxxxxxxxxx from the caller. Entering the number ends by pressing "*".
UPD (30/12/2015):
So far I have settled on this solution:
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

2 answer(s)
V
Vladimir, 2015-12-28
@rostel

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.

A
alexdora, 2015-12-29
@alexdora

I myself have not been looking for a long time how to catch a number.
Here, maybe this question-answer will help you, only here is the lattice: How to implement such a call scheme?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question