Skip to content

Commit

Permalink
Merge pull request #564 from codeforequity-at/develop
Browse files Browse the repository at this point in the history
Botium Core 1.9.11
  • Loading branch information
Botium authored Sep 12, 2020
2 parents f98a8c2 + 45b2195 commit c24e2fc
Show file tree
Hide file tree
Showing 81 changed files with 12,307 additions and 6,766 deletions.
4,872 changes: 2,898 additions & 1,974 deletions LICENSES-3RDPARTY.txt

Large diffs are not rendered by default.

2,849 changes: 1,605 additions & 1,244 deletions package-lock.json

Large diffs are not rendered by default.

33 changes: 15 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "botium-core",
"version": "1.9.10",
"version": "1.9.11",
"description": "The Selenium for Chatbots",
"main": "index.js",
"module": "dist/botium-es.js",
Expand Down Expand Up @@ -31,23 +31,21 @@
},
"homepage": "https://www.botium.ai",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@babel/runtime": "^7.11.2",
"async": "^3.2.0",
"body-parser": "^1.19.0",
"boolean": "^3.0.1",
"bottleneck": "^2.19.5",
"copy-dir": "^1.3.0",
"csv-parse": "^4.9.0",
"debug": "^4.1.1",
"esprima": "^4.0.1",
"express": "^4.17.1",
"find-root": "^1.1.0",
"glob": "^7.1.6",
"globby": "^11.0.1",
"ioredis": "^4.17.3",
"is-class": "^0.0.9",
"is-json": "^2.0.1",
"jsonpath": "^1.0.2",
"lodash": "^4.17.19",
"lodash": "^4.17.20",
"markdown-it": "^11.0.0",
"mime-types": "^2.1.27",
"mkdirp": "^1.0.4",
Expand All @@ -65,32 +63,31 @@
"socketio-auth": "^0.1.1",
"swagger-jsdoc": "^4.0.0",
"swagger-ui-express": "^4.1.4",
"tcp-port-used": "^1.0.1",
"uuid": "^8.3.0",
"write-yaml": "^1.0.0",
"xlsx": "^0.16.6",
"xlsx": "^0.16.7",
"xregexp": "^4.3.0",
"yaml": "^1.10.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/core": "^7.11.6",
"@babel/node": "^7.10.5",
"@babel/plugin-transform-runtime": "^7.11.5",
"@babel/preset-env": "^7.11.5",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint": "^7.8.1",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"license-checker": "^25.0.1",
"mocha": "^7.1.2",
"nock": "^12.0.3",
"nyc": "^15.0.1",
"rollup": "^2.7.3",
"mocha": "^8.1.3",
"nock": "^13.0.4",
"nyc": "^15.1.0",
"rollup": "^2.26.11",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
Expand Down
4 changes: 4 additions & 0 deletions samples/connectors/custom/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
To run this custom connector sample:

$ npm install
$ npm test
107 changes: 107 additions & 0 deletions samples/connectors/custom/botium-connector-myapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const SimpleRestContainer = require('botium-core/src/containers/plugins/SimpleRestContainer.js')
const CoreCapabilities = require('botium-core/src/Capabilities')

const Capabilities = {
MYAPI_URL: 'MYAPI_URL',
MYAPI_TOKEN: 'MYAPI_TOKEN'
}

class BotiumConnectorMyApi {
constructor ({ queueBotSays, caps }) {
this.queueBotSays = queueBotSays
this.caps = caps
this.delegateContainer = null
this.delegateCaps = null
this.userSaysCounter = 0
}

Validate () {
if (!this.caps[Capabilities.MYAPI_URL]) throw new Error('MYAPI_URL capability required')

if (!this.delegateContainer) {
this.delegateCaps = {
[CoreCapabilities.SIMPLEREST_URL]: this.caps[Capabilities.MYAPI_URL],
[CoreCapabilities.SIMPLEREST_METHOD]: 'POST',
[CoreCapabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.reply',
[CoreCapabilities.SIMPLEREST_BODY_TEMPLATE]: JSON.stringify({
username: 'botium',
message: '{{msg.messageText}}',
session: '{{botium.conversationId}}',
startsession: false,
quickreply: null
})
}
if (this.caps[Capabilities.MYAPI_TOKEN]) {
this.delegateCaps[CoreCapabilities.SIMPLEREST_HEADERS_TEMPLATE] = `{ "Authorization": "Token ${this.caps[Capabilities.MYAPI_TOKEN]}"}`
}

this.delegateCaps[CoreCapabilities.SIMPLEREST_REQUEST_HOOK] = ({ msg, requestOptions, context }) => {
if (this.userSaysCounter === 0) {
requestOptions.body.startsession = true
} else {
requestOptions.body.startsession = false
}
if (msg.buttons && msg.buttons.length > 0) {
delete requestOptions.body.message
requestOptions.body.quickreply = msg.buttons[0].payload || msg.buttons[0].text
}
}
this.delegateCaps[CoreCapabilities.SIMPLEREST_RESPONSE_HOOK] = ({ botMsg, botMsgRoot }) => {
if (botMsgRoot.status === 'error') throw new Error(`MyAPI Error: ${botMsgRoot.message}`)

if (botMsgRoot.quickreplies && botMsgRoot.quickreplies.length > 0) {
botMsg.buttons = botMsgRoot.quickreplies.map(b => ({ text: b.title, payload: b.value }))
}
}

this.delegateCaps = Object.assign({}, this.caps, this.delegateCaps)
this.delegateContainer = new SimpleRestContainer({ queueBotSays: this.queueBotSays, caps: this.delegateCaps })
}
return this.delegateContainer.Validate()
}

async Build () {
await this.delegateContainer.Build()
}

async Start () {
this.userSaysCounter = 0
await this.delegateContainer.Start()
}

async UserSays (msg) {
await this.delegateContainer.UserSays(msg)
this.userSaysCounter++
}

async Stop () {
await this.delegateContainer.Stop()
}

async Clean () {
await this.delegateContainer.Clean()
}
}

module.exports = {
PluginVersion: 1,
PluginClass: BotiumConnectorMyApi,
PluginDesc: {
name: 'My API',
provider: 'Me',
capabilities: [
{
name: 'MYAPI_URL',
label: 'MyAPI Endpoint',
type: 'url',
required: true
},
{
name: 'MYAPI_TOKEN',
label: 'MyAPI Authorization Token',
type: 'secret',
required: false
}
]
}
}
9 changes: 9 additions & 0 deletions samples/connectors/custom/botium.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"botium": {
"Capabilities": {
"PROJECTNAME": "Custom Connector Sample",
"CONTAINERMODE": "./botium-connector-myapi.js",
"MYAPI_URL": "https://demo.botiumbox.com/iambotium/reply"
}
}
}
Loading

0 comments on commit c24e2fc

Please sign in to comment.