Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
5,566 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"qnaDir": "./generated/qna" | ||
} |
1 change: 1 addition & 0 deletions
1
packages/dev-bot/generated/intents/__qna__6d2c0js5y6_who_is_donkey.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "entities": [] } |
3 changes: 3 additions & 0 deletions
3
packages/dev-bot/generated/intents/__qna__6d2c0js5y6_who_is_donkey.utterances.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
who is zebra? | ||
who is donkey? | ||
who is monkey? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "6d2c0js5y6_who_is_donkey", | ||
"data": { | ||
"questions": ["who is zebra?", "who is donkey?", "who is monkey?"], | ||
"answer": "animal!", | ||
"enabled": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/ | ||
webpack.js |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Botpress Q&A ⚡ | ||
|
||
Botpress Q&A is a Botpress module that adds the unified Q&A management interface to your bot admin panel. | ||
|
||
It relies on the NLU module for recognizing the questions. It also requires the `builtins` module to be present. | ||
|
||
# Installation | ||
|
||
⚠️ **This module only works with the new [Botpress X](https://github.com/botpress/botpress).** | ||
|
||
- Install the peer dependencies and the module iteslf `yarn add @botpress/builtins @botpress/nlu @botpress/qna` | ||
- Configure [NLU](https://github.com/botpress/botpress/tree/master/packages/functionals/botpress-nlu#botpress-nlu-) | ||
|
||
# Usage | ||
|
||
Go to the bot admin panel and choose Q&A from the left hand side menu. | ||
|
||
# Contributing | ||
|
||
The best way to help right now is by helping with the exising issues here on GitHub and by reporting new issues! | ||
|
||
# License | ||
|
||
Botpress is dual-licensed under [AGPLv3](/licenses/LICENSE_AGPL3) and the [Botpress Proprietary License](/licenses/LICENSE_BOTPRESS). | ||
|
||
By default, any bot created with Botpress is licensed under AGPLv3, but you may change to the Botpress License from within your bot's web interface in a few clicks. | ||
|
||
For more information about how the dual-license works and why it works that way please see the <a href="https://botpress.io/faq">FAQS</a>. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"qnaDir": "./qna" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
"name": "@botpress/qna", | ||
"version": "10.11.1", | ||
"description": "Botpress Q&A module", | ||
"main": "bin/node.bundle.js", | ||
"homepage": "https://github.com/botpress/modules", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/botpress/modules" | ||
}, | ||
"botpress": { | ||
"menuText": "Q&A", | ||
"menuIcon": "question_answer", | ||
"webBundle": "bin/web.bundle.js", | ||
"moduleView": { | ||
"stretched": true | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"watch": "node webpack.js --watch", | ||
"compile": "node webpack.js --compile" | ||
}, | ||
"author": "Botpress, Inc.", | ||
"license": "AGPL-3.0", | ||
"peerDependencies": { | ||
"botpress": ">= 10.0.0", | ||
"@botpress/nlu": ">= 10.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-loader": "^7.1.2", | ||
"babel-plugin-transform-async-to-generator": "^6.24.1", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-latest": "^6.24.1", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-0": "^6.24.1", | ||
"babel-register": "^6.26.0", | ||
"brace": "^0.11.0", | ||
"classnames": "^2.2.5", | ||
"copy-webpack-plugin": "^4.4.1", | ||
"core-js": "^2.4.1", | ||
"css-loader": "^0.28.9", | ||
"draft-js": "^0.10.4", | ||
"draftjs-utils": "^0.9.1", | ||
"extract-text-webpack-plugin": "^3.0.2", | ||
"file-loader": "^1.1.6", | ||
"node-sass": "^3.11.2", | ||
"react-select": "^1.2.1", | ||
"react-splitter-layout": "^3.0.0", | ||
"sass-loader": "^6.0.6", | ||
"style-loader": "^0.20.1", | ||
"webpack": "^3.11.0", | ||
"webpack-node-externals": "^1.6.0" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.17.1", | ||
"bluebird": "^3.5.1", | ||
"bluebird-retry": "^0.11.0", | ||
"lodash": "^4.17.4", | ||
"mkdirp": "^0.5.1", | ||
"ms": "^2.1.1", | ||
"nanoid": "^1.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Storage from './storage' | ||
import { processEvent } from './middleware' | ||
|
||
let storage | ||
let logger | ||
|
||
module.exports = { | ||
config: { | ||
qnaDir: { type: 'string', required: true, default: './qna', env: 'QNA_DIR' } | ||
}, | ||
async init(bp, configurator) { | ||
const config = await configurator.loadAll() | ||
storage = new Storage({ bp, config }) | ||
await storage.initializeGhost() | ||
|
||
logger = bp.logger | ||
|
||
bp.middlewares.register({ | ||
name: 'qna.incoming', | ||
module: 'botpress-qna', | ||
type: 'incoming', | ||
handler: async (event, next) => { | ||
if (!await processEvent(event, { storage, logger })) { | ||
next() | ||
} | ||
}, | ||
order: 11, // must be after the NLU middleware and before the dialog middleware | ||
description: 'Listen for predefined questions and send canned responses.' | ||
}) | ||
}, | ||
ready(bp) { | ||
const router = bp.getRouter('botpress-qna') | ||
|
||
router.get('/', async (req, res) => { | ||
try { | ||
res.send(await storage.getQuestions()) | ||
} catch (e) { | ||
logger.error('QnA Error', e, e.stack) | ||
res.status(500).send(e.message || 'Error') | ||
} | ||
}) | ||
|
||
router.post('/', async (req, res) => { | ||
try { | ||
const id = await storage.saveQuestion(null, req.body) | ||
res.send(id) | ||
} catch (e) { | ||
logger.error('QnA Error', e, e.stack) | ||
res.status(500).send(e.message || 'Error') | ||
} | ||
}) | ||
|
||
router.put('/:question', async (req, res) => { | ||
try { | ||
await storage.saveQuestion(req.params.question, req.body) | ||
res.end() | ||
} catch (e) { | ||
logger.error('QnA Error', e, e.stack) | ||
res.status(500).send(e.message || 'Error') | ||
} | ||
}) | ||
|
||
router.delete('/:question', async (req, res) => { | ||
try { | ||
await storage.deleteQuestion(req.params.question) | ||
res.end() | ||
} catch (e) { | ||
logger.error('QnA Error', e, e.stack) | ||
res.status(500).send(e.message || 'Error') | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NLU_PREFIX } from './storage' | ||
|
||
export const processEvent = async (event, { storage, logger }) => { | ||
if (!event.nlu.intent || !event.nlu.intent.startsWith(NLU_PREFIX)) { | ||
return false | ||
} | ||
|
||
logger.debug('QnA: matched NLU intent', event.nlu.intent.name) | ||
const id = event.nlu.intent.name.substring(NLU_PREFIX.length) | ||
const { data } = await storage.getQuestion(id) | ||
// actually this shouldn't be the case as we delete intents | ||
// for disabled questions | ||
if (!data.enabled) { | ||
logger.debug('QnA: question disabled, skipping') | ||
return false | ||
} | ||
|
||
logger.debug('QnA: replying to recognized question', id) | ||
event.reply('#builtin_text', { text: data.answer }) | ||
// return `true` to prevent further middlewares from capturing the message | ||
return true | ||
} |
Oops, something went wrong.