question

bansalbhavin avatar image
bansalbhavin asked ·

Can anyone provide a sample code for making discovery request or turn on lights

I have been reading all documents on official amazon forum regarding integrating Alexa using lambda. I have somewhere in those document read that it works with payload version 2. But when I tried to create a sample labmda function using node the demo code created is using payload version 1. I am not familier with python thats why I am trying to create this using node.

Any help is really appreciated.

alexa skills kitalexaalexa smart homenode_js
10 |2000 characters needed characters left characters exceeded

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

nkatz3 avatar image
nkatz3 answered ·

The headers are in the documentation, but for discovery it must look like this

var headers = { 
        namespace: 'Alexa.ConnectedHome.Discovery',
        name: 'DiscoverAppliancesResponse',
        payloadVersion: '2'
    };

You must attach this and the payload described in the documentation (which includes the device list and all the devices) and return it from your lambda handler function. I say this because some people assume context.succeed returns the data, which it does not.

Turning on lights is easier, here is the entire payload:

 var headers = { //ALL HEADERS ARE REQUIRED AS IS. DO NOT CHANGE
        namespace: 'Alexa.ConnectedHome.Control',
        name: 'TurnOnConfirmation',
        payloadVersion: '2'
    };
 var payload={
    };
 var result = {
	header: headers,
        payload: payload
    };

And then you can return the result object.

10 |2000 characters needed characters left characters exceeded

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

bansalbhavin avatar image
bansalbhavin answered ·

What will be the use of onIntent(), onLaunch() in our lambda code?

1 comment
10 |2000 characters needed characters left characters exceeded

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

For smart home skills? I don't think you would need those ones. I'd take a look at the API refrence here: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/smart-home-skill-api-reference

0 Likes 0 ·