1

I follow up an intent for intent let's say "master intent" to have a child intent follow as yes and no response intent

If it's yes i want to get the parameters from the master intent I am trying to access it using context like this :

var name = agent.context.get('saveContact.saveContact-yes').params['name'];Cannot read property 'get' of undefined

but I don't know what to put in the get Is it the context name ? or intent name for the master or the specific child intent name ? I tried the both and get Null

I've got Cannot read property 'get' of undefined in the log .

Libraries :

    "firebase-functions": "^2.0.2",
    "firebase-admin": "^5.13.1",
    "googleapis": "^27.0.0",
    "actions-on-google": "2.2.0",
    "dialogflow-fulfillment": "^0.4.1"

rest of the code :

function SaveContact(agent){
 //var name = agent.parameters.name;
 var name = agent.context.get('saveContact.saveContact-yes').params['name'];
 var email = agent.context.get('saveContact.saveContact-yes').params['email'];
// var email=agent.parameters.email;
   return admin.database().ref('/contacts').push({name: name,email:email}).then((snapshot) => {
 // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
     agent.add('added sucessfully');
// console.log('database write sucessful: ' + snapshot.val());
});
}
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response }); /// Thid is to handle the communication with dialogflow
  let intentMap = new Map();
  intentMap.set('makeAppointment', makeAppointment);  // It maps the intent 'Make Appointment' to the function 'makeAppointment()'
  intentMap.set('saveContact-yes', SaveContact);
  agent.handleRequest(intentMap);

});
  • Can you [edit](https://stackoverflow.com/posts/55550129/edit) your question to include the rest of your code, including the libraries that you're using? This looks valid on the surface, but there may be other parts of your code that could be causing the problem. – Prisoner Apr 06 '19 at 15:04
  • The rest of the codes is just the basic stuff , I include the Libraries – Rand Abu Salim Apr 06 '19 at 15:07
  • Really, the rest of the code would help, at least for that handler function. – Prisoner Apr 06 '19 at 15:09
  • Okay, I edit it – Rand Abu Salim Apr 06 '19 at 15:15
  • Have a look here: Looks similar issue: https://stackoverflow.com/questions/55039936/dialogflow-context-suddenly-undefined – Anshul Apr 07 '19 at 17:07
  • Also try doing this '#saveContact.saveContact-yes' https://dialogflow.com/docs/intents/actions-parameters#from_contexts – Anshul Apr 07 '19 at 17:10

1 Answers1

0

Make sure you are using the latest version of the dialogflow-fulfillment library. It looks like, from your package.json you are using version 0.4.1, which had a different way of working with contexts.

agent.context.get() was introduced in version 0.6.0, with the previous method being deprecated.

You can update to the latest version using npm install --save dialogflow-fulfillment@latest

Prisoner
  • 49,922
  • 7
  • 53
  • 105