How to properly get user response from Google Actions json response

梦想与她 提交于 2019-12-13 07:20:47

问题


I've been working with Google Actions API.ai and I have an app based on number genie. The user triggers an intent and responds with the number and I have to use that number in my nodejs app running at the webhook.

So should I parse the json where I can see result.action.check_guess:65.

Or follow the sample code which uses:

let guess = parseInt(assistant.getArgument('check_guess')); 

What is recommended and what are the pros and cons?


回答1:


For starters - both are perfectly valid and well documented (documentation for AssistantApp and for the JSON). The actions-on-google module is great if you're using node.js, but using the JSON directly is also perfectly workable if you're familiar with working with JSON.

In particular, it is best to use the actions-on-google package if:

  • You're using node.js
  • You may be switching away from API.AI at some point (since the actions-on-google package for API.AI and native work very similarly).
  • You don't want to get into some of the implementation details (the package abstracts many of the parameters and contexts into the simpler "data" field).

However, using JSON and the API directly is best (or essential) if:

  • You aren't using node.js
  • You are making more complex use of API.AI's contexts or other features
  • You may want to support your bot for more than the Google Assistant (ie - for some of the other bot platform integrations that API.AI supports).


来源:https://stackoverflow.com/questions/43763253/how-to-properly-get-user-response-from-google-actions-json-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!