6

I am integrating the Dialogflow Nodejs sdk into my application to detect the knowledge base intent with the help of the following document nodejs-dialoglowflow-detect-knowledgebase-intent.

Below is my query request

const request = {
session: sessionPath,
queryInput: {
  text: {
    // The query to send to the dialogflow agent
    text: message,
    // The language used by the client (en-US)
    languageCode: 'en-US',
  },
},
queryParams: {
  knowledgeBaseNames: ['projects/my-project-id/knowledgeBases/my-knowledge-base-name'],
},

};

When I test the FAQ in dialogflow console it works, but when I try to do the same with Dialoglflow Nodejs SDK, the knowledgeAnswers object from dialogflow response is null.

Any help is appreciated. Thanks

Denny John
  • 464
  • 7
  • 20

1 Answers1

5

This is happening because of the incorrect value in knowledgeBaseNames property. When you create a knowledge base it returns below response:

{
  "name": "projects/project-id/knowledgeBases/NDA4MTM4NzE2MjMwNDUxMjAwMA",
  "displayName": "knowledge-base-display-name"
}

knowledgeBaseNames property accepts the array of name. It is different than displayName.

In case you have created the Konwledgebase form Dialogflow dashboard, you won't see this detail in the dashboard. However, Dialogflow SDKs Provide APIs to get the list of knowledgebase of an agent. Node js V2Beta1 SDK has a method projects.knowledgeBases.list, which, when given a project name, will list all of the knowledge bases along with their display name and their name. You can send the list of names into the detect intent request.

If your use case only requires knowing the ID for the knowledge base then you can get if from "Try it out" section of the Dialogflow console. Type a question you have added in knowledgebase and click on diagnostic info. It will show the dialogflow response in JSON. Look for the knowledgeAnswers object. The knowledgebase ID is the part of source property as mentioned below:

"knowledgeAnswers": {
            "answers": [{
                "source": "projects/project-id/knowledgeBases/knowledgebase-id/documents/document-id"
            }]
}
Suraj
  • 1,625
  • 1
  • 15
  • 33
  • 2
    The answer isn't clear in what's it's directing OP to actually do. I have a similar problem and have used the "name" value from the diagnostic info that Google shares from testing inside the console, and it still doesn't work via the SDK. – tgmerritt Sep 13 '19 at 19:22
  • 2
    For me the issue was that I was using the /v2/ API version instead of the /v2beta1/ version – Federico Schiocchet Dec 16 '19 at 19:02