[英]using Alexa.net - can i call an intent from code?
我正在嘗試使用alexa.net構建一個問答游戲。 但是我遇到了一個潛在的問題。
每當用戶回答問題並且評估了答案時,我想立即提出另一個問題。
就像現在一樣,用戶必須手動請求另一個問題。 我想要發生的是,處理問題的意圖一直在調用自己直到用戶主動選擇結束游戲。
這甚至可能嗎? 如果是這樣,任何人都可以指出我正確的方向,甚至可能寫一個簡短的hello-world風格的例子?
假設您想要創建一個數學測驗游戲,其中Alexa將詢問您隨機數學問題,您必須提供正確的答案。 游戲必須持續到用戶專門要求退出為止。
創建一個在用戶說出答案時觸發的AnswerIntent
。 我們的答案是數字,因此請使用AMAZON.NUMBER
插槽創建此意圖,以便您捕獲所說的數字。 (根據您的問題的答案選擇您的插槽)。
AnswerIntent
示例話語:
{number}
the answer is {number}
is it {number}
{number} -> AMAZON.NUMBER slot
因此,每當用戶說出您的問題的答案時,您將在后端收到POST
請求,其中觸發了意圖(在本例中為AnswerIntent
),插槽及其值。 然后:
只有在用戶交互時,您才會在后端收到請求 。 因此,請確保當用戶說出答案時, 您的回答會提出下一個問題 。 通過這種方式,用戶可以繼續回答問題而無需明確詢問問題。
樣本互動:
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
存儲有關問題或其答案的一些信息,以便在收到用戶的響應時可以在后端輕松驗證。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.