1

first intent second intent As shown in the below code, the flow is not going from Number Intent to First Intent, it is been looped into the number loop. In dialog flow, with every intent corresponding context is also made. The flow is not moving as per context and is stuck in NumberIntent.

The flow should be like the google ask the user its survey id, the user says its id 612020 and google start asking its questions. The flow works fine until the type of question is rating i.e. user has to speak number. The error arises when the user is asked to answer in descriptive manner.

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

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

const axios = require('axios').default;

global.ques = [];
global.i=0;

app.intent('Default Welcome Intent', (conv) => {
   conv.add('Hello! What is your survey id?');
      });

app.intent('NumberIntent', (conv,{number}) => {

  return axios.get('https://www.openeyessurvey.com/api/get_open_survey_info/612020')
  .then((result) => {
      result.data.Item.QUESTIONS.map(questionobj => {
      ques.push(questionobj.question);
     })
     conv.ask(ques[i]);
     i+=1;
  }).catch( err => {
        console.log("error", JSON.stringify(err,null,2));
        conv.close('This is not a valid survey ID');
      });
});

app.intent('FirstIntent', (conv, {number}) => {
      conv.ask(ques[i]);
      i+=1; 
});

app.intent('SecondIntent', (conv) => {
      const des = conv.parameters.any;
      if(des === 'ankit'){
      conv.ask(ques[i]);  
      i+=1;
      }
});

app.intent('ThirdIntent', (conv) => {
      conv.ask(ques[i]);  
      i+=1;
});

app.intent('FourthIntent', (conv, {number}) => {
      conv.ask(ques[i]);
      i+=1;  
});

app.intent('FifthIntent', (conv) => {
      conv.ask(ques[i]);  
      i+=1;
      conv.close('Goodbye!')
});


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

Output Output2

INVALID INTENT NAME ERROR

  • Welcome to StackOverflow! It is difficult to diagnose your problem without seeing how the Intents themselves are setup. Can you update your question to include screen shots of all the Intents referenced? Particularly the sample phrases and the Input and Output contexts. It would also help to see an example conversation of what you expect and what is actually happening. See [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Prisoner Feb 25 '21 at 12:13
  • i have added corresponding intent screenshots – Saakshi Agrawal Mar 03 '21 at 06:39
  • Please look into the code and screenshots of intents and its output. – Saakshi Agrawal Mar 04 '21 at 05:32

1 Answers1

0

I suspect that the issue is that i never actually gets updated.

You treat ques and i as global object, but since this is running under Firebase Cloud Functions, each call may be a new instance of the function. As a new instance, these would get reinitialized.

The flip side of this is that if you didn't get a new instance, it also has the problem that this would not work correctly if more than one person was using the Action at the same time since they would all be sharing the same value of i.

The solution to both is that, instead of storing i as a global variable, store it either in the Actions on Google session storage or in a Dialogflow context parameter.

Storing it as a session parameter, you would get the value, use it, increment it, and then save it again in the session parameter. It might look something like this:

const i = conv.data.i;
conv.ask(ques[i]);
conv.data.i = i+1;
Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Thank you for your support. I made the changes in the code, as you told but the issue persists of Invalid Intent Name. I attached the screenshot of same. @Prisoner – Saakshi Agrawal Mar 04 '21 at 13:27
  • There are a number of possible causes for this, but they sound unrelated to your original question. If this has resolved the problem, I suggest you accept the answer and post a new one about the Invalid Intent Name, showing exactly how you are editing and deploying updates and outlining the steps you took leading up to that error. – Prisoner Mar 04 '21 at 14:22
  • Okay. Thank you for your support. – Saakshi Agrawal Mar 05 '21 at 07:52
  • You're welcome. If an answer has helped, accepting and/or upvoting is always appreciated. – Prisoner Mar 05 '21 at 10:51