question

triglm avatar image
triglm asked

ReportState Event JSON format?

I have a Version 3 Alexa SmartHome skill and supporting Node.js Lambda that appears to respond properly to the Alexa Discovery Event based on the Version 3 documentation. Then, however, it receives a ReportState event. But the JSON is formatted differently than the documentation leads me to expect (and handle in the Lambda code).

Here is the event I'm logging:

2019-04-15T20:26:56.106Z 1ab5cdb6-7bbb-4652-9f2d-b7e6d19cce2a exports.handler event =

{ "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "adeeb64e-55e2-4e42-b1dc-8df0841cf936", "correlationToken": "... deleted..." }

But the documentation ( https://developer.amazon.com/docs/smarthome/state-reporting-for-a-smart-home-skill.html#report-state-when-alexa-requests-it) says it should look like:

{
  "directive": {
    "header": {
      "messageId": "abc-123-def-456",
      "correlationToken": "abcdef-123456",
      "namespace": "Alexa",
      "name": "ReportState",
      "payloadVersion": "3"
    },
    "endpoint": {
      "endpointId": "appliance-001",
      "cookie": {},
      "scope": {
        "type": "BearerToken",
        "token": "access-token-from-skill"
      }
    },
    "payload": {}
  }
}

Where is the directive and endpoint wrapper? Do I have to check to see if the event JSON contains "directive" and "header"?


alexa smart homelambdaapi
10 |5000

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

roy-1 avatar image
roy-1 answered

Hi triglm,


Thanks for posting, and welcome to the forums. The full event Report State Event that your Lambda Function is receiving will include the keys listed in the tech docs. Please check to ensure that you are logging the full event, and not just the header.

2 comments
10 |5000

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

triglm avatar image triglm commented ·

@Roy@amazon thanks for the reply. Here is the very simple code that is logging the event:

----------

exports.handler = function(event, context, callback){

console.log('exports.handler event = ', JSON.stringify(event));

switch (event.directive.header.namespace) {

//...

-------

The same code is logging the discovery, which contains the header. Here is the output from the following Discovery event:

exports.handler event =

{

"directive": {

"header": {

"namespace": "Alexa.Discovery",

"name": "Discover",

"payloadVersion": "3",

"messageId": "874e6be0-xxx-4ee8-8ed6-5017003299e1"

},

"payload": {

"scope": {

"type": "BearerToken",

"token": "...deleted for space"

}

}

}

}


So I don't know why it would log the header for that event, but not the other. Just to be sure, I checked my Lambda code to make sure "exports.handler event=" only occurs in the one log statement.

0 Likes 0 ·
triglm avatar image triglm triglm commented ·

Followup question: Is it possible that I have to do something to mark the message as consumed or something after/before callback() is called?

0 Likes 0 ·
triglm avatar image
triglm answered

Deleting and re-adding the AWS Home Automation and lambda fixed this problem. It is now logging the entire message.

10 |5000

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