Nodejs-dialogflow: knowledge beta connection error

Created on 21 Mar 2019  路  1Comment  路  Source: googleapis/nodejs-dialogflow

hi,

I am trying to add the knowledge beta but I am getting an error

error:

UnhandledPromiseRejectionWarning: TypeError: match error: could not instantiate a path template from projects/botkit-a4598/knowledgeBases/projects/botkit-a4598/knowledgeBases/NzU0ODk2NTM2LOMzMzMwNTM0NA
    at PathTemplate.match (/home/****/project/demo/node_modules/google-gax/build/src/pathTemplate.js:99:19)

code:

const dialogflow = require('dialogflow');
const uuid = require('uuid');

module.exports = {
  know:async function(
  projectId,
  sessionId,
  languageCode,
  knowledgeBaseFullName,
  query,
  error
) {
  // [START dialogflow_detect_intent_knowledge]
  // Imports the Dialogflow client library
  const dialogflow = require('dialogflow').v2beta1;

  // Instantiate a DialogFlow client.
  const sessionClient = new dialogflow.SessionsClient();

   projectId = 'botkit-a4598fgh';
   sessionId = `12345`;
   languageCode = 'en-US';
   knowledgeBaseFullName = `projects/botkit-a4598fgh/knowledgeBases/NzU0ODk2NTM2MTMzMzMwNTM0NA`;
   query = `How can I track my orders & payment?`;

  // Define session path
  const sessionPath = sessionClient.sessionPath(projectId, sessionId);
  const knowbase = new dialogflow.KnowledgeBasesClient();
  const knowledgeBasePath = knowbase.knowledgeBasePath(
    projectId,
    knowledgeBaseFullName
  );

  // The audio query request
  const request = {
    session: sessionPath,
    queryInput: {
      text: {
        text: query,
        languageCode: languageCode,
      },
    },
    queryParams: {
      knowledgeBaseNames: [knowledgeBasePath],
    },
}
if(error)
{
  console.log(error);
}
const responses = await sessionClient.detectIntent(request);
  const result = responses[0].queryResult;
  console.log(`Query text: ${result.queryText}`);
  console.log(`Detected Intent: ${result.intent.displayName}`);
  console.log(`Confidence: ${result.intentDetectionConfidence}`);
  console.log(`Query Result: ${result.fulfillmentText}`);
  const answers = result.knowledgeAnswers.answers;
  console.log(`There are ${answers.length} anwser(s);`);
  answers.forEach(a => {
    console.log(`   answer: ${a.answer}`);
    console.log(`   confidence: ${a.matchConfidence}`);
    console.log(`   match confidence level: ${a.matchConfidenceLevel}`);
  });
  // [END dialogflow_detect_intent_knowledge]
}

}

please help me
thanks

question dialogflow

Most helpful comment

Hi @sarigasurendranms it looks like there's an issue with how you're calling knowledgeBasePath(). In your example you're passing the full name as the second parameter but it is expecting just NzU0ODk2NTM2MTMzMzMwNTM0NA.

>All comments

Hi @sarigasurendranms it looks like there's an issue with how you're calling knowledgeBasePath(). In your example you're passing the full name as the second parameter but it is expecting just NzU0ODk2NTM2MTMzMzMwNTM0NA.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BenjaminHoegh picture BenjaminHoegh  路  7Comments

Knowledge91 picture Knowledge91  路  7Comments

praveenptl71 picture praveenptl71  路  4Comments

yusufkhan07 picture yusufkhan07  路  5Comments

YrockInnovators picture YrockInnovators  路  4Comments