I've been struggling trying to write a working code in order to controll my lights using a Amazon Echo (Alexa) with a JSON-url. I've read many examples and tried lots of different combinations, but I can't get it to work. The launch request does work. The IntentRequest doesn't. I've changed the link.
At the moment it looks like this:
var http = require('http')
exports.handler = (event, context) => {
try {
if (event.session.new) {
console.log("NEW SESSION");
}
switch (event.request.type) {
case "LaunchRequest":
console.log(`LAUNCH REQUEST`);
context.succeed(
generateResponse(
buildSpeechletResponse("Welcome", true),
{}
)
);
break;
case "IntentRequest":
console.log(`INTENT REQUEST`);
switch(event.request.intent.name) {
case "TurnTheLightsOn":
var url = "http://full link";
http.get(url, function(response){
var body = "";
response.on('data', function(chunk) {
body += chunk;
});
response.on('end', function() {
var data = JSON.parse(body); // {"result":"ok"}
console.log("Got a response: ", data);
context.succeed(
generateResponse(
buildSpeechletResponse(`Ok`)
)
);
});
});
}
break;
case "SessionEndedRequest":
console.log(`SESSION ENDED REQUEST`);
break;
default:
context.fail(`INVALID REQUEST TYPE: ${event.request.type}`);
}
} catch(error) { context.fail(`Exception: ${error}`); }
};
buildSpeechletResponse = (outputText, shouldEndSession) => {
return {
outputSpeech: {
type: "PlainText",
text: outputText
},
shouldEndSession: shouldEndSession
};
};
generateResponse = (speechletResponse, sessionAttributes) => {
return {
version: "1.0",
sessionAttributes: sessionAttributes,
response: speechletResponse
};
};
The Intent schema looks like the following: Intent Schema And the service simulator: Service Simulator No matter what I try, I keep getting the error: 'The remote endpoint could not be called, or the response it returned was invalid.'
And I have no idea how to resolve this issue. Anyone who can help me? Many thanks in advance!