I'm a noob in Dialogflow.
I am trying to access parameters from previous intent in follow up intent. Getting the above error
**TypeError: Cannot read property 'parameters' of undefined**
at final (/srv/index.js:29:33)
at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:313:44)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:56:9)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57: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)
Raw response
{
"responseId": "e2434e8b-92a4-41aa-9ff1-acf54003e262-ce609cdc",
"queryResult": {
"queryText": "yes",
"action": "TRansferthiscall.TRansferthiscall-yes",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "Booking confirmed for 8784549879",
"fulfillmentMessages": [
{
"text": {
"text": [
"Booking confirmed for 8784549879"
]
}
}
],
"outputContexts": [
{
"name": "projects/car-wninbg/agent/sessions/f35d3c8e-b572-387d-d185-53e46c73e65b/contexts/transferthiscall-followup",
"lifespanCount": 4,
"parameters": {
"phonenumber": "8784549879",
"phonenumber.original": "8784549879"
}
}
],
"intent": {
"name": "projects/car-wninbg/agent/intents/b3cffc67-fd3c-44a3-8f26-c59234ddbe8c",
"displayName": "TRansfer this call - yes"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 546
},
"languageCode": "en"
},
"webhookStatus": {
"code": 14,
"message": "Webhook call failed. Error: UNAVAILABLE."
},
"outputAudio": "/qqqqqqqqqqqqq",
"outputAudioConfig": {
"audioEncoding": "OUTPUT_AUDIO_ENCODING_MP3",
"synthesizeSpeechConfig": {
"speakingRate": 1,
"pitch": 4,
"voice": {
"name": "en-US-Wavenet-C"
}
}
}
}
Fulfillment request
curl -X POST -H 'Content-Type: application/json' -d '{"responseId":"e2434e8b-92a4-41aa-9ff1-acf54003e262-ce609cdc","queryResult":{"queryText":"yes","action":"TRansferthiscall.TRansferthiscall-yes","parameters":{},"allRequiredParamsPresent":true,"fulfillmentText":"Booking confirmed for 8784549879","fulfillmentMessages":[{"text":{"text":["Booking confirmed for 8784549879"]}}],"outputContexts":[{"name":"projects/car-wninbg/agent/sessions/f35d3c8e-b572-387d-d185-53e46c73e65b/contexts/transferthiscall-followup","lifespanCount":4,"parameters":{"phonenumber":"8784549879","phonenumber.original":"8784549879"}},{"name":"projects/car-wninbg/agent/sessions/f35d3c8e-b572-387d-d185-53e46c73e65b/contexts/system_counters","parameters":{"no-input":0,"no-match":0}}],"intent":{"name":"projects/car-wninbg/agent/intents/b3cffc67-fd3c-44a3-8f26-c59234ddbe8c","displayName":"TRansfer this call - yes"},"intentDetectionConfidence":1,"languageCode":"en"},"originalDetectIntentRequest":{"payload":{}},"session":"projects/car-wninbg/agent/sessions/f35d3c8e-b572-387d-d185-53e46c73e65b"}' https://us-central1-car-wninbg.cloudfunctions.net/dialogflowFirebaseFulfillment
CODE
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const axios = require('axios');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function call_final(agent) {
const phonenumber = agent.parameters.phonenumber;
agent.add(phonenumber + `Is your number correct?` );
}
function final(agent) {
const context = agent.context.get('TRansferthiscall-followup');
const phonenumber = context.parameters.phonenumber;
agent.add(`Yaayyyyy!!!!!!! `+ phonenumber);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function booking(agent) {
const time = agent.parameters.time;
const date = agent.parameters.date;
const url ='http://klucky796.pythonanywhere.com/poc?NAME=test&phonenumber=14487&time='+ time+'&date=' + date;
return axios.get(url)
.then((result) => {
console.log(result.data);
agent.add(result.data);
});
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('BOOKING TIME DATE', booking);
intentMap.set('TRansfer this call - yes', final);
intentMap.set('TRansfer this call', call_final);
agent.handleRequest(intentMap);
});