actions-on-google / actions-on-google-nodejs

Node.js client library for Actions on Google
https://actions-on-google.github.io/actions-on-google-nodejs
Apache License 2.0
900 stars 194 forks source link

smarthome Action: onSync response is invalid (according to GCP logs explorer) #417

Open rlbartle opened 3 years ago

rlbartle commented 3 years ago

The issue is that whatever the contents of a response may be, it is being rejected which also means the account linking fails.

The log shows the following message every time this happens:

{
  "insertId": "1uvc6nbg5w34z7a",
  "jsonPayload": {
    "syncLog": {
      "syncs": [
        {
          "requestId": "16538090895749715207",
          "status": "json_response_invalid_format",
          "httpLatencyMsec": "2082"
        }
      ]
    }
  },
  "resource": {
    "type": "assistant_action_project",
    "labels": {
      "project_id": "XXX"
    }
  },
  "timestamp": "2021-02-21T02:32:17.000194145Z",
  "severity": "ERROR",
  "logName": "projects/XXX/logs/assistant_smarthome%2Fassistant_smarthome_logs",
  "receiveTimestamp": "2021-02-21T02:32:17.000194145Z"
}

With the debug option of the smarthome object set to true, this is some example output tagged in the log as "Response":

{
    "status": 200,
    "headers": {
        "content-type": "application/json;charset=utf-8"
    },
    "body": {
        "requestId": "3168304628571660115",
        "payload": {
            "agentUserId": "c28834eee672",
            "devices": []
        }
    }
}

This is hosted on AWS Lambda API gateway - using the Node.js 14.x runtime and additional modules for the latest v3 AWS SDK.

rlbartle commented 3 years ago

Was able to get it working by configuring the API Gateway resource. Integration Response => Mapping Templates: Integration-Response = $input.path('$.body')

There needs to be documentation of some kind to let us know what the expected configuration the api gateway should be.