为什么名称许可不起作用?

时间:2018-09-30 19:10:08

标签: node.js firebase actions-on-google

我正在尝试允许Google Assistant中的权限,但是模拟器只是在要求输入名称时要求“重复答案”。这是权限代码。

app.intent('Default Welcome Intent', (conv) => {
conv.ask(new Permission({
context: 'Hi there, to get to know you better',
permissions: 'NAME'
 }));
});

通过Firebase部署代码时,不会引发任何错误。

谢谢。

1 个答案:

答案 0 :(得分:2)

在您的代理商中,Default Welcome Intent是请求NAME许可的意图。 您将必须实现另一个意图来处理此权限。让我们称之为user_info意图。

因此,当“ Google上的Actions”提出问题,并且用户回答“是”或“否”(同意或拒绝)时;然后,Google上的“操作”会向DialogFlow发送一个名为“ actions_intent_PERMISSION”的事件。我们将使用该事件来触发此特定意图。触发意图后,我们将确保将“ user_info”操作发送到我们的应用程序。

enter image description here

在应用程序中,我们将注册“ user_info”操作,并确保检查用户是否已授予或拒绝了权限。为此,我们调用isPermissionGranted帮助器方法。

app.intent('user_info', (conv, params, permissionGranted) => {

  if (!permissionGranted) {
    throw new Error('Permission not granted');
  }

  const {requestedPermission} = conv.data;

  if (requestedPermission === 'NAME') {
    conv.user.storage.name = conv.user.name.display;
    return conv.close(responses.sayName(conv.user.storage.name));
  }

  throw new Error('Unrecognized permission');

});