1

In the commented area of code if a function call is done.

newGame.call(conv);

It throws the error:"TypeError: Cannot read property 'ask' of undefined at newGame"

And if i replace the comment with the below line of code.

It throws the error:"Error: No response has been set."

app.intent('newGameIntent',newGame);

Here is the code.

const functions = require('firebase-functions');
process.env.DEBUG = 'actions-on-google:*';
const {dialogflow,SimpleResponse} = require('actions-on-google');
const app = dialogflow();

var welcome =(conv)=>{
    if(newUser)
    {
        // how to trigger 'newGameIntent' here
    }
    else
    {
        // how to trigger 'LoadGameIntent' here
    }
}

var newGame =(conv)=>{
    conv.ask(new SimpleResponse({
      speech: "Welcome to new game",
      text: "Welcome to new game"
    }));
}

var loadGame =(conv)=>{
    conv.ask(new SimpleResponse({
      speech: "Resuming the game for you",
      text: "Resuming the game for you"
    }));
}

app.intent('Default Welcome Intent',welcome);
app.intent('newGameIntent',newGame);
app.intent('LoadGameIntent',loadGame);

exports.MySample = functions.https.onRequest(app);
David Passmore
  • 6,089
  • 4
  • 46
  • 70
Rahil B Rasheed
  • 129
  • 1
  • 8

1 Answers1

0

In your code you define two var newGame and therefore there will be a problem in the line app.intent('LoadGameIntent', loadGame); .

And the error cannot read property ask of undefined mean that conv is not kept in your context. I would personnaly try something like that:

app.intent('newGameIntent',conv => newGame(conv));

And modify your newGame:

function newGame(conv) {
conv.ask(new SimpleResponse({
      speech: "Welcome to new game",
      text: "Welcome to new game"
    }));
}
Rémi C.
  • 339
  • 2
  • 12
  • defining "two var newGame" was typing mistake. I have updated the question. Sorry for that. But I would like to know how will I trigger a different intent based on the condition. – Rahil B Rasheed Jun 04 '18 at 10:02
  • As I mentioned, instead of wanting to trigger an intent specifically you could trigger a function. Why does it need to be an intent ? – Rémi C. Jun 04 '18 at 11:26