0

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!

PaulG
  • 13,871
  • 9
  • 56
  • 78
  • This may be a similar issue which I answered here: [Need help fixing Alexa Skill](http://stackoverflow.com/questions/42861910/need-help-fixing-alexa-skill/42862647#42862647) – StueyKent Mar 17 '17 at 16:35
  • Here is a link to a working skill which is giving the same issue as above but is working with alexa: https://github.com/Stuey192/getting-started-with-alexa/blob/master/app.js – StueyKent Mar 17 '17 at 16:38

0 Answers0