谷歌动作:使用动作SDK退出对话不会调用actions.intent.CANCEL

时间:2019-01-25 11:47:38

标签: actions-on-google

我正在使用动作SDK来构建实现。我正在使用Google Functions。 action.json

中包含以下内容
{
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "App"
      },
      "intent": {
        "name": "actions.intent.MAIN",
        "trigger": {
          "queryPatterns": [
            . . .
          ]
        }
      }
    }
  ],
  "conversations": {
    "App": {
      "name": " ... ",
      "url": " ...",
      "fulfillmentApiVersion": 2
    }
  },
  "locale": "en"
}

在功能代码中,我注意到当用户说出/键入actions.intent.CANCELexit时,Goodbye的自定义意图代码没有被调用。在仿真器中,仅显示<earcon>。 JS代码如下:

app.intent('actions.intent.MAIN', (conv) => {
  conv.ask('Welcome to ...');
});

app.intent('actions.intent.TEXT', (conv, input) => {
  // the main logic of the application is here
  });

app.intent('actions.intent.CANCEL', (conv) => {
  conv.close(`Okay, let's try this again later.`); 
  // this code does not get called
});

在action.json中需要设置一些内容以使取消意图起作用

1 个答案:

答案 0 :(得分:0)

是的,您需要add something到action.json才能将CANCEL Intent发送给您。在现有的conversations对象中,添加一个inDialogIntents属性,该属性带有一组对象,这些对象的名称为CANCEL Intent。像这样:

"conversations": {
  "App": {
    "name": "...",
    "url": "...",
    "fulfillmentApiVersion": 2
    "inDialogIntents": [
      {
        "name": "actions.intent.CANCEL"
      }
    ]
  }
}