如何通过dialogflow将其他参数从nodejs客户端传递到webhook?

时间:2018-07-23 21:01:17

标签: node.js dialogflow

实际上,我想将一些其他参数(例如用户名,用户ID)传递给webhook,但我无法执行此操作。

我正在使用sessionClient的detectIntent()方法。以下是请求:

function detectEventIntent(projectId, sessionId, eventName, languageCode) {

  // Imports the Dialogflow library
  const dialogflow = require('dialogflow');

  // Instantiates a sessison client
  const sessionClient = new dialogflow.SessionsClient();

  // The path to identify the agent that owns the created intent.
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);

  // The text query request.
  const request = {
      session: sessionPath,
      queryInput: {
        text: {
          text: query,
          languageCode: languageCode,
        },
      },
      queryParams:{
         payload: {
            data:{
             username: 'gaurav',
             userId: usr1
            }
         }
     }
  };

  sessionClient
    .detectIntent(request)
    .then(responses => {
      console.log('Detected intent');

      logQueryResult(sessionClient, responses[0].queryResult);
    })

    .catch(err => {
      console.error('ERROR:', err);
    });

}

1 个答案:

答案 0 :(得分:0)

There are differences in passing some additional parameters such as username, user ID in dialogFlow V1 and dialogFlow V2. In dialogFlow V1 its relatively hard to pass additional parameters whereas in dialogFlow V2 one can easily pass user ID, project ID. Just give additional functions in the dialogFlow after

const dialogflow = require('dialogflow');

Just give as:-

let projectId = 'Name as you like';
let sessionId = ' As you Like ';
let dialogflow = require('dialogflow');
let config = {
  credentials: {
    private_key: "....Your Key.....",
    client_email: "....Your Service Account mail...."
  }
}
相关问题