javascript - how do I send a context parameter to the webhookfulfilments DialogFlow v2 - Stack Overflow

I am reading the official documentation from this link:but I am unable to pass a context parameter into

I am reading the official documentation from this link: 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!

I am reading the official documentation from this link: https://cloud.google./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!

Share Improve this question asked Jun 6, 2018 at 8:01 MizlulMizlul 2,29010 gold badges52 silver badges105 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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"
  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744836870a4596315.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信