如何从Google Actions JSON响应中正确获取用户响应 [英] How to properly get user response from Google Actions json response

查看:71
本文介绍了如何从Google Actions JSON响应中正确获取用户响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Google Actions API.ai ,并且我有一个基于数字精灵的应用程序。用户触发一个意图并用数字响应,我必须在运行于Webhook的nodejs应用中使用该数字。

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.

所以我应该解析 json 可以在其中看到 result.action.check_guess:65

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?

推荐答案

对于初学者-两者都是完全有效的并有据可查的文档( AssistantApp JSON )。如果您使用的是node.js,则Google动作模块非常有用,但是如果您熟悉使用JSON,则直接使用JSON也是完全可行的。

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.

尤其是在以下情况下,最好使用Google动作包:

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


  • 您正在使用node.js

  • 您可能会在某个时候退出API.AI(因为API.AI和Google本机的Google动作包非常相似)。

  • 您不想了解某些实现细节(该程序包将许多参数和上下文抽象到更简单的 data字段中)。

但是,如果满足以下条件,则最好(或必不可少)直接使用JSON和API:

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


  • 您没有使用node.js

  • 您正在更复杂地使用API​​.AI的上下文或其他功能

  • 您可能希望为机器人提供更多支持, Google Assistant(即-用于API.AI支持的其他一些机器人平台集成rts)。

这篇关于如何从Google Actions JSON响应中正确获取用户响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆