1

In the v1, the request and response were specifically defined and read via -

console.log(request.body);
var input = request.body.queryResult;

In the v2, the request and response, both are wrapped inside the 'app'. My declarations of app are as below -

const {dialogflow} = require('actions-on-google');
const app = dialogflow({clientId: 'projectId'});

I have tried using the following but understood that it's not exactly the right way -

console.log(conv.request.body); //Getting undefined in console
//OR
console.log(app.request.body); //Getting undefined in console
var input = conv.request.body.queryResult; 

Do I need to specifically mention request and response anywhere similar to the WebhookClient({request, response}) in V1?

Thanks in advance

Sairaj Sawant
  • 1,842
  • 1
  • 12
  • 16
AceDullur
  • 61
  • 8
  • Just to make sure I didn't miss something. Did you use to call "queryResult" on the Dialogflow API V1? Additionally, please add how are you sending requests to the API v2 – Kevin Quinzel Feb 27 '20 at 00:42
  • Yes, like I indicated above, using ' request.body.queryResult.queryText' I could retrieve the value of the input given by the user in V1. To be a little clearer, console.log('Dialogflow Request body: ' + JSON.stringify(request.body)) would show me the response in the console. I am unable to find a way to do the same in V2. Hope I have provided further clarity. FYI, I am using the in-line editor – AceDullur Feb 27 '20 at 06:24

2 Answers2

3

After million trial and error, I finally found it and it's terribly simple

console.log(conv.body);
var input = conv.body.queryResult.queryText;
AceDullur
  • 61
  • 8
  • That's great. If you found the solution, consider to accept your own answer so the community with similar issues will find this :) – Kevin Quinzel Feb 28 '20 at 17:22
1

I know this seems to already be resolved. But I noticed that you did a console.log() on conv.body. Assuming this conv variable is the JSON response object you received from Dialogflow, I'd recommend doing console.log(JSON.stringify(conv)), which, not surprisingly prints the full JSON object to string in the console. This has saved me much time while trying to figure out the many JSON formats.

Lucas Raza
  • 499
  • 1
  • 4
  • 13