File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ A node.js robot for wechat.
14141 . 方便灵活的规则定义,轻松实现文本匹配流程控制
15152 . 基于正则表达式的对话设定,配置简单,可以给一句话随机回复不同内容
16163 . 支持等待后续操作模式,如可以提示用户“需要我执行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// 接管消息请求
4871webot .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
107137webot rule 的 handler 接收到的 info 对象,包含请求消息内容和 session 支持。
You can’t perform that action at this time.
0 commit comments