在 Google 操作中使用带有 API.AI 的事件启动 Intent

Launching an Intent with an Event with API.AI in a Google Action

我正在开发一个 Google Assistant Action,我想创建一个可以自动启动我已有的 Intent 的事件。问题是我似乎找不到任何关于如何实际定义事件的好文档,所以通过这种方式它可以启动一个意图,而不必在两者之间与用户沟通。

举个例子.. 我附上了我尝试使用的意图的图像。我想让用户用一句话提示 get_location 意图。由此,我的代码检查我们是否已经拥有权限,如果没有,我希望通过事件启动意图 request-permission。我如何设置事件以完成此操作?

这是我正在寻找的 conversation/work 流程: - 用户说:'Book a tee time near me' - 这启动了我的 get_location 意图 - get_location 意图检查是否通过 isPermissionGranted() 授予了权限 - 它意识到没有授予许可 - 启动请求许可意图 - 提示用户权限

我的意图是这样设置的:

听起来在您当前的实现中,您的流程是这样的:

  1. User says "Book a tee time nearby".
  2. get_location intent is matched.
  3. In the webhook for get_location, you check if the user has previously granted permission with isPermissionGranted().
    • If they have previously granted, you move forward with looking up their local course.
  4. If they have not previously granted, you call ask from the webhook to ask the user's permission to ask them for permission to get their location.
  5. If they say "yes", the request-permission intent is matched.
  6. In the webhook for request-permission, you call askForPermission() and the Assistant asks the user for permission to get their location.
  7. You now move forward with looking up their local course.

在这种情况下,对话框将如下所示:

User: Book a tee time nearby
App:  Can I ask permission to get your location?
User: Yes
App:  [from Assistant] Can I access your location?
User: Yes
App:  Thanks, your local course is Pebble Beach and I booked you a tee time.

您正试图避免从第 4 步开始的过程,在该步骤中您征求用户的许可以征求他们的许可以获取他们的位置

为此,您可以执行以下流程:

  1. User says "Book a tee time nearby".
  2. get_location intent is matched.
  3. In the webhook for get_location, you check if the user has previously granted permission with isPermissionGranted().
    • If they have previously granted, you move forward with looking up their local course.
  4. If they have not previously granted, you should call askForPermission(), still in the webhook for get_location. The Assistant will ask the user for permission to get their location.
  5. To handle the response from the permission request, you need to create a new intent and add to it an event named actions_intent_PERMISSION (see the docs for reference). This event will cause the intent to be triggered when the user has granted location permission.
  6. Build a webhook for this new intent that, in its webhook, confirms the permission with isPermissionGranted() and then moves forward with looking up their local course.

现在,对话框如下:

User: Book a tee time nearby
App:  [from Assistant] Can I access your location?
User: Yes
App:  Thanks, your local course is Pebble Beach and I booked you a tee time.