Skip to content

Commit 174ed4c

Browse files
committed
update doc about async handler
1 parent 2bec54b commit 174ed4c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ A node.js robot for wechat.
1414
1. 方便灵活的规则定义,轻松实现文本匹配流程控制
1515
2. 基于正则表达式的对话设定,配置简单,可以给一句话随机回复不同内容
1616
3. 支持等待后续操作模式,如可以提示用户“需要我执行xxx操作吗?”
17+
4. 可直接从 yaml 或 json 文件中载入对话规则
1718

1819
## 使用示例:
1920

@@ -44,6 +45,28 @@ webot.set('subscribe', {
4445
}
4546
});
4647

48+
webot.set('test', {
49+
pattern: /^test/i,
50+
handler: function(info, next) {
51+
next(null, 'roger that!')
52+
}
53+
})
54+
55+
// 你可以获取已定义的 rule
56+
//
57+
// webot.get('subscribe') ->
58+
//
59+
// {
60+
// name: 'subscribe',
61+
// pattern: function(info) {
62+
// return info.is('event') && info.param.event === 'subscribe';
63+
// },
64+
// handler: function(info) {
65+
// return '欢迎订阅微信机器人';
66+
// }
67+
// }
68+
//
69+
4770
// 接管消息请求
4871
webot.watch(app, { token: 'your1weixin2token', path: '/wechat' });
4972

@@ -99,9 +122,16 @@ app.listen(80);
99122

100123
![Wechat API flow](https://github.com/node-webot/weixin-robot/blob/master/wechat-api-flow.png?raw=true)
101124

125+
## 规则定义
102126

103127
> 具体的规则定义部分,请参考 [webot](https://github.com/node-webot/webot) 的文档。
104128

129+
主要API:
130+
131+
- [webot.set()](https://github.com/node-webot/webot#webotsetpattern-handler--replies)
132+
- [webot.waitRule()](https://github.com/node-webot/webot#webotwaitrulename-handler)
133+
- [webot.loads()](https://github.com/node-webot/webot#webotloadsfile1-file2-)
134+
105135
## info 对象
106136

107137
webot rule 的 handler 接收到的 info 对象,包含请求消息内容和 session 支持。

0 commit comments

Comments
 (0)