Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Dialogflow nodejs sdk "detect Intent with Knowledge Base" method responds with null ? ( V2Beta)

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

like image 769
Denny John Avatar asked Jan 10 '19 07:01

Denny John


1 Answers

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"
            }]
}
like image 197
Suraj Avatar answered Sep 20 '22 15:09

Suraj