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

5
  • Can you add screen shots of your input.search Intent and input.welcome Intent from Dialogflow? Commented Nov 29, 2017 at 17:50
  • here is image urls of my intents Commented Nov 30, 2017 at 8:54
  • here is image urls of my intents from Dialogflow. 1. imgur.com/a/NcM4z 2. imgur.com/a/NcM4z 3.imgur.com/a/NcM4z 4. imgur.com/a/NcM4z Commented Nov 30, 2017 at 9: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? Commented Dec 2, 2017 at 2: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. Commented Dec 2, 2017 at 15:32

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
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.

Comments

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);
}

1 Comment

I have added "input.unknown" to my script but not working getting the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.