在 Lambda 函数中的代码中,确保在处理每种意图时,只有相应的语句会触发该意图。可以使用以下示例代码为例:
const handlers = {
'HelloWorldIntent': function () {
this.emit(':tell', 'Hello World!'); // only triggered by the "Hello" utterance
},
'LaunchRequest': function () {
this.emit(':tell', 'Welcome to my Alexa skill.'); // triggered by the skill's invocation name
},
'AMAZON.StopIntent': function () {
this.emit(':tell', 'Goodbye!'); // only triggered by the "stop" utterance
}
};
在上面的代码中,'HelloWorldIntent' 只能通过 "Hello" 语句触发,'LaunchRequest' 只能通过技能的唤醒名触发,'AMAZON.StopIntent' 只能通过 "stop" 语句触发。这确保了每种意图只能由特定的语句触发,避免了意图被无意中调用的风险。