0

I want to run this code in dialogflow ,basically i want to use if condition for example. if my intent "Done" reply response [Text Response] =>'Now add 2 more and say got it' then it switch to my another intent called "alright" so the response should be "you no. is 1" and end the converstation. similary if my intent "Done" reply response [Text Response] =>'Now add 4 more and say got it' then it switch to my another intent called "alright" so the response should be "you no. is 2" and end the converstation.

and goes on.

just look at the SS Below enter image description here enter image description here

'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

var numr=0;
app.intent('done',(conv,output)=>{
  if(conv.ask ==='Now add 2 more, and say got it'){
    numr=1;
    return numr;
  }
  else{
    numr=2;
    return numr;
  }   
});

app.intent('Alright',(conv)=>{
  conv.close('your number is '+ numr);
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

1 Answers1

0

There are a number of issues with your code that make it difficult to understand exactly what you're doing. However, there are a few things to note. I'm assuming you're using JavaScript here.

  1. You have a syntax error in how you are using else. The else statement should be followed by an execution block. You look like you're following it with a condition. Perhaps you are trying to use else if there?

  2. conv.ask is a function. You're then assigning a string to it which would remove it as a function. I don't think this is what you mean to do here.

  3. In the Intent Handler for the "done" Intent, you're not sending anything back to the user using the conv.ask() function since you just removed that as a function.

  4. Setting a global variable does not guarantee the value of it will be preserved in between Intent Handler calls. If you want a value saved during a conversation, you should use a Context or conv.data or other means.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • **Actually i want to ask. i have to two intent in action first is done and another is Alright.....** – Rishabh Dinkar Nov 08 '19 at 06:57
  • I see the "done" and "alright" Intent Handlers. I'm not sure what your question is, however. Please [update your original question](https://stackoverflow.com/posts/58672594/edit) to clarify what your problem is. The more information or explanation you can provide, the better the chances are that we're able to help you. Providing things such as example conversation, error logs, or illustrating what it is doing and why this is incorrect. – Prisoner Nov 08 '19 at 11:51
  • Hello sir, please help me and solve my query .. please read the code above – Rishabh Dinkar Nov 11 '19 at 12:46
  • Help please sir.. view my question – Rishabh Dinkar Nov 12 '19 at 17:34