如果您无法在蓝图选项下找到Alexa-Skills-kit-factskill,您可以通过以下方式手动创建fact skill
:
以下是使用Node.js实现的简单Lambda函数示例:
const Alexa = require('ask-sdk-core');
const data = [
'The world’s oldest piece of chewing gum is over 9,000 years old!',
'In France, it is legal to marry a dead person.',
'Pteronophobia is the fear of being tickled by feathers!'
];
const GetFactHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'GetNewFactIntent';
},
handle(handlerInput) {
const randomFact = data[Math.floor(Math.random() * data.length)];
const speechOutput = `Here's your random fact: ${randomFact}`;
return handlerInput.responseBuilder
.speak(speechOutput)
.getResponse();
}
};
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(GetFactHandler)
.lambda();
请注意,这仅是一个简单的示例,您可以根据自己的需求进行修改。