question

Shaun Clark avatar image
Shaun Clark asked

How to launch another response.ask

So ive got a function wokring, and its working as expected. var myfunction = function myfunction(intent, session, response) { var PHRASES = [ 'what do you want', 'what can i do for you' ]; var phraseIndex = Math.floor(Math.random() * PHRASES.length); var phrase = PHRASES[phraseIndex]; response.ask(phrase, phrase); }; module.exports = what do you want; However my question, once you give alexa your reply, how do you invoke another question, so response.ask("What can i do for you) the user respondse with "Call me shaun" If (response == "Call me shaun) { response.tell("Hello Shaun) }
alexa skills kitdebugging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Galactoise avatar image
Galactoise answered
I think the question you're asking is how to have stateful behavior on your service when the client itself makes stateless REST requests, correct? Or, put into your example, you're wondering how to know which code path to execute when the intent was actually a user's response to an earlier question? If that's what you're looking for, you do that through session attributes. When you make your initial response to the user, you can set these attributes, and then when the user responds, all of the attributes that you set on the previous response will be included with the incoming intent. This lets you essentially set flags (something like {"previousQuestion":"What can I do for you?"} that track your workflow. You can then use the combination of the intent data and the session attributes to know how to choose a code path.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mm-nickname avatar image
mm-nickname answered
As mentioned before, using the session state is a great way to build up conversation trees For an example of how to use the session attributes check out the ColorExpert example which is created when starting a new Lambda function. This example skill makes use of saving state data and reusing later, also the code is really easy to follow too!
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.