Search code examples
dialogflow-esactions-on-google

How do you read/query the response body in API V2 of dialogflow-fulfillment?


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


Solution

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

    console.log(conv.body);
    var input = conv.body.queryResult.queryText;