0

I'm Using Dialogflow with Firebase and the V2 API, I'm getting this error on my webhook:

TypeError: Cannot read property 'parameters' of undefined
    at exports.dialogflowFirebaseFulFillment.functions.https.onRequest (/srv/index.js:15:38)
    at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:9)
    at /worker/worker.js:783:7
    at /worker/worker.js:766:11
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

I've already looked this post, but I cannot figure any difference between his line and mine.

This is the code:

const functions = require('firebase-functions');

process.env.DEBUG = 'dialogflow:debug';

const admin = require('firebase-admin');
admin.initializeApp();

exports.dialogflowFirebaseFulFillment = functions.https.onRequest((request, response) => {
  console.log('Request headers: ' + JSON.stringify(request.headers));
  console.log('Request body: ' + JSON.stringify(request.body));

  const parameters = request.body.queryResult.parameters;
  const db = admin.firestore();

  const reservationRef = db.collection('reservations').doc('room-reservation');
  reservationRef.add(parameters).then(() => {
    response.send({
      speech: 'Room reserved!'
    });
  }).catch((e => {
    response.send({
      speech: 'something went wrong'
    })
  }))
});

Is the error anywhere else? Thanks.

EDIT: Actually none of the console.log's are showing.

My webhook is being triggered from the cloud function url. I've already provided it: webhook

When browsing that url it says: Error: could not handle the request, but I suposse it is normal as I haven't provided any params. Is that correct?

Do I have to provide authentication when configuring the webhook?

EDIT 2:

This is the log (Couldn't find it, my mistake): enter image description here

The error in the log is the same as the one I mentioned starting.

ParticleDuality
  • 139
  • 3
  • 13
  • You are printing the value of `request.body` in the logs. Can you look at the logs and include the results from that line in the question and how, exactly, you are triggering the webhook? – Prisoner Nov 19 '19 at 22:24
  • Thank you, I'l edit it. – ParticleDuality Nov 19 '19 at 22:26
  • 1
    No logs at all? You should be able to see them from https://console.firebase.google.com/ if you go to the Functions navigation on the left and then Logs along the top. Is your function listed if you just go to the Functions navigation on the Firebase Console? – Prisoner Nov 19 '19 at 22:52

0 Answers0