Tropo is part of CiscoLearn More

Handling No Input or Bad Input

What if the user never responds to your ask, responds with something other than the possible choices you’ve specified or responds with something Tropo doesn’t understand? You’d probably like to tell the user they made a bad choice, and possibly provide more information so they can respond properly. To do this, just use the optional onBadChoice and onChoice event handlers:

ask("What's your favorite color?", {
    choices: "red, blue, green",
    timeout: 10.0,
    attempts: 3,
    onBadChoice: function(event) {
        say("I'm sorry,  I didn't understand that. You can select red, blue, or green.");
    },
    onChoice: function(event) {
        say("You chose " + event.value);
    }
});
ask "What's your favorite color?", {
    :choices => "red, blue, green",
    :timeout => 10.0,
    :attempts => 3,
    :onBadChoice => lambda { |event|
        say "I'm sorry,  I didn't understand that. You can select red, blue, or green."
    },
    :onChoice => lambda { |event|
        say "You chose " + event.value
    }
}
<?php

ask("What's your favorite color?", array(
    "choices" => "red, blue, green",
    "timeout" => 10.0,
    "attempts" => 3,
    "onChoice" => "choiceFCN",
    "onBadChoice" => "badChoiceFCN"
    )
);
function choiceFCN($event) {
    say("You chose" . $event->value);
}
function badChoiceFCN($event) {
    say("I'm sorry,  I didn't understand that. You can select red, blue, or green.");
}

?>
ask("What's your favorite color?", {
    "choices":"red, blue, green",
    "timeout":10.0,
    "attempts":3,
    "onChoice": lambda event : say("You chose " + event.value),
    "onBadChoice": lambda event : say("I'm sorry,  I didn't understand that. You can select red, blue, or green.")
})
ask("What's your favorite color?", [
    choices: "red, blue, green",
    timeout: 10.0,
    attempts: 3,
    onChoice: {event->
        say("You chose $event.value")
    },
    onBadChoice: {event->
        say("I'm sorry,  I didn't understand that. You can select red, blue, or green.")
    }
])

For all of the options for the ask method, see the detailed API reference.