只有 2 个意图有效 'MAIN' 和 'TEXT'

Only 2 intents work 'MAIN' and 'TEXT'

我正在尝试使用 actions-on-google / google-assistant-sdk 构建我的第一个应用程序,我想开始使用 3 个意图,MAIN,响应输入文本,HELP用户可以随时拨打电话:

action.json是:

{
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "conversation_1"
      },
      "intent": {
        "name": "actions.intent.MAIN"
      }
    },

    {
      "description": "Help Intent",
      "name": "Help",
      "fulfillment": {
        "conversationName": "conversation_1"
      },
      "intent": {
        "name": "app.StandardIntents.HELP",
        "trigger": {
           "queryPatterns": [
            "Help",
            "HELP",
            "help"
        ]
      }
    }
    }

  ],
  "conversations": {
    "conversation_1": {
      "name": "conversation_1",
      "url": "https://us-central1-sillytest-16570.cloudfunctions.net/sayNumber",
      "fulfillmentApiVersion": 2      
    }
  }
}

index.js:

'use strict';

process.env.DEBUG = 'actions-on-google:*';

const ActionsSdkApp = require('actions-on-google').ActionsSdkApp;
const functions = require('firebase-functions');

const NO_INPUTS = [
  'I didn\'t hear that.',
  'If you\'re still there, say that again.',
  'We can stop here. See you soon.'
];

exports.sayNumber = functions.https.onRequest((request, response) => {
  const app = new ActionsSdkApp({request, response});

  function mainIntent (app) {
    console.log('mainIntent');
    let inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
      'I can read out an ordinal like ' +
      '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>', NO_INPUTS);
    app.ask(inputPrompt);
  }

  function rawInput (app) {
    console.log('rawInput');
    if (app.getRawInput() === 'bye') {
      app.tell('Goodbye!');
    } else {
      let inputPrompt = app.buildInputPrompt(true, '<speak>You said, <say-as interpret-as="ordinal">' +
        app.getRawInput() + '</say-as></speak>', NO_INPUTS);
      app.ask(inputPrompt);
    }
  }

  function helpHandler (app) {
    console.log('rawInput');
    app.ask('<speak>What kind of help do you need?</speak>');
  }

  let actionMap = new Map();
  actionMap.set(app.StandardIntents.MAIN, mainIntent);
  actionMap.set(app.StandardIntents.TEXT, rawInput);
  actionMap.set(app.StandardIntents.HELP, helpHandler);

  app.handleRequest(actionMap);
});

我将 firebase 推送为:

firebase deploy --only functions

并将 Google 操作推送为:

gactions update --action_package action.json --project <YOUR_PROJECT_ID>

在测试小助手here的时候,启动的很好,重复我输入的号码,等待另一个号码,等等,但是当我输入help时,它是已终止且未响应!

更新

我尝试了以下方法,但没有成功:

actionMap.set("app.StandardIntents.HELP", helpHandler);

当我 enter/say "Help" 时,我应该期望该应用程序 "What kind of help do you need?",但发生的只是重写它,与处理任何其他数字的方式相同。

您的 actionMap 正在寻找 app.StandardIntents.HELP,但它不存在。您可以在 GitHub 存储库中查看所有 the standard intents

app.StandardIntents.MAIN returns 对应于“'actions.intent.MAIN'”的另一个字符串。它不会读取您的 action.json 并生成新的意图。因此,app.StandardIntents.HELP 实际上 returns undefined 并且永远不会被调用。

您的地图应使用字符串作为帮助意图,因为它在 app 对象中不可用作常量。

actionMap.set("app.StandardIntents.HELP", helpHandler);

这应该可以解决您的问题。如果没有,请告诉我。

非内置 Intent 仅支持 first message in a conversation. After that, while you can use them for speech biasing,您只会获得一个内置 Intent,例如 TEXT Intent。