質問: Google Actions は、すべてのユーザー入力で Webhook ポストを起動することによって常に機能しますか? 毎回 json を解析し、関心のあるパラメーターが見つかった場合にのみ反応するようにロジックを操作する必要がありますか? または、Google Actions API によって作成された Webhook 投稿を制御して、対象のパラメータの値を含めることによってアクションが完全に満たされている場合にのみ作成する方法はありますか?
#詳細: この nodejs アプリを Heroku にデプロイしました: https://github.com/quique123/myjsonparser/blob/master/app.js
Google Actions API (Number Genie) の例への Webhook として使用しています。Number Genie では、ユーザーは「Number Genie に話しかける」でゲームを開始します。魔神は、私が数字を考えていると答えます...推測します。ユーザーが数字で応答すると (そのときだけ) ロジックが実行され、推測と答えが比較されます。
しかし、私はグーグルホームからの投稿リクエストごとにAPI呼び出しを行っています。つまり、ユーザーが会話 API を操作するたびに Webhook の投稿が行われます。body に user-input-parameter が含まれておらず、Heroku が "talk to number genie" に応答していることがわかります。
2017-04-30T18:59:19.480900+00:00 heroku[router]: at=info method=POST path="/API/switches/sw1?password=123456" host=myjsonparser.herokuapp.com request_id=64d51b1c-3253-4a64-b7f5-a29a7750945b fwd="54.224.155.160" dyno=web.1 connect=1ms service=35ms status=200 bytes=254 protocol=https
2017-04-30T18:59:19.473973+00:00 app[web.1]: headers: {"host":"myjsonparser.herokuapp.com","connection":"close","accept":"*/*","content-type":"application/json; charset=UTF-8","cache-control":"no-cache","pragma":"no-cache","user-agent":"Java/1.8.0_112","x-request-id":"64d51b1c-3253-4a64-b7f5-a29a7750945b","x-forwarded-for":"54.224.155.160","x-forwarded-proto":"https","x-forwarded-port":"443","via":"1.1 vegur","connect-time":"1","x-request-start":"1493578759443","total-route-time":"0","content-length":"575"}
2017-04-30T18:59:19.474002+00:00 app[web.1]: body: {"id":"14797289-b0b8-492a-b030-bf9f05c7ea17","timestamp":"2017-04-30T18:59:19.413Z","lang":"en","result":{"source":"agent","resolvedQuery":"talk to number genie","speech":"","action":"generate_answer","actionIncomplete":false,"parameters":{},"contexts":[],"metadata":{"intentId":"688b0da5-547e-4c7a-8adc-189844834bcc","webhookUsed":"true","webhookForSlotFillingUsed":"false","intentName":"start_game"},"fulfillment":{"speech":"","messages":[{"type":0,"speech":""}]},"score":0.61},"status":{"code":200,"errorType":"success"},"sessionId":"ff2e0c97-552b-40d3-8f06-32e612476897"}
2017-04-30T18:59:19.477116+00:00 app[web.1]: postSwitch {"id":"sw1","state":"off","name":"Koko's Lamp"}
Google Actions API で数値を使用してテストすると、"44" に対する Heroku の応答に check_guess が含まれていることがわかります。
2017-04-30T19:00:31.901297+00:00 app[web.1]: headers: {"host":"myjsonparser.herokuapp.com","connection":"close","accept":"*/*","content-type":"application/json; charset=UTF-8","cache-control":"no-cache","pragma":"no-cache","user-agent":"Java/1.8.0_112","x-request-id":"5a7a2c31-9ce5-4b02-9bac-bcef55ad6818","x-forwarded-for":"54.224.155.160","x-forwarded-proto":"https","x-forwarded-port":"443","via":"1.1 vegur","connect-time":"1","x-request-start":"1493578831899","total-route-time":"0","content-length":"573"}
2017-04-30T19:00:31.901347+00:00 app[web.1]: body: {"id":"5478dfb5-54f3-451d-b975-4f984d1ce3cb","timestamp":"2017-04-30T19:00:31.858Z","lang":"en","result":{"source":"agent","resolvedQuery":"44","speech":"","action":"check_guess","actionIncomplete":false,"parameters":{"check_guess":"44"},"contexts":[],"metadata":{"intentId":"c863e1e2-c850-45d8-9b96-b57e0b1ee77e","webhookUsed":"true","webhookForSlotFillingUsed":"false","intentName":"provide_guess"},"fulfillment":{"speech":"","messages":[{"type":0,"speech":""}]},"score":1},"status":{"code":200,"errorType":"success"},"sessionId":"ff2e0c97-552b-40d3-8f06-32e612476897"}
2017-04-30T19:00:31.903553+00:00 app[web.1]: postSwitch {"id":"sw1","state":"on","name":"Koko's Lamp"}
2017-04-30T19:00:31.907017+00:00 heroku[router]: at=info method=POST path="/API/switches/sw1?password=123456" host=myjsonparser.herokuapp.com request_id=5a7a2c31-9ce5-4b02-9bac-bcef55ad6818 fwd="54.224.155.160" dyno=web.1 connect=1ms service=5ms status=200 bytes=253 protocol=https
問題は、postSwitch{} が両方の場合に発生することです。
これは Google Actions が常に機能する方法ですか?毎回 json を解析し、check_guess が見つかった場合にのみ反応するようにロジックを操作する必要がありますか? または、パラメータ check_guess の値を含めることによってアクションが完全に満たされている場合にのみ作成するために、Google Actions API によって作成された webhook 投稿を制御する方法はありますか?