google-home / smart-home-nodejs

A sample of the Smart Home device control APIs in Actions on Google
Apache License 2.0
892 stars 291 forks source link

Missing payload in QUERY response #556

Closed predond closed 2 years ago

predond commented 2 years ago

Hello, tell me guys, what is wrong with my QUERY response. Because I looked at it and found nothing but Google Console tells that I am missing payload field. Error message from Google Cloud: { "insertId": "166g06lg15lgekt", "jsonPayload": { "executionLog": { "executionResults": [ { "actionResults": [ { "action": { "actionType": "STATE_QUERY" }, "device": { "deviceType": "OUTLET" }, "status": { "externalDebugString": "JSON payload not an object.", "isSuccess": false, "statusType": "PARTNER_RESPONSE_INVALID_PAYLOAD" } } ], "executionType": "PARTNER_CLOUD", "latencyMsec": "191", "requestId": "4734217757620110233" } ] }, "locale": "en-US" }, "logName": "projects/smartlightproject-f47f4/logs/assistant_smarthome%2Fassistant_smarthome_logs", "receiveTimestamp": "2022-07-13T13:23:04.088211105Z", "resource": { "labels": { "project_id": "smartlightproject-f47f4" }, "type": "assistant_action_project" }, "severity": "ERROR", "timestamp": "2022-07-13T13:23:04.088211105Z" }

And my QUERY response: { "requestId": "4734217757620110233", "payload": { "devices": { "123": { "on": "true", "online": "true" } } } }

slaesh commented 2 years ago

Your response seems fine.. How do you handle/answer that request? Maybe you can share a code snippet..

predond commented 2 years ago

Here's my code responsible for handling and answering QUERY requests:

var queryObj = JsonConvert.DeserializeObject<dynamic>("{\"requestId\":\"" + requestId + "\",\"payload\":{\"devices\":{\"123\":{\"on\":true,\"online\":true}}}}");
_logger.LogInformation("Odpowiedź na żądanie QUERY." + originalRequest + "\n\n" + JsonConvert.SerializeObject((object)queryObj));
return Ok((object)queryObj);
slaesh commented 2 years ago

I guess this is C#? I don't know what this Ok function does..

I would try either do Ok(--object-stringified-here-instead-of-the-actual-object--) or maybe there is something like JSON(actual-object).

I guess it has something to do with how the http call is answered and what content-type is used?! :)

predond commented 2 years ago

The Ok function is an ASP.NET base element that returns the data passed to it as argument as JSON. So that object passed to Ok function is converted to application/JSON content type of response and parsed into JSON. I done SYNC request in the same way and Actions on Google accepted it, so I wouldn't suspect it as the cause of issue. But I don't see any other causes that may evoke that problem. That's the reason why I started that issue :). I don't see any ways to solve it at all. Maybe you can write some example with QUERY handling and send it to me? It doesn't have to be in C#, because I can read other languages as well (from languages known for more than a little people of course :)).

predond commented 2 years ago

@slaesh, my friend, you are a genious! I managed to try your solution anyway and it worked! I totally don't know why this happened but when I passed string JSON to Ok method I got intended action and no error. I really really appreciate your suggestion, it saved me life :). Now with a cool heart I can close issue. Know that I am really really thankful to you.