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:
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):
The error in the log is the same as the one I mentioned starting.