Aks*_*ayM 5 amazon-web-services alexa aws-lambda alexa-skill alexa-skills-kit
我正在开发一种Alexa技能,在启动它会询问,具体Do you want to perform something ?
取决于用户的回复'yes'或'no'我想发布另一个意图.
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'
}
};
Run Code Online (Sandbox Code Playgroud)
我确实看过,dialog model似乎它将达到目的.但我不知道如何实现它.
做你从技能找什么最简单的方法,是处理AMAZON.YesIntent和AMAZON.NoIntent从你的技能(请务必将其添加到交互模型以及):
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
}
};
Run Code Online (Sandbox Code Playgroud)
请注意,在更复杂的技能中,您可能需要存储一些状态,以确定用户发送了"是"意图以回答您是否"做某事"的问题.您可以使用会话对象中的技能会话属性来保存此状态.例如:
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 ..
}
};
Run Code Online (Sandbox Code Playgroud)
最后,您还可以在问题中提到使用Dialog接口,但是如果你要做的就是从启动请求中得到一个简单的Yes/No确认作为提示而不是我认为上面的示例将是非常直接地实施.
| 归档时间: |
|
| 查看次数: |
3232 次 |
| 最近记录: |