AWS Lambda Proxy Custom Alexa Skill when you don't have https

Could this be something going on in the Dev branch? Could anyone confirm if they have this proxy media working on the latest Dev build of HaSS?

Cheers!

This is definity working at the minute I set it up last night. If you at getting invalid responses chech your HA config and make sure port is open.

Well just for eliminating a few things… I’m on a raspberry pi 3, using AIO install method, and updated HAss to 0.31 just before trying this. Usually when something like this doesn’t work for me it is because I have missed a character, or space or something else very obvious that my eyes refuse to see. Things that are very much my fault.

I’m waiting on some dots to show up and will probably use Ha-Bridge when they do but wanted to try this out more as an exercise as I try to learn some basic programming and understand how all this stuff ties together better.

Oh, and the only line I edited in the code was “amzn1.ask.skill.xxxx-xxxx-xxxx-xxxx-xxxxxx’:’ http://xxxxxxxx:8123/api/alexa?api_password=password” - I can see there are bits below that with port 80 mentioned - I’m using the default 8123, port 80 is blocked by my ISP.

don’t need to worry about the port 80 part… of you edited the xxxxx link I’d check your Amazon Skill and HA config.

I might delete everything and start again tomorrow, I am sure it’s some small thing I’ve missed.

don’t use everything start just with the wherearewe and part and copy and paste don’t change anything then test from the amazon skill.

Thanks for the help @josephdouce

I only have a scene intent set up copied from my HTTPS version - nothing else.

When I try a fresh start tomorrow I’ll try with the wherearewe and see if it gets through.

Hey tarnfeather!

Thanks for posting this! This has been very useful thus far.

My only problem is that I can’t use a public IP address. I have a router and admin access but this is running under my college’s network via ethernet to my router. Is there anything I can do to get around this? I originally looked into PageKite, a VPN of some sort, or something to do with Hamachi, but I’m not quite sure.

All help is greatly appreciated!!!

I have pagekite as well. I am not able to figure out how to get it working. Even testing the HTTPS call I get “405:Method not allowed” when I try to access https://HOMEASSISTANT.pagekite.me:8000/api/alexa?api_password=PASSWORD

I get {“message”: “API running.”} when accessing https://HOMEASSISTANT.pagekite.me:8000/api/?api_password=PASSWORD

So I think there is something wrong with the alexa plugin.

Any idea of why that is? HA Version 34.4 I tested it with


Free valid certificate for https, in case someone has missed it.

Hi guys, anyone have solution about this issue? “The remote endpoint could not be called, or the response it returned was invalid.”

1 Like

Ok, I got it working.

I added “use strict” in the first line and fixed the spacing issue here:

The part in bold in the original code has a space between the quote and the http part of the URL, which also need to be closed quotes (close the quotes after the api_password=YOURPWD )

Hope that helps. I resorted to this proxy as I couldn’t set up the encryption for whatever reason.

D.

Is this still working? I’ve developed a fair few Alexa skills and should have the knowledge but I just can’t get it working.

Response invalid from the Alexa Skills kit test tool and trying to test with a sample intent through the Lambda console doesn’t work either - I get the error ‘no url found for application id’ ?

Also you can only choose NodeJS 4.3 now ? Not sure if this breaks your code?

I was considering writing an updated Lambda function using the official Amazon NodeJS SDK to do it but I don’t have experience of the HA Alexa API. Is this documented anywhere? I’d like to test it using Postman.

Or if anyone could help me to get this working that would be good.

Hi @tarnfeather

I tried using your method as described but on AWS Lambda for the runtime there is no option for NodeJS, the only options are: node.js 4.3, C#, Java 8, Edge Node.js 4.3, Python 2.7.

Can you please tell me which one to select as I tried it with node.js 4.3 and it did not work.

Hi @weissblut

I am going through the same problem. Could you please share your code as I get an error:
{
“errorMessage”: "Exception: TypeError: Cannot read property ‘application’ of undefined”
}

I am not sure if it is the spacing issue.

Can you please help?

My setup:

  • VMWare ESXI Server
  • Home Assistant VMWare not accessible from web (only via VPN)

Is it mandatory to expose the Hass instance to the web in order to use Alexa? I have Hass only accessible via VPN from outside and I would like to keep it this way. (I’m just wondering because in the script in the first post the local IP adress is also listed)

Regarding my VPN setup: Could I run a NodeJS Server in another VMWare communicating with Hass locally?

I too am wondering about this part.

I followed the walk-through and think I have the “where are we” part working but cannot get “where is corey” to work. I have put-off the whole Alexa intent part of my setup as I keep seeing people have difficulty but I would really like to get it setup, integrated, and expand everything.

When I test on Lambda I get:

{
  "errorMessage": "Exception: TypeError: Cannot read property 'application' of undefined"
}

Here is the script:

var http = require('http');
var URLParser = require('url');

exports.handler = function (json, context) {
    try {
        // A list of URL's to call for each applicationId
        var handlers = {
            'appId':'url',
            'amzn1.ask.skill.9c72c728-a69c-44e0-9e4b-2d4d4dc4aade':'http://Redacted:Redacted/api/alexa?api_password=Redacted'
        };

        // Look up the url to call based on the appId
        var url = handlers[json.session.application.applicationId];
        if (!url) { context.fail("No url found for application id"); }
        var parts = URLParser.parse(url);

        var post_data = JSON.stringify(json);

        // An object of options to indicate where to post to
        var post_options = {
            host: parts.hostname,
            auth: parts.auth,
            port: (parts.port || 80),
            path: parts.path,
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Content-Length': post_data.length
            }
        };
        // Initiate the request to the HTTP endpoint
        var req = http.request(post_options,function(res) {
            var body = "";
            // Data may be chunked
            res.on('data', function(chunk) {
                body += chunk;
            });
            res.on('end', function() {
                // When data is done, finish the request
                context.succeed(JSON.parse(body));
            });
        });
        req.on('error', function(e) {
            context.fail('problem with request: ' + e.message);
        });
        // Send the JSON data
        req.write(post_data);
        req.end();        
    } catch (e) {
        context.fail("Exception: " + e);
    }
};

No idea mate.

I am getting the same error: “errorMessage”: "Exception: TypeError: Cannot read property ‘application’ of undefined”

Any help would be appreciated.

Hi guys,

apologies for the delay, I was traveling. Here’s my code, hope it helps.

"use strict"

var http = require('http');
var URLParser = require('url');

exports.handler = function (json, context) {
    try {
        // A list of URL's to call for each applicationId
        var handlers = {
            'appId':'url',
            'YOUR_SKILL_ID':'http://YOUR_HA_ADDRESS:8123/api/alexa?api_password=YOUR_PWD'
        };

        // Look up the url to call based on the appId
        var url = handlers[json.session.application.applicationId];
        if (!url) { context.fail("No url found for application id"); }
        var parts = URLParser.parse(url);

        var post_data = JSON.stringify(json);

        // An object of options to indicate where to post to
        var post_options = {
            host: parts.hostname,
            auth: parts.auth,
            port: (parts.port || 80),
            path: parts.path,
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Content-Length': post_data.length
            }
        };
        // Initiate the request to the HTTP endpoint
        var req = http.request(post_options,function(res) {
            var body = "";
            // Data may be chunked
            res.on('data', function(chunk) {
                body += chunk;
            });
            res.on('end', function() {
                // When data is done, finish the request
                context.succeed(JSON.parse(body));
            });
        });
        req.on('error', function(e) {
            context.fail('problem with request: ' + e.message);
        });
        // Send the JSON data
        req.write(post_data);
        req.end();        
    } catch (e) {
        context.fail("Exception: " + e);
    }
};
1 Like

Hi thanks for the code.

Can I ask you what runtime are you using?