node-webot / webot

An easy-to-use robot for web services.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.replies数据库获取实现

sang4lv opened this issue · comments

基于用户回复的二次回复是否能使用数据库查询这种异步的方法调用?
比如在.replies 1)获取用户再次回复的内容, 2) 有next函数?
或者在.handler可以管理多层回复?

在 replies 里面指定的 handler 是可以直接使用异步函数的,回复内容为空,就会从头开始运行所有规则

webot.set({
  pattern: /..../
  handler: function(info, next) {
     next(null, 'your reply');
  },
  replies: {
    'reply_1': function(info, next) {
        do_something(function(err, doc) {
           if (doc) {
             return next(null, 'some nice thing');
           }
           next();
        });
    }
 }
});

如果有更复杂的连续回复操作,不建议再用 rule.replies ,可以试一下更加扁平的 webot.waitRule 接口:

https://github.com/node-webot/webot-example/blob/master/rules/index.js#L280

好的,谢谢。还有就是replies里的内容(案例的‘reply_1’)是否也可以用类似方式获取?。replies和。waitRule的例子似乎都没有这种用法

rule.replies 其实就是一些特殊的 waitRule , webot.set 处理的时候会给他们一个名字,这个名字仅限内部使用,不保证以后命名规则会变。

如果需要使用 info.wait('wait_rule_name') ,不建议直接去找这个名字,最好显式调用 webot.waitRule 定义你的规则。