Skip to content

Commit 3d71d43

Browse files
authored
Merge pull request #49 from yeuai/dev-typo
Dev typo
2 parents 7be3d6d + 7c29951 commit 3d71d43

10 files changed

Lines changed: 57 additions & 36 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To define a list of items, just enter item in a new line which started with symb
4646

4747
## comment
4848

49-
Comments make your code clearer, you can add a comment in BotScript document by add symbol `#` at the begining of a line:
49+
Comments make your code clearer, you can add a comment in BotScript document by starting the symbol `#` at the begining of a line or followed by a space:
5050

5151
```bash
5252
# here is a comment

examples/register.bot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@ register_account post https://botscript.ai/api/account/register
1+
@ register_account post /api/account/register
22

33
! yesno
44
- yes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yeuai/botscript",
3-
"version": "1.5.2",
3+
"version": "1.5.3",
44
"description": "A text-based scripting language and bot engine for Conversational User Interfaces (CUI)",
55
"main": "dist/engine",
66
"scripts": {

src/engine/botscript.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export class BotScript extends EventEmitter {
122122
.replace(/\n +/g, '\n')
123123
// remove comments
124124
.replace(/^#.*$\n/igm, '')
125+
// remove inline comment
126+
.replace(/# .*$\n/igm, '')
125127
// separate definition struct (normalize)
126128
.replace(/^!/gm, '\n!')
127129
// concat multiple lines (normalize)
@@ -370,7 +372,7 @@ export class BotScript extends EventEmitter {
370372
return false;
371373
}
372374
const vTestResult = utils.evaluate(x.expr, req.variables);
373-
this.logger.info(`Evaluate test: ${vTestResult}|`, x.type, x.expr, x.value);
375+
this.logger.info(`Evaluate test: ${vTestResult} is ${!!vTestResult}|`, x.type, x.expr, x.value);
374376
return vTestResult;
375377
});
376378

src/lib/regex.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const REGEX_HEADER_SEPARATOR = / *: */;
2+
const REGEX_IP = /^(([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])(\.(?!$)|(?=$))){4}$/;
3+
4+
export {
5+
REGEX_IP,
6+
REGEX_HEADER_SEPARATOR,
7+
};

src/lib/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Struct, Request } from '../common';
44
import { TestConditionalCallback, Types } from '../interfaces/types';
55
import { Logger } from './logger';
66
import { interpolate } from './template';
7+
import { REGEX_HEADER_SEPARATOR } from './regex';
78

89
const logger = new Logger('Utils');
910

@@ -91,7 +92,9 @@ export function evaluate(code: string, context: any) {
9192
*/
9293
export function callHttpService(command: Struct, req: Request) {
9394
const vIsGetMethod = /^get$/i.test(command.options[0]);
94-
const headers = command.body.map(x => x.split(':'));
95+
const headers = command.body
96+
.filter(x => x.split(REGEX_HEADER_SEPARATOR).length === 2)
97+
.map(x => x.split(REGEX_HEADER_SEPARATOR).map(kv => kv.trim()));
9598
const method = vIsGetMethod ? 'GET' : 'POST';
9699
const url = interpolate(command.options[1], req.variables);
97100
const body = vIsGetMethod ? undefined : req.variables;

test/e2e/delay.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
import axios from 'axios';
2+
import MockAdapter from 'axios-mock-adapter';
3+
4+
// Setup axios interceptors
5+
const mock = new MockAdapter(axios);
6+
// Mock specific requests, but let unmatched ones through
7+
mock
8+
.onPost('/api/account/register').reply(200, {
9+
reg_result_message: 'ok',
10+
})
11+
.onGet('/api/nlu').reply(200, {
12+
intent: 'who',
13+
entities: [{ id: 1, name: 'John Smith' }],
14+
})
15+
.onGet('/api/nlu/react').reply(200, {
16+
intent: 'react_positive',
17+
entities: [{ id: 1, name: 'John Smith' }],
18+
})
19+
.onGet('/api/data/list').reply(200, {
20+
people: [{
21+
name: 'Vũ',
22+
age: 30,
23+
}, {
24+
name: 'Toàn',
25+
age: 20,
26+
}, {
27+
name: 'Cường',
28+
age: 25,
29+
},
30+
],
31+
})
32+
.onAny().passThrough();
33+
134
/**
235
* sleep utils
336
* @param m

test/e2e/register-bot.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ describe('Register.bot (e2e)', async () => {
2525
expect(req.speechResponse).match(/xác nhn thông tin/i);
2626
await bot.handleAsync(req.enter('yes'));
2727

28-
expect(req.speechResponse).match(/đăng ký thành công/i);
28+
const {reg_username, reg_result_message} = req.variables;
29+
const vResult = `Bạn đã đăng ký thành công, tài khoản ${reg_username}: ok!`;
30+
31+
expect(reg_result_message).match(/ok/);
32+
expect(req.speechResponse).eq(vResult);
2933
bot.logger.info('Chi tiết tài khoản: ', req.variables);
3034
});
3135

test/engine/conditions.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BotScript, Request } from '../../src/engine';
2+
import { REGEX_IP } from '../../src/lib/regex';
23
import { assert } from 'chai';
34

45
describe('BotScript: Conditional dialogue', () => {
@@ -170,7 +171,7 @@ describe('BotScript: Conditional dialogue', () => {
170171
const req = new Request('what is my ip');
171172
await condBot.handleAsync(req);
172173
assert.match(req.speechResponse, /here is your ip/i, 'bot reply');
173-
assert.match(req.variables.ip, /^(([1-9]?\d|1\d\d|2[0-4]\d|25[0-5])(\.(?!$)|(?=$))){4}$/, 'match ip');
174+
assert.match(req.variables.ip, REGEX_IP, 'match ip');
174175
});
175176

176177
it('should handle conditional redirect', async () => {

test/features/directive.spec.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
import { assert } from 'chai';
22
import { BotScript, Request } from '../../src/engine';
3-
import axios from 'axios';
4-
import MockAdapter from 'axios-mock-adapter';
5-
6-
const mock = new MockAdapter(axios);
7-
// Mock specific requests, but let unmatched ones through
8-
mock
9-
.onGet('/api/nlu').reply(200, {
10-
intent: 'who',
11-
entities: [{ id: 1, name: 'John Smith' }],
12-
})
13-
.onGet('/api/nlu/react').reply(200, {
14-
intent: 'react_positive',
15-
entities: [{ id: 1, name: 'John Smith' }],
16-
})
17-
.onGet('/api/data/list').reply(200, {
18-
people: [{
19-
name: 'Vũ',
20-
age: 30,
21-
}, {
22-
name: 'Toàn',
23-
age: 20,
24-
}, {
25-
name: 'Cường',
26-
age: 25,
27-
},
28-
],
29-
})
30-
.onAny()
31-
.passThrough();
323

334
describe('Feature: Directive', () => {
345

0 commit comments

Comments
 (0)