Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I send a context parameter to the webhook/fulfilments DialogFlow v2

I am reading the official documentation from this link: https://cloud.google.com/dialogflow-enterprise/docs/reference/rest/v2beta1/QueryParameters but I am unable to pass a context parameter into my request using the following code:

  var query = req.body.query;
    const request = {
      session: sessionPath,
      queryInput: {
        text: {
          text: query,
          languageCode: 'en-US',
        },
      },
      queryParameters: {
        contexts: ['Question-followup']
      },
    };

    // Send request and log result
    sessionClient
      .detectIntent(request)
      .then(responses => {
        const result = responses[0].queryResult;
        console.log(result);
        res.json(result);   
        if (result.intent) {
          console.log(`  Intent: ${result.intent.displayName}`);
        } else {
          console.log(`  No intent matchede.`);
        }
      })
      .catch(err => {
        console.error('ERROR:', err);
      });

In the documentation it says that I should have something like:

"contexts": [
    {
      object(Context)
    }
  ],

The reason I want this is that sometimes DialogFlow is not able to detect the Intent so I would think that by passing the context into the parameter would help dialogflow to find the correct intent!

like image 587
Mizlul Avatar asked Jun 06 '18 08:06

Mizlul


1 Answers

The contexts array needs to be an array of Context objects, not just a string with the context names.

The context object looks something like

{
  "name": "projects/<Project ID>/agent/sessions/<Session ID>/contexts/<Context Name>",
  "lifespanCount": 1,
  "parameters": {
    "anyParameterName": "parameterValue"
  }
}
like image 146
Prisoner Avatar answered Sep 30 '22 04:09

Prisoner