【问题标题】:Hubot nesting commandsHubot 嵌套命令
【发布时间】:2017-09-21 20:46:24
【问题描述】:

我想创建一个树形问答机器人,hubot 提供支持服务,但我不知道如何做。我希望 Hubot 在有人进入房间时问一个问题(使用 robots.enter),尽管这不适用于 Rocket.Chat,但我找到了一种解决方法。但是如果我想问一个问题并等待用户回复以保存他们的回复并问他们另一个问题,我该怎么做呢?

我什至尝试嵌套 res.send,但它不允许我,在 CoffeeScript 上给我一个索引错误

【问题讨论】:

    标签: javascript coffeescript nested hubot rocket.chat


    【解决方案1】:

    根据https://github.com/github/hubot/blob/master/docs/scripting.md 您可以使用:

    robot.enter (res) -> res.send res.random enterReplies

    【讨论】:

    • 不幸的是 Rocket.chat,robot.enter 不起作用。这就是我所说的,我最初也尝试过
    【解决方案2】:

    如果您想要预构建的东西,有几个框架脚本可以提供此功能:

    https://github.com/lmarkus/hubot-conversation https://www.npmjs.com/package/hubot-dynamic-conversation

    hubot-conversation 更加 JavaScript (讽刺的是,更加动态),而 hubot-dynamic-conversation 围绕您构建会话流的 JSON 模型。

    如果您不喜欢这两个选项中的任何一个,您始终可以使用混合使用 robots.listen 来动态匹配消息和大脑来跟踪状态来实现自己的流程。

    示例(我没有实际测试过,但应该给出正确的想法):

    module.exports = (robot) ->
      robot.respond /hello$/, (res) ->
        res.reply 'Why hello there! How are you today?'
        # Record that we are mid-conversation
        convs = robot.brain.get('conversations')
        convs = convs.push(message.user.name)
        robot.brain.set('conversations', convs)
    
      robot.listen(
        # If we are mid-conversation, respond to whatever they say next
        (message) -> message.user.name in robot.brain.get('conversations')
        (response) ->
          response.reply 'I hope you have a great rest of the day!'
          # Record that we are done conversing
          convs = robot.brain.get('conversations')
          convs = convs.splice(convs.indexOf(message.user.name), 1)
          robot.brain.set('conversations', convs)
      )
    

    【讨论】:

    • 这里的Hubot大脑肯定是处理这个问题的方法
    【解决方案3】:

    不知道是否还有解决方案,因为TS提到rocketchat中的robot.enter不起作用。

    【讨论】:

    • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 2014-04-05
    • 1970-01-01
    • 2010-12-24
    相关资源
    最近更新 更多