question

fat ninja avatar image
fat ninja asked

Lambda response "the response is invalid" why is this not POSTing?

I found this code on the GitHub, and I can not get it to post the url. However, I have it placed in lambda and working somewhat. If I go to the alexa simulator and text anything that is not something the script is looking for, it responds correctly with the default message of the script which is "I did not hear an option". However if I enter a test text in the simulator that is in the case statement of the index file, I get a response from lambda as "invalid". If I test directly on the lambda side of things I get a "timed out after 3 seconds". I found the code here: https://github.com/MrEggsalad/Echo-Roku-Voice-Control the file that I am placing in lambda are the AlexaSkill and the index.js file. I suspect something needs to be changed in the index file, but for the life of me I can't see it. Can you? this is a paste of the index var http = require('http'); // Your external IP. Alexa can only access publically-accessible IPs. No LAN access unfortunately. // Make sure to set up port fortwarding on port 8080 to your Roku's IP on your router. var local_ip = 'xxx.xxx.xxx.xxx'; /** * App ID for the skill */ var APP_ID = ""; //replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]"; /** * The AlexaSkill prototype and helper functions */ var AlexaSkill = require('./AlexaSkill'); var RokuControl = function () { AlexaSkill.call(this, APP_ID); }; // Extend AlexaSkill RokuControl.prototype = Object.create(AlexaSkill.prototype); RokuControl.prototype.constructor = RokuControl; RokuControl.prototype.intentHandlers = { RokuIntent: function (intent, session, response) { //No matter what she wants to tell you her opinion. function satisfyAlexa() { response.tell(""); }; // Obtain User Intent switch(intent.slots.Control.value) { // Same button is used case "to play": case "Play": case "resume": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=play&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "to pause": case "pause": case "freeze": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=pause&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go to guide": case "open guide": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=guide&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "power": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=power&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "to turn on": case "power up": case "power on": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=poweron&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "turn the power off": case "turn off": case "power off": case "power down": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=poweroff&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "format": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=format&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "to rewind": case "rewind": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=rew&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "to replay": case "replay": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=replay&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "to stop": case "stop": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=stop&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "advance": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=advance&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "to fast forward": case "fast forward": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=ffwd&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "to record": case "record": case "save": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=record&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "active": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=active&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go to list": case "list": case "find recorded shows": case "DVR": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=list&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "exit": case "end": case "leave": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=exit&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go back": case "back": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=back&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go to menu": case "menu": case "main menu": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=menu&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go to info": case "info": case "find info": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=info&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go up": case "move up": case "up": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=up&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go down": case "move down": case "down": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=down&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go left": case "move left": case "left": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=left&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "go right": case "move right": case "right": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=right&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "select": case "enter": case "to enter": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=select&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "red button": case "delete all": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=red&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "green button": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=green&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "yellow button": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=yellow&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "blue button": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=blue&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "channel up": case "page up": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=chanup&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "channel down": case "page down": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=chandown&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "previous channel": case "last channel": case "go back to the last channel": case "change it back to what i was watching": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=prev&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; case "dash": var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=dash&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); break; default: response.tell("I didn't hear an option."); break; } } } exports.handler = function (event, context) { var rokuControl = new RokuControl(); rokuControl.execute(event, context); };
alexa skills kitsubmission testing certification
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

fat ninja avatar image
fat ninja answered
I think I have this nailed down to one main issue that maybe someone can help me out with. var options = { host: local_ip, port: 8080, path: '/remote/processKey?key=play&hold=keyPress', method: 'POST' }; var req = http.request(options, satisfyAlexa); req.end(); This bit does not seem to be sending a POST from lambda. Does anyone see anything flat out missing or wrong with it? I have the local_ip assigned as var local_ip = 'xxx.xxx.xxx.xxx'; (xxx equals my Internet IP) any guesses? If I add a response.tell("OK"); after the req.end(); alexa will respond with OK. So it looks like the POST is not getting hung up.... though it may be wrong. Any ideas or info needed let me know! Thanks
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nick Gardner avatar image
Nick Gardner answered
Hi, Have you looked at this HistoryBuff sample here: https://github.com/amzn/alexa-skills-kit-js? It is doing a get instead of a post, but the general code should be the same and you can start from a known point. -Nick
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Greg Crawford avatar image
Greg Crawford answered
The call to http.request is asyncronous so you need to make sure that your Lambda code isn't exiting before the http.request can be initiated and finished.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.