最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin8浏览0评论

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"
  }
}
发布评论

评论列表(0)

  1. 暂无评论