Alexa skill lambda函数尝试将http请求发送到localhost端口8000
我已经坚持了一段时间,无论我尝试什么,Alexa总是说错误信息:'所请求技能的回复存在问题。
我使用的请求格式是节点js的标准格式,但由于某种原因,它在AWS lambda函数控制台中不起作用。
真的可以使用一些帮助(我在节点或js编码时没有真正的经验,我真的只做了python之前很抱歉,如果我犯了一个愚蠢的错误)
谢谢!
'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = 'amzn1.ask.skill.4201f25c-5da7-4668-89ef-321896522bb8';
const SKILL_NAME = 'make request';
const INTRO = "we are going to try to make an H T M L request ";
const HELP_MESSAGE = 'sorry I just suck at getting data';
const GETTING_DATA = ' sorry I am dumb';
const HELP_REPROMPT = 'i am sad';
const STOP_MESSAGE = 'Goodbye!';
const handlers = {
'LaunchRequest': function () {
this.emit(':ask',INTRO);
},
'send_request': function () {
const http = require("http");
const PORT = 8000;
const requestHandler = (req, res) => {
res.write("trying to send a message")
res.end("Hello from AWS Cloud9!")`enter code here`
}
const server = http.createServer(requestHandler);
server.listen(PORT, (err) => {
if (err) {
console.log("Error occurred", err) ;
}
})
this.emit(':tell', `Server is listening on ${PORT}`);
},
'AMAZON.HelpIntent': function () {
const speechOutput = HELP_MESSAGE;
const reprompt = HELP_REPROMPT;
this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak(STOP_MESSAGE);
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();
};