Skip to content

Commit

Permalink
Merge pull request #661 from codeforequity-at/develop
Browse files Browse the repository at this point in the history
Botium Core 1.12.0
  • Loading branch information
Botium authored Dec 17, 2021
2 parents 33f1da7 + 50fe66d commit 7643f98
Show file tree
Hide file tree
Showing 10 changed files with 865 additions and 760 deletions.
1,488 changes: 763 additions & 725 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "botium-core",
"version": "1.11.16",
"version": "1.12.0",
"description": "The Selenium for Chatbots",
"main": "index.js",
"module": "dist/botium-es.js",
"engines": {
"node": ">=10.0.0"
"node": ">=14.0.0"
},
"scripts": {
"postinstall": "node ./report.js",
Expand All @@ -32,23 +32,23 @@
},
"homepage": "https://www.botium.ai",
"dependencies": {
"@babel/runtime": "^7.16.0",
"@babel/runtime": "^7.16.5",
"async": "^3.2.2",
"body-parser": "^1.19.0",
"body-parser": "^1.19.1",
"boolean": "^3.1.4",
"bottleneck": "^2.19.5",
"csv-parse": "^4.16.3",
"debug": "^4.3.2",
"csv-parse": "^5.0.3",
"debug": "^4.3.3",
"esprima": "^4.0.1",
"express": "^4.17.1",
"express": "^4.17.2",
"globby": "11.0.4",
"ioredis": "^4.28.0",
"ioredis": "^4.28.2",
"is-class": "^0.0.9",
"is-json": "^2.0.1",
"jsonpath": "^1.1.1",
"lodash": "^4.17.21",
"markdown-it": "^12.2.0",
"mime-types": "^2.1.33",
"markdown-it": "^12.3.0",
"mime-types": "^2.1.34",
"mkdirp": "^1.0.4",
"moment": "^2.29.1",
"mustache": "^4.2.0",
Expand All @@ -58,40 +58,40 @@
"request": "^2.88.2",
"rimraf": "^3.0.2",
"sanitize-filename": "^1.6.3",
"slugify": "^1.6.1",
"socket.io": "^4.3.1",
"socket.io-client": "^4.3.2",
"slugify": "^1.6.4",
"socket.io": "^4.4.0",
"socket.io-client": "^4.4.0",
"socketio-auth": "^0.1.1",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.1.6",
"swagger-ui-express": "^4.3.0",
"uuid": "^8.3.2",
"vm2": "^3.9.5",
"write-yaml": "^1.0.0",
"xlsx": "^0.17.3",
"xlsx": "^0.17.4",
"xregexp": "^5.1.0",
"yaml": "^1.10.2"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/node": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/core": "^7.16.5",
"@babel/node": "^7.16.5",
"@babel/plugin-transform-runtime": "^7.16.5",
"@babel/preset-env": "^7.16.5",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.1.0",
"eslint": "^8.4.1",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.1",
"eslint-plugin-promise": "^5.2.0",
"eslint-plugin-standard": "^4.1.0",
"license-checker": "^25.0.1",
"license-compatibility-checker": "^0.3.5",
"mocha": "^9.1.3",
"nock": "^13.1.4",
"npm-check-updates": "^12.0.0",
"nock": "^13.2.1",
"npm-check-updates": "^12.0.5",
"nyc": "^15.1.0",
"rollup": "^2.59.0",
"rollup": "^2.61.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
Expand Down
6 changes: 3 additions & 3 deletions samples/connectors/custom/botium-connector-myapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class BotiumConnectorMyApi {
[CoreCapabilities.SIMPLEREST_URL]: this.caps[Capabilities.MYAPI_URL],
[CoreCapabilities.SIMPLEREST_METHOD]: 'POST',
[CoreCapabilities.SIMPLEREST_RESPONSE_JSONPATH]: '$.reply',
[CoreCapabilities.SIMPLEREST_BODY_TEMPLATE]: JSON.stringify({
[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]}"}`
Expand Down Expand Up @@ -104,4 +104,4 @@ module.exports = {
}
]
}
}
}
6 changes: 3 additions & 3 deletions samples/extensions/asserterHooks/DummyAsserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ module.exports = class DummyAsserter {
this.caps = caps
}

assertConvoBegin ({convo, container, args}) {
assertConvoBegin ({ convo, container, args }) {
console.log(`Dummy asserter Begin started with those args: ${utils.inspect(args)}`)
return Promise.resolve()
}

assertConvoStep ({convo, convoStep, args, botMsg}) {
assertConvoStep ({ convo, convoStep, args, botMsg }) {
console.log(`ConvoStep dummy assertion with those args: ${utils.inspect(args)}, botMessage: ${utils.inspect(botMsg)} ...`)
return Promise.resolve()
}

assertConvoEnd ({convo, container, transcript, args}) {
assertConvoEnd ({ convo, container, transcript, args }) {
console.log(`ConvoEnd dummy assertion with those args: ${utils.inspect(args)}, transcript: ${utils.inspect(transcript)} ...`)
return Promise.resolve()
}
Expand Down
19 changes: 19 additions & 0 deletions src/containers/plugins/SimpleRestContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Defaults = require('../../Defaults').Capabilities
const { SCRIPTING_FUNCTIONS } = require('../../scripting/ScriptingMemory')
const { getHook, executeHook } = require('../../helpers/HookUtils')
const { escapeJSONString } = require('../../helpers/Utils')
const { BotiumError } = require('../../scripting/BotiumError')

Mustache.escape = s => s

Expand Down Expand Up @@ -387,6 +388,15 @@ module.exports = class SimpleRestContainer {
if (debug.enabled && body) {
debug(botiumUtils.shortenJsonString(body))
}
if (body) {
const jsonBody = botiumUtils.toJsonWeak(body)
const errKey = Object.keys(jsonBody).find(k => k.startsWith('err') || k.startsWith('fail'))
if (errKey) {
return reject(new BotiumError(`got error response: ${response.statusCode}/${response.statusMessage} - ${jsonBody[errKey]}`, {
message: botiumUtils.shortenJsonString(body)
}))
}
}
return reject(new Error(`got error response: ${response.statusCode}/${response.statusMessage}`))
}

Expand Down Expand Up @@ -478,6 +488,15 @@ module.exports = class SimpleRestContainer {
requestOptions.uri = `${requestOptions.uri}?${appendToUri}`
}
}
if (msg.ADD_FORM_PARAM && Object.keys(msg.ADD_FORM_PARAM).length > 0) {
requestOptions.form = {}
for (const formKey of Object.keys(msg.ADD_FORM_PARAM)) {
const formValue = this._getMustachedVal(
_.isString(msg.ADD_FORM_PARAM[formKey]) ? msg.ADD_FORM_PARAM[formKey] : JSON.stringify(msg.ADD_FORM_PARAM[formKey]),
false)
requestOptions.form[formKey] = formValue
}
}
if (msg.ADD_HEADER && Object.keys(msg.ADD_HEADER).length > 0) {
requestOptions.headers = requestOptions.headers || {}

Expand Down
2 changes: 1 addition & 1 deletion src/scripting/CompilerCsv.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const parse = require('csv-parse/lib/sync')
const { parse } = require('csv-parse/sync')
const _ = require('lodash')
const debug = require('debug')('botium-core-CompilerCsv')

Expand Down
2 changes: 2 additions & 0 deletions src/scripting/logichook/LogicHookUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ module.exports = class LogicHookUtils {
return CheckClass({ ref, ...this.buildScriptContext }, this.caps, args)
} else if (isClass(CheckClass.PluginClass)) {
return new CheckClass.PluginClass({ ref, ...this.buildScriptContext }, this.caps, args)
} else if (_.isFunction(CheckClass.PluginClass)) {
return CheckClass.PluginClass({ ref, ...this.buildScriptContext }, this.caps, args)
} else {
throw new Error(`${src} class or function expected`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/logichook/asserter/JsonPathAsserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module.exports = class JsonPathAsserter {
}
},
cause: {
expected: assert || (args && `any element for ${args.join('|')}`) || (!args && `any element in ${path}`),
expected: assert || ((args && args.length > 0) && `any element for ${args.join('|')}`) || ((!args || args.length === 0) && `any element in ${path}`),
actual: null,
path
}
Expand Down
6 changes: 6 additions & 0 deletions test/connectors/convos/hello.convo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hello

#me
hello

#bot
44 changes: 42 additions & 2 deletions test/connectors/simplerest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const myCapsPost = {
[Capabilities.SIMPLEREST_BODY_TEMPLATE]: { BODY1: 'BODY1VALUE', BODY2: '{{msg.messageText}}' },
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$']
}
const myCapsFormPost = {
[Capabilities.CONTAINERMODE]: 'simplerest',
[Capabilities.SIMPLEREST_URL]: 'http://my-host.com/api/endpoint/{{msg.messageText}}',
[Capabilities.SIMPLEREST_METHOD]: 'POST',
[Capabilities.SIMPLEREST_RESPONSE_JSONPATH]: ['$']
}

const myCapsScriptingMemory = {
[Capabilities.CONTAINERMODE]: 'simplerest',
Expand Down Expand Up @@ -448,7 +454,7 @@ describe('connectors.simplerest.build', function () {
assert.isTrue(err.message.includes('Cant load hook, syntax is not valid'))
}
})
it('should query params from UPDATE_CUSTOM (without "?")', async function () {
it('should add query params from UPDATE_CUSTOM (without "?")', async function () {
const myCaps = Object.assign({}, myCapsGet)
const myMsg = Object.assign({}, msg)
myMsg.ADD_QUERY_PARAM = {
Expand All @@ -467,7 +473,7 @@ describe('connectors.simplerest.build', function () {

await container.Clean()
})
it('should query params from UPDATE_CUSTOM (with "?")', async function () {
it('should add query params from UPDATE_CUSTOM (with "?")', async function () {
const myCaps = Object.assign({}, myCapsGet)
myCaps.SIMPLEREST_URL = 'http://my-host.com/api/endpoint/messageText?const1=const1'
const myMsg = Object.assign({}, msg)
Expand Down Expand Up @@ -510,6 +516,26 @@ describe('connectors.simplerest.build', function () {

await container.Clean()
})
it('should add form params from UPDATE_CUSTOM (without "?")', async function () {
const myCaps = Object.assign({}, myCapsFormPost)
const myMsg = Object.assign({}, msg)
myMsg.ADD_FORM_PARAM = {
formparam1: 'valueparam1',
formparam2: '{{msg.messageText}}'
}

const driver = new BotDriver(myCaps)
const container = await driver.Build()
assert.equal(container.pluginInstance.constructor.name, 'SimpleRestContainer')

await container.Start()
const request = await container.pluginInstance._buildRequest(myMsg)
assert.isObject(request.form)
assert.equal(request.form.formparam1, 'valueparam1')
assert.equal(request.form.formparam2, 'messageText')

await container.Clean()
})
it('should add header from UPDATE_CUSTOM', async function () {
const myCaps = Object.assign({}, myCapsGet)
const myMsg = Object.assign({}, msg)
Expand Down Expand Up @@ -789,6 +815,7 @@ describe('connectors.simplerest.useresponse', function () {
.get('/startencoded').reply(200, { text: JSON.stringify({ prop: 'response from start' }) })
.get('/startstring').reply(200, 'response from start')
.get('/msg').reply(200, { text: 'response from msg' })
.get('/msgfail').reply(400, { error: 'failure text' })
.persist()

const myCaps = Object.assign({
Expand Down Expand Up @@ -914,6 +941,19 @@ describe('connectors.simplerest.useresponse', function () {
assert.equal(transcript.steps.length, 1)
assert.equal(transcript.steps[0].actual.messageText, 'response from start')
})

it('should use error body content', async function () {
await this.init({
[Capabilities.SIMPLEREST_URL]: 'https://mock.com/msgfail'
})

this.compiler.ReadScript(path.resolve(__dirname, 'convos'), 'hello.convo.txt')
try {
await this.compiler.convos[0].Run(this.container)
} catch (err) {
assert.isTrue(err.message.indexOf('failure text') >= 0)
}
})
})

describe('connectors.simplerest.inbound', function () {
Expand Down

0 comments on commit 7643f98

Please sign in to comment.