2

I'm creating an application in Tropo using Python and I was wondering if I could create a small grammar that is local. I've read about external grammars SRGS and GRXML but can I create one using a Python list right in the code. Below is what I'm trying to do.

food = ['cheeseburger', 'hot dog', 'salad']

ask("What food would you like?",
    #{'choices': "cheeseburger, hot dog, salad",
    {'choices': food,
    'attempts':3,
    'onChoice': fill,
    'onBadChoice': nomatch,
    'onTimeout': noinput })

The above code compiles but it hangs up when it gets to this question.

user2743
  • 1,423
  • 3
  • 22
  • 34

2 Answers2

1

If you want Tropo to ask the caller "What food would you like", and give them 3 attempts to answer with one of the phrases in 'food', try sending the following json response:

{
  "tropo": [
    {
      "ask": {
        "choices": {
          "value": "cheeseburger, hot dog, salad",
          "mode": "speech",
          "terminator": "#"
        },
        "attempts": 3,
        "name": "foodchoice",
        "recognizer": null,
        "required": null,
        "say": {
          "value": "What food would you like"
        }
      }
    },
    {
      "on": {
        "event": "continue",
        "name": null,
        "next": "/fill",
        "required": true
      }
    },
    {
      "on": {
        "event": "incomplete",
        "name": null,
        "next": "/noinput",
        "required": true
      }
    },
    {
      "on": {
        "event": "error",
        "name": null,
        "next": "/nomatch",
        "required": true
      }
    }
  ]
}

To answer your question exactly, you would need to understand the Python Tropo library. I'm not familiar with the python one but Tropo's Java and NodeJS libraries seem to be out of date...so if the Python one is too then you will have to do some more work to build and return this JSON object.

michael256
  • 71
  • 6
0

According to the example in the Tropo docs:

result = ask("What's your favorite color? Choose from red, blue or green.", {
   "choices":"red, blue, green"})
say("You said " + result.value)
log("They said " + result.value)

choices is a string, not a list, so you'd want to do this instead:

food = "cheeseburger, hot dog, salad"

ask("What food would you like?",
    {'choices': food,
    'attempts':3,
    'onChoice': fill,
    'onBadChoice': nomatch,
    'onTimeout': noinput })
yed
  • 322
  • 2
  • 5