我正在开发一项 Alexa 技能,在启动时它会询问Do you want to perform something ?
取决于用户的回复'yes'
or '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'
}
};
我确实看过dialog model
看来它会达到目的。但我不确定如何实施。
实现您从技能中寻找的目标的最简单方法是处理AMAZON.YesIntent
and 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
}
};
请注意,在更复杂的技能中,您可能必须存储一些状态才能确定用户发送了“是”意图来响应您是否“做某事”的问题。您可以使用技能会话属性来保存此状态会话对象 https://developer.amazon.com/docs/custom-skills/request-and-response-json-reference.html#session-object。例如:
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 ..
}
};
最后,您还可以考虑使用对话界面 https://developer.amazon.com/docs/custom-skills/dialog-interface-reference.html正如您在问题中提到的,但如果您想做的只是从启动请求中获得一个简单的是/否确认作为提示,那么我认为上面的示例将非常容易实现。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)