8

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

Neeraj Singh
  • 101
  • 1
  • 5
  • Can you add screen shots of your input.search Intent and input.welcome Intent from Dialogflow? – Prisoner Nov 29 '17 at 17:50
  • here is image urls of my intents – Neeraj Singh Nov 30 '17 at 08:54
  • here is image urls of my intents from Dialogflow. 1. https://imgur.com/a/NcM4z 2. https://imgur.com/a/NcM4z 3.https://imgur.com/a/NcM4z 4. https://imgur.com/a/NcM4z – Neeraj Singh Nov 30 '17 at 09:01
  • Not sure if this has any effect, but you're setting the `WELCOME` action map twice. Maybe try to remove that and see what happens? – Topher Fangio Dec 02 '17 at 02:40
  • I had removed duplicate WELCOME action map. Actually, the error was due to "Dialogflow v2 API" which I had enabled in API versions section for the Agent and now I have disabled that and issue is fixed now. Thanks you your valuable support. – Neeraj Singh Dec 02 '17 at 15:32

3 Answers3

10

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.

Topher Fangio
  • 20,372
  • 15
  • 61
  • 94
  • 1
    thank u for your response, but I have put action name in Actions section. Here is the screenshots link of my intents. imgur.com/a/NcM4z – Neeraj Singh Dec 01 '17 at 08:22
2

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.

Neeraj Singh
  • 101
  • 1
  • 5
1

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);
}
Priyam Gupta
  • 250
  • 1
  • 14