Skip to content

Commit

Permalink
fix(qna): categories can be provided as config-variable (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
epaminond committed Oct 5, 2018
1 parent 87fba19 commit a30f18d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/functionals/botpress-qna/README.md
Expand Up @@ -22,6 +22,7 @@ The following properties can be configured either in the `qna.json` file or usin
| `exportCsvEncoding` | `QNA_EXPORT_CSV_ENCODING` | No | `utf8` | Encoding for CSV that can be exported from Q&A module
| `qnaMakerApiKey` | `QNA_MAKER_API_KEY` | No | | API-key for [Microsoft QnA Maker](https://www.qnamaker.ai). If provided QnA maker gets used to save items and search through them (instead of NLU-module)
| `qnaMakerKnowledgebase` | `QNA_MAKER_KNOWLEDGEBASE` | No | `botpress` | Name of the QnA Maker knowledgebase to use
| `qnaCategories` | `QNA_CATEGORIES` | No | | Comma-separated list of categories to use within QNA-module

# Usage

Expand Down
18 changes: 4 additions & 14 deletions packages/functionals/botpress-qna/src/index.js
Expand Up @@ -27,7 +27,8 @@ module.exports = {
textRenderer: { type: 'string', required: true, default: '#builtin_text', env: 'QNA_TEXT_RENDERER' },
exportCsvEncoding: { type: 'string', required: false, default: 'utf8', env: 'QNA_EXPORT_CSV_ENCODING' },
qnaMakerApiKey: { type: 'string', required: false, env: 'QNA_MAKER_API_KEY' },
qnaMakerKnowledgebase: { type: 'string', required: false, default: 'botpress', env: 'QNA_MAKER_KNOWLEDGEBASE' }
qnaMakerKnowledgebase: { type: 'string', required: false, default: 'botpress', env: 'QNA_MAKER_KNOWLEDGEBASE' },
qnaCategories: { type: 'string', required: false, default: '', env: 'QNA_CATEGORIES' }
},
async init(bp, configurator) {
const config = await configurator.loadAll()
Expand Down Expand Up @@ -61,7 +62,7 @@ module.exports = {
async ready(bp, configurator) {
const config = await configurator.loadAll()
const storage = this.storage
let categories = []
const categories = config.qnaCategories.split(',')
bp.qna = {
/**
* Parses and imports questions; consecutive questions with similar answer get merged
Expand Down Expand Up @@ -148,18 +149,7 @@ module.exports = {
* @param {String} question - question to match against
* @returns {Array.<{questions: Array, answer: String, id: String, confidence: Number, metadata: Array}>}
*/
answersOn: storage.answersOn.bind(storage),

/**
* @param {string[]} categoriesToRegister - array of category names to register
*/

registerCategories(categoriesToRegister) {
if (!_.isArray(categoriesToRegister)) {
return
}
categories = [...categories, ...categoriesToRegister]
}
answersOn: storage.answersOn.bind(storage)
}

const router = bp.getRouter('botpress-qna')
Expand Down

0 comments on commit a30f18d

Please sign in to comment.