Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting error "Action Error: no matching intent handler for: null" while accessing webhook URL

I am trying to call webhook from dialog flow and not getting a response from webhook, the response I am getting from the response section, which I have put in intent. I have also enabled the webhook for each intent and also put the webhook URL, which is generated from firebase CLI in fulfillment URL section. I am attaching the screenshots of firebase log and JSON response which we see in dialog flow "show JSON" and index.js file as well.I am stuck for 2 weeks to resolve it.

'use strict';

process.env.DEBUG = 'actions-on-google:*';
const { DialogflowApp } = require('actions-on-google');
const functions = require('firebase-functions');
let express = require('express');
let bodyParser = require('body-parser');

// Constants for Dialogflow Agent Actions
let app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({type: 'application/json'}));

const BYE_RESPONSE = 'input.search';
const WELCOME = 'input.welcome';

exports.helloAssistant = functions.https.onRequest((req, res) => {
  console.log('Request headers: ' + JSON.stringify(req.headers));
  console.log('Request body: ' + JSON.stringify(req.body));
  const asst = new DialogflowApp({request: req, response: res});


  // Welcome
  function welcome(asst) {
    asst.ask('Want to search product or order history');
    asst.tell('hello Neeraj!');
  }

  // Leave conversation with SimpleResponse

  function byeResponse (asst) {
    app.post('/',function (req, res) {
      var myProduct = req.body.result.parameters["productParameter"];
      //let intent=asst.getIntent();
      var address ="https://ipadress/rest/v2/electronics/products/search";
      var address1="https://ipadress";
      switch(myProduct){
        case 'BYE_RESPONSE':
          req.post(address);
          break;

        case 'WELCOME':
          asst.tell('welcome!');
          break;

        default:
          req.post(address1);
          break;
      }

      asst.tell('We swear to serve the master of the Precious.');
    });
  }

  const actionMap = new Map();
  actionMap.set(WELCOME, welcome);

  actionMap.set(BYE_RESPONSE, byeResponse);
  actionMap.set(WELCOME, welcome);
  asst.handleRequest(actionMap);
});

.json response in dialogflow

.firebase log

like image 590
Neeraj Singh Avatar asked Nov 29 '17 15:11

Neeraj Singh


3 Answers

I just ran into this exact same error and it was caused because I forgot to put my intent name in the Enter action name field of the Actions section.

So, it was passing null as the intent name since I did not specify one.

I only figured it out by very carefully re-reading https://developers.google.com/actions/dialogflow/first-app.

like image 76
Topher Fangio Avatar answered Oct 26 '22 01:10

Topher Fangio


Thank you all for your valuable responses. Somehow, I am able to fix this null error. Actually, I had enabled "Dialogflow V2 API" in API version section for the Agent. Now, I have disabled it and it works for me.

like image 32
Neeraj Singh Avatar answered Oct 26 '22 01:10

Neeraj Singh


For every agent there need to be an unknown Intent handler for handling the unexpected situation such as null, etc

'input.unknown': () => {
  // The default fallback intent has been matched, try to recover.
  // Define the response users will hear
  responseJson.speech = 'I\'m having trouble, can you try that again?';
  // Define the response users will see
  responseJson.displayText = 'I\'m having trouble :-/ can you try that again?';
  // Send the response to API.AI
  // response.json(responseJson);
  callback(null, responseJson);
}
like image 24
Priyam Gupta Avatar answered Oct 26 '22 01:10

Priyam Gupta