Tropo is part of CiscoLearn More

Asking for Digits

Tropo supports a number of simple ways to specify available choices. For example, if you want to collect a single digit input from a user, you could do this:

result=ask("Pick a number from 0 to 9", {
   choices:"0,1,2,3,4,5,6,7,8,9"
});
say("You said " + result.value);
log("They said " + result.value);
result = ask "Pick a number from 0 to 9", {
  :choices => "0,1,2,3,4,5,6,7,8,9"}
say "You said " + result.value
log "They said " + result.value
<?php

$result = ask("Pick a number from 0 to 9", array(
  "choices" => "0,1,2,3,4,5,6,7,8,9"
));
say("You said" . $result->value);
_log("They said " . $result->value);

?>
result = ask("Pick a number from 0 to 9", {
  "choices":"0,1,2,3,4,5,6,7,8,9"})
say("You said " + result.value)
log("They said " + result.value)
result = ask("Pick a number from 0 to 9", [
  choices: "0,1,2,3,4,5,6,7,8,9"])
say("You said $result.value")
log("They said $result.value")

But Tropo also has a variety of built-in shortcuts you can use in the Choices parameter. One of those is the DIGIT shortcut. You can replace the numbered list with a built-in shortcut [1 DIGIT] in your choice:

result=ask("Pick a number from 0 to 9", {
    choices:"[1 DIGIT]"
});
say("You said " + result.value);
log("They said " + result.value);
result = ask "Pick a number from 0 to 9", {
 :choices => "[1 DIGIT]"}
say "You said " + result.value
log "They said " + result.value
<?php

$result = ask("Pick a number from 0 to 9", array(
 "choices" => "[1 DIGIT]"
));
say("You said" . $result->value);
_log("They said " . $result->value);

?>
result = ask("Pick a number from 0 to 9", {
 "choices":"[1 DIGIT]"})
say("You said " + result.value)
log("They said " + result.value)
result = ask("Pick a number from 0 to 9", [
 choices: "[1 DIGIT]"])
say("You said $result.value")
log("They said $result.value")

Or if you want the user to enter their four digit pin code, just replace the ask prompt with

“Please enter your four digit pin”

and change the [1 DIGIT] choices to [4 DIGITS]

The term for the list of available choices is a "grammar". The "choices" Tropo uses here to allow you to specify possible user inputs is in a format called Simple Grammar. It provides a way to specify complex inputs with a more simple syntax.