我正在开发一项Alexa技能,该技能在启动时会询问您要执行某些操作吗? 根据用户的答复,'是'或'no',我要启动另一个意图.
I am developing a Alexa skill in which on launch it will ask Do you want to perform something ? Depending upon user's reply 'yes' or 'no' I want to launch another intent.
var handlers = { 'LaunchRequest': function () { let prompt = this.t("ASK_FOR_SOMETHING"); let reprompt = this.t("LAUNCH_REPROMPT"); this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt); this.emit(':responseReady'); }, "SomethingIntent": function () { //Launch this intent if the user's response is 'yes' } };我确实看过了 dialog模型,看来它将达到目的.但是我不确定如何实现.
I did have a look at dialog model and it seems that it will serve the purpose. But I am not sure how to implement it.
推荐答案执行此技能所需的最简单方法是处理 AMAZON.YesIntent 和熟练掌握AMAZON.NoIntent (请确保也将其添加到交互模型中):
The simplest way to do what you're looking for from the skill, is to handle the AMAZON.YesIntent and AMAZON.NoIntent from your skill (make sure to add them to the interaction model as well):
var handlers = { 'LaunchRequest': function () { let prompt = this.t("ASK_FOR_SOMETHING"); let reprompt = this.t("LAUNCH_REPROMPT"); this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt); this.emit(':responseReady'); }, "AMAZON.YesIntent": function () { // raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below this.emit('SomethingIntent'); }, "AMAZON.NoIntent": function () { // handle the case when user says No this.emit(':responseReady'); } "SomethingIntent": function () { // handle the "Something" intent here } };请注意,在更复杂的技能中,您可能必须存储一些状态才能弄清楚用户是否针对您关于是否做某事"的问题发送了是"意图.您可以使用会话对象.例如:
Note, that in a more complex skill you might have to store some state to figure out that the user sent a 'Yes' intent in response to your question as to whether to "do something". You can save this state using the skill session attributes in the session object. For instance:
var handlers = { 'LaunchRequest': function () { let prompt = this.t("ASK_FOR_SOMETHING"); let reprompt = this.t("LAUNCH_REPROMPT"); this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt); this.attributes.PromptForSomething = true; this.emit(':responseReady'); }, "AMAZON.YesIntent": function () { if (this.attributes.PromptForSomething === true) { // raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below this.emit('SomethingIntent'); } else { // user replied Yes in another context.. handle it some other way // .. TODO .. this.emit(':responseReady'); } }, "AMAZON.NoIntent": function () { // handle the case when user says No this.emit(':responseReady'); } "SomethingIntent": function () { // handle the "Something" intent here // .. TODO .. } };最后,您还可以使用对话框界面就像您在问题中提到的那样,但是如果您要做的只是从启动请求中获得一个简单的是/否"确认作为提示,那么我认为上面的示例很容易实现.
Finally, you could also look into using the Dialog Interface as you alluded to in your question but if all you're trying to do is get a simple Yes/No confirmation as a prompt from the launch request than I think my example above would be pretty straight forward to implement.
更多推荐
如何获得和使用Alexa技能意图响应的确认``是''或``否''
发布评论