I am trying to build a quiz game using alexa.net. However i´ve run into a potential problem.
Whenever the user has answered a question and the answer has been evaluated i want to immediately ask another question.
As it is right now, the user has to manually request another question. What i would like to have happen, was that the intent that handles the question keeps calling itself until the user actively chooses to end the game.
Is that even possible? If so, can anyone point me in the right direction, maybe even write up a brief hello-world style example?
Suppose you want to create a math quiz game where Alexa will ask you random math questions and you have to provide the right answer. The game has to continue until the user ask specifically to quit.
Create an AnswerIntent
which is triggered when the user says an answer. Our answers are numbers, so create this intent with AMAZON.NUMBER
slot which lets you capture the numbers spoken. (Choose your slot according to the answers for your questions).
Sample utterance for AnswerIntent
:
{number}
the answer is {number}
is it {number}
{number} -> AMAZON.NUMBER slot
So each time when the user says an answer to your question you will receive a POST
request in your backend with the intent triggered (in this case AnswerIntent
), slot and its value. Then:
You will only receive a request at your backend when there is a user interaction. So make sure that when the user says an answer, your response has the next question to asked. In this way the user can continue answering questions without asking for a question explicitly.
Sample Interaction:
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.
Use sessionAttributes
to store some information about the question or its answer so that you can validate it easily at the backend when your receive a response from the user.