下面的GraphQL请求是based on this tutorial和Alexa NodeJS HelloWorld boilerplate。运行调用名称后,Alexa返回“请求的技能的响应存在问题”。 该技能是 custom + Alexa托管。
AWS CloudWatch日志:
START RequestId: 1992effc-ec02-42fc-bd5f-22df89b16598 Version: 13
Unable to import module 'index': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/index.js:6:27)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
END RequestId: 1992effc-ec02-42fc-bd5f-22df89b16598
NodeJS代码:
const Alexa = require('ask-sdk-core');
const { GraphQLClient } = require('graphql-request');
const GRAPHQL_ENDPOINT = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr';
const graphQLClient = new GraphQLClient(GRAPHQL_ENDPOINT, { })
const helloWorldQuery = `
{
Movie(title: "Inception") {
releaseDate
actors {
name
}
}
}
`
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
const speechText = 'Welcome to the Alexa Skills Kit, you can say hello!';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
},
};
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent'
);
},
async handle(handlerInput) {
const response = await graphQLClient.request(helloWorldQuery);
const speechText = `Hello World ${response}`;
return handlerInput.responseBuilder
.speak(speechText)
// .withSimpleCard('GraphQL Query', speechText)
.getResponse();
},
};
如何解决此错误?
答案 0 :(得分:0)
我不确定可能是什么问题,我刚刚进行了测试,您可以找到结果here
仅作为示例,这就是我从查询中得到的信息:
2019-06-16T21:48:05.702Z e45cf19c-daf9-4aa8-90ef-d7e827655d21 INFO查询结果= { “电影”:{ “ releaseDate”:“ 2010-08-28T20:00:00.000Z”, “演员”:[ { “名称”:“莱昂纳多·迪卡普里奥” }, { “名称”:“艾伦·佩奇” }, { “名称”:“汤姆·哈迪” }, { “名称”:“约瑟夫·戈登-莱维特” }, { “名称”:“ Marion Cotillard” } ] } }
示例技巧只是让Alexa说这部电影是莱昂纳多·迪卡普里奥(Leonardo DiCaprio)主演的:
const speechText = The movie Inception is starred by ${response.Movie.actors[0].name}
;
我希望这可以帮助您找到错误。
可以随意复制github存储库并从那里建立。