Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): created @botpress/util-sdk to help develop modules
- Loading branch information
1 parent
9157849
commit 96d30a3
Showing
8 changed files
with
4,027 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"node": "6.10" | ||
} | ||
}] | ||
], | ||
"plugins": ["transform-object-rest-spread", "transform-export-extensions"] | ||
} |
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 @@ | ||
.npmignore | ||
src |
Empty file.
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,32 @@ | ||
{ | ||
"name": "@botpress/util-sdk", | ||
"version": "10.8.0", | ||
"description": "The built-in stuff such as Content Elements, Content Renderers and Actions for Botpress X+", | ||
"main": "./dist/index.js", | ||
"repository": "https://github.com/botpress/botpress", | ||
"author": "Botpress, Inc.", | ||
"license": "AGPL-3.0", | ||
"private": false, | ||
"scripts": { | ||
"watch": "babel src --out-dir dist --source-maps --watch", | ||
"compile": "babel src --out-dir dist --source-maps", | ||
"test": "jest --watch" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-plugin-transform-export-extensions": "^6.22.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"jest": "^22.4.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.5.1", | ||
"joi": "^13.3.0", | ||
"lodash": "^4.17.10", | ||
"mime": "^2.3.1", | ||
"moment": "^2.22.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 @@ | ||
export * as Skill from './skill' |
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 @@ | ||
test('Skills', () => { | ||
// expect(obj).toBe(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import _ from 'lodash' | ||
|
||
const genId = () => | ||
Math.random() | ||
.toString() | ||
.substr(2, 6) | ||
|
||
const _renderElement = (type, args) => { | ||
if (_.isString(args)) { | ||
return `say ${type} ${args}` | ||
} else { | ||
return `say ${type} ${JSON.stringify(args)}` | ||
} | ||
} | ||
|
||
export function Flow(config) { | ||
const obj = { ...config } | ||
|
||
if (!obj.version) { | ||
obj.version = '0.0' | ||
} | ||
|
||
if (!obj.name || !obj.location) { | ||
obj.name = obj.location = genId() | ||
} | ||
|
||
if (!obj.startNode) { | ||
if (!obj.nodes || obj.nodes.length <= 0) { | ||
throw new Error('Expected at least one node in `nodes`') | ||
} | ||
|
||
if (!obj.nodes.filter(n => n.name === 'entry').length) { | ||
obj.startNode = obj.nodes[0].name | ||
} | ||
|
||
obj.startNode = 'entry' | ||
} | ||
|
||
return obj | ||
} | ||
|
||
export function Node(config) { | ||
const obj = { ...config } | ||
|
||
if (!obj.id) { | ||
obj.id = genId() | ||
} | ||
|
||
if (!obj.onEnter) { | ||
obj.onEnter = [] | ||
} | ||
|
||
if (!obj.onReceive) { | ||
obj.onReceive = null | ||
} | ||
|
||
if (!obj.next) { | ||
obj.next = [] | ||
} | ||
|
||
return obj | ||
} | ||
|
||
export function renderElement(...args) { | ||
if (args.length === 1) { | ||
return _renderElement('#text', args[0]) | ||
} else if (args.length === 2) { | ||
return _renderElement(args[0], args[1]) | ||
} else { | ||
throw new Error('Can only call say with one or two args') | ||
} | ||
} | ||
|
||
export function runAction(name, args) { | ||
return args ? `${name} ${JSON.stringify(args)}` : name | ||
} |
Oops, something went wrong.