问题
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