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

时光总嘲笑我的痴心妄想 提交于 2019-12-12 12:08:51

问题


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


回答1:


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"
            }]
}


来源:https://stackoverflow.com/questions/54123686/why-does-dialogflow-nodejs-sdk-detect-intent-with-knowledge-base-method-respon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!