使用Alexa.net-我可以从代码中调用意图吗?

时间:2018-12-03 20:30:43

标签: c# alexa alexa-skills-kit alexa-skill alexa-voice-service

我正在尝试使用alexa.net构建测验游戏。但是我遇到了潜在的问题。

只要用户回答了问题并且评估了答案,我都想立即提出另一个问题。

目前,用户必须手动请求另一个问题。我想发生的事情是,处理问题的意图一直不断地自我呼叫,直到用户积极选择结束游戏为止。

那有可能吗?如果是这样,有人可以指出正确的方向,甚至可以写一个简短的hello-world风格的例子吗?

1 个答案:

答案 0 :(得分:4)

假设您要创建一个数学问答游戏,其中Alexa会问您随机的数学问题,并且您必须提供正确的答案。游戏必须继续进行,直到用户明确要求退出为止。

创建一个AnswerIntent,当用户说出答案时触发。我们的答案是数字,因此请使用AMAZON.NUMBER槽创建此意图,以便您捕获所讲的数字。 (根据问题的答案选择您的位置。)

AnswerIntent的示例语音:

{number}
the answer is {number}
is it {number}

{number} -> AMAZON.NUMBER slot

因此,每次用户说出您的问题的答案时,您都会在后端收到一个POST请求,并触发了意图(在这种情况下为AnswerIntent),广告位及其值。然后:

  1. 验证答案。
  2. 更新分数(如果您的用例中有分数)
  3. 生成下一个问题。
  4. 提供下一个问题的答案。

您将仅在与用户互动时在后端接收请求。因此,请确保当用户说出答案时,您的回答中有下一个要问的问题。这样,用户可以继续回答问题而无需明确地提出问题。

示例互动:

User : Alexa, open math quiz
Alexa: Welcome to math quiz. Here is your first question. 
       What is the sum of five and four.
       [you will receive the launch request and your response has the first question]
User : Nine
       [you will receive AnswerIntent request, with number slot having value 9. 
        Validate the answer and generate the next question]
Alexa: Correct!. Here is your next question.
       What is the product of ten and five.
User : Twenty.
Alexa: Wrong, the right answer is fifty. 
       here is your next question.
       What is sum of two and six.
User : Stop
       [AMAZON.StopIntent is triggered and you can now end the game.]
Alexa: Bye.

使用sessionAttributes存储有关问题或其答案的一些信息,以便在收到用户响应时可以在后端轻松验证它。

相关问题