尝试在用Python编写的Tropo应用程序中创建简单的本地语法

尝试在用Python编写的Tropo应用程序中创建简单的本地语法,python,tropo,Python,Tropo,我正在使用Python在Tropo中创建一个应用程序,我想知道是否可以创建一个本地的小语法。我已经读过关于外部语法SRGS和GRXML,但是我可以在代码中使用Python列表创建一个语法吗。下面是我想做的 food = ['cheeseburger', 'hot dog', 'salad'] ask("What food would you like?", #{'choices': "cheeseburger, hot dog, salad", {'choices': food

我正在使用Python在Tropo中创建一个应用程序,我想知道是否可以创建一个本地的小语法。我已经读过关于外部语法
SRGS
GRXML
,但是我可以在代码中使用Python列表创建一个语法吗。下面是我想做的

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

上面的代码可以编译,但当它遇到这个问题时会挂断。

如果您想让Tropo询问来电者“您想要什么食物”,并让他们用“食物”中的一个短语尝试回答3次,请尝试发送以下json响应:

{
  "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
      }
    }
  ]
}

要准确回答您的问题,您需要了解Python Tropo库。我不熟悉python one,但Tropo的Java和NodeJS库似乎已经过时了……因此,如果python one太过时,那么您必须做更多的工作来构建并返回此JSON对象。

根据Tropo文档中的示例:

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
是一个字符串,而不是一个列表,因此您需要执行以下操作:

food = "cheeseburger, hot dog, salad"

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