Skip to content

Commit 7743d6e

Browse files
committed
add docs about webot.loads
1 parent cd2b62c commit 7743d6e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,40 @@ webot.set('domain-1 act-2', {
153153
So when `/some pattern/` and `/another pattern/` is matched, webot will run into the `domain-1` middleware first,
154154
to check whether user is logged in.
155155
156+
### webot.loads(file1, _[file2, ...]_)
157+
158+
载入 nodejs 模块作为 webot 的回复规则,以方便你在比较复杂的项目中组织文件。
159+
160+
file1, file2 是相对于调用此方法的文件所在目录的文件名。
161+
162+
163+
```javascript
164+
webot.loads('./rules/a', './rules.b');
165+
```
166+
167+
In file `./rules/a.js` and `./rules/b.js`:
168+
169+
```javascript
170+
module.exports = function(webot) {
171+
webot.set('rule_a', function(info, next) {
172+
// ...
173+
});
174+
webot.set('rule_a_1', 'some reply');
175+
};
176+
```
177+
178+
or use single Rule defination:
179+
180+
```
181+
module.exports = {
182+
pattern: /some pattern/,
183+
handler: function(info, next) {
184+
// ...
185+
},
186+
};
187+
```
188+
189+
156190
### webot.dialog(file1, _[file2, ...]_)
157191
158192
增加对话规则
@@ -195,7 +229,7 @@ In your `app.js`:
195229
```javascript
196230
require('js-yaml');
197231

198-
webot.dialog(__dirname__ + './rules/abc.yaml');
232+
webot.dialog('./rules/abc.yaml');
199233
```
200234
201235
In `rules/abc.yaml`:

0 commit comments

Comments
 (0)