Tropo is part of CiscoLearn More

Collecting Digits

In the Asking for Digits Quick Start, we introduced the [DIGITS] grammar and used it to tell Tropo to expect 1 digit. You can also express a range of digits by using [4-5 DIGITS] instead (the number values are defined by you; it could be [10-20 DIGITS], [1-2 DIGITS], and so on). If your caller enters 4 digits instead of 5, Tropo will wait 4 seconds before considering the input complete. If you want to allow your callers to press a key to tell Tropo they're done, just add the terminator parameter to your ask statement and set it to the key they should press.

Because there are two primary ways of interacting with users over the phone (DTMF - which is touch-tone input - and voice) and by default Tropo will listen for input in both modes, we'll want to specify "dtmf" input for our pin number request. This behavior can be controlled using the mode parameter. Possible values are 'dtmf', 'speech' or 'any':

ask("What's your four or five digit pin? Press pound when finished", {
    choices:"[4-5 DIGITS]",
    terminator:"#",
    mode:"dtmf",
    onChoice: function(event) {
        say("Thank you");
    }
});
ask "What's your four or five digit pin?  Press pound when finished", {
    :choices => "[4-5 DIGITS]",
    :terminator => '#',
    :timeout => 15.0,
    :mode => "dtmf",
    :onChoice => lambda { |event|
        say "Thank you"
    }
}
<?php
    ask("What's your four or five digit pin? Press pound when finished", array(
        "choices"=>"[4-5 DIGITS]",
        "terminator" => "#",
        "timeout" => 15.0,
        "mode" => "dtmf",
        "onChoice" => "choiceFCN" 
        )
    );
    function choiceFCN($event) {
        say("Thank you");
        }
?>
ask("What's your four or five digit pin? Press pound when finished.", {
    "choices":"[4-5 DIGITS]",
    "terminator":"#",
    "timeout":15.0,
    "mode":"dtmf",
    "onChoice": lambda event : say("Thank you")
})
ask("What's your four or five digit pin?  Press pound when finished.", [
    choices: "[4-5 DIGITS]",
    terminator: '#',
    timeout: 15.0,
    mode: "dtmf",
    onChoice: { event->
        say("Thank you.")
    }
])

Note that if you set the mode parameter to 'dtmf', you can set the choices to * or # as well; it's not restricted to numbers alone.

Tropo is capable of so much more than just digits and dtmf input - you can also use Tropo’s simple grammar notation to recognize words and even entire phrases.