当我打算使用AMAZON ALEXA时,我的lambda函数没有收到来自api的回复...
并获得响应-抱歉,发生了错误。请再说一次。
答案 0 :(得分:0)
函数httpsGet(myData,回调) {
var options = {
host: 'cp6gckjt97.execute-api.us-east-1.amazonaws.com',
port: 80,
path: '/prod/stateresource?usstate=' + encodeURIComponent(myData),
method: 'GET',
};
var req = https.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log(JSON.stringify(returnData))
var pop = JSON.parse(returnData).population;
callback(pop); // this will execute whatever function the caller defined, with one argument
});
});
req.end();
}
答案 1 :(得分:0)
const GetProductList_Handler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'GetProductList' ;
},
async handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const responseBuilder = handlerInput.responseBuilder;
let sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
var myRequest = 'Florida';
httpsGet(myRequest, (myResult) => {
say = "there2"+JSON.stringify(myResult);
});
return responseBuilder
.speak(say)
.reprompt('try again, ' + say)
.getResponse();
},
}