我无法在谷歌助手上触发我的第二个动作

时间:2017-11-03 18:42:49

标签: actions-on-google

我一直在玩sdk的动作,它似乎有效,但仅限于我的主要意图。我添加了第二个意图,它永远不会触发。

这是我的action.json:

{
  "actions": [
    {
      "description": "Default Welcome Intent",
      "name": "MAIN",
      "fulfillment": {
        "conversationName": "conversation_1"
      },
      "intent": {
        "name": "actions.intent.MAIN"
      }
    },
    {
      "name": "add",
      "intent": {
        "name": "myintent.ADD",
        "parameters": [
          {
            "name": "somenumber",
            "type": "SchemaOrg_Number"
          }
        ],
        "trigger": {
          "queryPatterns": [
            "add $SchemaOrg_Number:somenumber",
            "add"
          ]
        }
      },
      "fulfillment": {
        "conversationName": "add"
      }
    }
  ],
  "conversations": {
    "conversation_1": {
      "name": "conversation_1",
      "url": "https://myaddress/sayNumber",
      "fulfillmentApiVersion": 2
    },
    "add": {
      "name": "add",
      "url": "https://myaddress/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 addIntent (app) {
    console.log('addIntent');
    let inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
      'I can add.</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>'+app.getIntent()+'</speak>', NO_INPUTS);
      app.ask(inputPrompt);
    }
  }

  let actionMap = new Map();
  actionMap.set(app.StandardIntents.MAIN, mainIntent);
  actionMap.set(app.StandardIntents.TEXT, rawInput);
  actionMap.set("myintent.ADD", addIntent);

  app.handleRequest(actionMap);
});

我可以说talk to my action name然后即使我使用add关键字,我之后说的所有内容都会被视为原始输入。我究竟做错了什么?

1 个答案:

答案 0 :(得分:1)

这是正确的。 actions.json包仅定义用户{9}}如何使用您的操作。 start a conversation,您传递TEXT(或OPTION)意图,并且您需要自己处理自然语言处理。其他意图可用于Once the conversation has started,但不用于解析响应。

这与其他一些语音代理处理语言解析的方式不同。如果您已拥有自己的NLP,则主要打算使用Actions SDK。

如果你不这样做,你可能最好使用Dialogflow或Converse.AI之类的东西。