Ask user for input from LaunchIntent

拈花ヽ惹草 提交于 2019-12-31 07:29:14

问题


I'm writing a skill in Node JS 8. I have an intent set up with slots and it works properly if I say

Ask {skill name} to {utterance}.

I'd like to design my skill so that the user can just say

Open {skill Name}

and on opening it will ask them for input that will then be handled and passed to the intent. I've seen multiple people say that you can't do this. But I've used 2 skills today that did exactly this. I'm just looking for the correct syntax to do this.

I have:

'LaunchRequest': function() {
   this.response.speak("What note would you like?");
   this.emit(':responseReady');
}

Which seems like it should work, but I'm pretty new to JS and Alexa.


回答1:


Yes, it is possible.

When the skill user open your skill, you can give a welcome message followed by a question.
Ex:

[user]  : open note skill  
[Alexa] : Welcome to note skill. What note would you like?  
----------<Alexa will wait for users input>--------  
[user]  : ABC note.  
[Alexa] : <response>

In order for Alexa to wait for users input after it says the welcome message, you need to keep the session alive. The session is kept alive based on shouldEndSession parameter in the response. For any request, if not provided, shouldEndSession defaults to true. In your case, the response to LaunchRequest should have this shouldEndSession parameter set to false. Only by which the session remains open and users can continue interaction.

Ex:

'LaunchRequest': function() {
   const speech = "Welcome to note skill. What note would you like?";
   const reprompt = "What note would you like?";
   this.emit(':ask', speech, reprompt);
}

Read this answer to know more about how you can keep the session alive using ask-nodejs-sdk.

Using Dialog Model
Another way to achieve this is to use Dialog directives. Dialog directives helps you to fill and validate slot values easily. You can use the directives to ask the user for the information you need to fulfill their request.

More information on Dialog directives here



来源:https://stackoverflow.com/questions/52107383/ask-user-for-input-from-launchintent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!