【发布时间】:2019-05-25 20:11:50
【问题描述】:
我正在尝试使用 Node.js 开发我的第一个 Alexa 技能,每次我尝试对其进行测试时,我都会收到“请求的技能响应有问题”。
我正在尝试创建一个随机餐厅生成器。很简单,它是一系列餐厅,选择了一个随机索引,Alexa 说的是餐厅。我不知道我哪里出错了我已经上传了我的 .json 和 .js 文件,如果有人可以帮助我真的很感激。
index.js:
const Alexa = require('alexa-sdk');
const APP_ID = 'amzn1.ask.skill.9350e65b-fb41-48ce-9930-98b5156eb63c';
const handlers = {
'LaunchRequest': function () {
this.emit('randomRestaurantGeneratorIntent');
},
'randomRestaurantGeneratorIntent': function () {
var randomResturant;
var foodArray = ['IHOP', 'Dennys', 'burger king'];
randomResturant = foodArray[Math.floor(Math.random() * foodArray.length)];
this.response.speak(randomResturant);
this.emit(':responseReady');
},
'AMAZON.HelpIntent': function () {
const say = 'You can say what did I learn, or, you can say exit... How can I help you?';
this.response.speak(say).listen(say);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.response.speak('Bye!');
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak('Bye!');
this.emit(':responseReady');
}
};
exports.handler = function (event, context, callback) {
const alexa = Alexa.handler(event, context, callback);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
randomResturantGeneratorIntent.JSON:
{
"interactionModel": {
"languageModel": {
"invocationName": "random restaurant generator",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
},
{
"name": "randomRestaurantGeneratorIntent",
"slots": [],
"samples": [
"Launch Random Restaurant Generator "
]
}
],
"types": []
}
}
}
谢谢
【问题讨论】:
-
嘿马里奥,拿了你的代码 JSON 和 Index.js 并且它可以工作,所以我的建议是退后一步,确保在你压缩和上传到 AWS lambda 的文件夹中它包含包含您的 alexa-sdk 库的 node_modules 文件夹。我还建议将 lambda 中的运行时设置为节点 6.10
-
我没有上传它 AWS 我正在在内联编辑器中编写代码。有关当前项目结构,请参阅imgur.com/a/KT7T0M3 屏幕截图。谢谢
-
Mario,查看您的屏幕截图,您显然在该路径中没有一个名为 node_modules 的文件夹,该文件夹将包含 alexa-sdk 节点库,这是您的 index.js 文件的第一个要求 const Alexa = require( 'alexa-sdk');您的代码将无法按您希望的方式运行,除非它具有此功能。
-
嗯,有道理。这是我可以手动添加这些文件的任何方式吗?我在 IDE 中工作。或者你能给我指个教程吗?谢谢
标签: node.js amazon-web-services alexa alexa-skill alexa-app