我想创建一个基于测验的Alexa技能。当我尝试在开发人员控制台中测试该技能时,出现以下“该技能的答案有问题”。我不知道这是AWS Lambda端点的编码问题还是构造问题。如果有人可以帮助我,我将不胜感激。
exports.handler = (event, context) => {
const alexa = Alexa.handler(event, context)
alexa.appId = APP_ID
alexa.registerHandlers(handlers, startHandlers, quizHandlers)
alexa.execute()
}
const handlers = {
'LaunchRequest': function() {
this.handler.state = states.START
this.emitWithState('Start')
},
'QuizIntent': function() {
this.handler.state = states.QUIZ
this.emitWithState('Quiz')
},
'AMAZON.HelpIntent': function() {
this.response.speak(HELP_MESSAGE).listen(HELP_MESSAGE)
this.emit(':responseReady')
},
'Unhandled': function() {
this.handler.state = states.START
this.emitWithState('Start')
}
},
'Start': function() {
this.response.speak(“Herzlich Willkommen zu Teach Me! Bist du bereit für das Quiz? ”).listen(“Bist du bereit für das Quiz? ”)
this.emit(':responseReady')
}
'AMAZON.YesIntent': function() {
this.handler.state = states.QUIZ
this.emitWithState('Quiz')
}
'Quiz': function() {
var data = < QUESTION LIST >
this.attributes['data'] = data
this.attributes['response'] = ''
this.attributes['counter'] = 0
this.attributes['quizscore'] = 0
this.emitWithState('AskQuestion')
}
let question = data[this.attributes['counter']]
function compareSlots(slots, item) {
var value = item.Answer
var requestSlotvalue = slots.Answer.value
var similarity = stringSimilarity.compareTwoStrings(requestSlotvalue.toString().toLowerCase(), value.toString().toLowerCase())
if (similarity1 >= 0.6) {
return true
} else {
return false
}
}
看来您正在使用Alexa SDK v1。 V2已经停产了一段时间,您应该使用较新的API来启动一个新项目。
此外,Alexa团队还有一个很好的测验教程/存储库,可用于Skill Builders进行构建。我建议您检查一下:https://github.com/alexa/skill-sample-nodejs-quiz-game