我的技能:做一个果汁建议,当用户说一个状态时,Alexa会根据这个状态给出一个果汁建议。状态和果汁对被存储在一个数组中。
挑战:目前,我的技能只执行一次。有什么方法可以让我有一个循环,在Alexa提出建议之后,Alexa会再次问这个问题,然后等待用户的响应吗?附随的是我用我的技巧所拥有的密码。谢谢。
var Alexa = require('alexa-sdk');
const APP_ID = undefined;
const skillData = [
{
state: "FLORIDA",
suggestion: "My suggestion for Florida is organic orange juice by Naked"
},
{
state: "CALIFORNIA",
suggestion: "My suggestion for California is pomegrante by POM!!"
},
{
state: "NEW JERSEY",
suggestion: "My suggestion for Jersey is blueberry by Jersey Fresh"
}
];
var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {
this.emit(':ask', 'I can suggest a juice from any state in the United States. What state would you like a juice suggestion for?', 'Tell me a state name and I will suggest a local juice from there.');
},
'MakeSuggestion': function() {
var stateSlot = this.event.request.intent.slots.state.value;
this.emit(':tell', getSuggestion(skillData, 'state', stateSlot.toUpperCase()).suggestion);
},
'Unhandled': function () {
this.emit(':tell', 'Sorry, I don\'t know what to do');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
}
number = number+1;
};
exports.handler = function(event, context){
var alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
function getSuggestion(arr, propName, stateName) {
for (var i=0; i < arr.length; i++) {
if (arr[i][propName] == stateName) {
return arr[i];
}
}
}
发布于 2018-05-04 14:39:27
在您的MakeSuggestion函数中,使用ask而不是tell,并再次附加问题:
this.emit(':ask', getSuggestion(skillData, 'state', stateSlot.toUpperCase()).suggestion + '. Tell me another state and I give you another suggestion!');发布于 2018-05-04 00:54:29
是的,您可以通过使用state来完成这一任务,而不是使用":tell",您可以通过":ask“来响应,这样alexa麦克风就可以保持开放状态以进行用户交互。
https://stackoverflow.com/questions/50159227
复制相似问题