casolorz
casolorz

Reputation: 9544

I can't trigger my second action on google assistant

I have been playing around with the actions sdk and it seems to work but only for my main intent. I added a second intent and it never triggers.

Here is my 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
    }
  }
}

And here is my 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);
});

I can say talk to my action name and then everything I say after that gets handled as raw input even if I use the add keywords. What am I doing wrong?

Upvotes: 2

Views: 138

Answers (1)

Prisoner
Prisoner

Reputation: 50701

That is correct. The actions.json package only defines how users can start a conversation with your Action. Once the conversation has started, you are passed TEXT (or OPTION) intents and you are expected to handle the natural language processing yourself. Additional intents can be used for speech biasing, but aren't used to parse the response.

This is different than how some other voice agents handle language parsing. The Actions SDK is primarily intended if you have your own NLP already.

If you don't, you are probably better off using something like Dialogflow or Converse.AI.

Upvotes: 1

Related Questions