【问题标题】:Hubot multiple messagesHubot 多条消息
【发布时间】:2019-05-30 12:28:30
【问题描述】:

我有以下脚本:

module.exports = (robot) ->

  robot.respond /petsit/i, (res) ->

    user_name = res.envelope.user.name
    res.reply "Starting new petsitting under: @" + user_name + "\n"
    res.send "What is the dog's name? Reply with 'dog `INSERT_DOG_NAME`'"

    robot.respond /dog (.*)/i, (msg) ->
      dog_name = msg.match[1]

      user_dog_name = "" + user_name + dog_name

      if robot.brain.get(user_dog_name)
        msg.send "Petsitting is already in progress for @" + user_name + " Dog: " + dog_name
      else
        robot.brain.set(user_app_name, true)
        msg.send "#{dog_name} " + robot.brain.get(user_app_name)

我很困惑为什么当我多次调用 petsit 时会收到多条消息?

例如:

@hubot petsit
@hubot dog lucky

@hubot petsit
@hubot dog kenny ---> This will give me multiple messages.

我的想法是这是异步的,第二条消息正在由第一条对话/对话运行?我该如何解决这个问题,以便第一次对话不会干扰后续对话?

【问题讨论】:

    标签: coffeescript slack hubot


    【解决方案1】:

    您会收到多条消息,因为每次调用 robot.respond /petsit/i 时都会附加 robot.respond /dog (.*)/i 侦听器。这是您第一次发送 petsit/dog (.*)/i 侦听器第一次被附加。当您发送 dog ... 时,只会触发一个响应。以后每次您发送 petsit 时,第二个侦听器都会将自己绑定到同一个 robot 实例上,从而向您发送多个响应。

    默认情况下,Hubot 不支持管理对话。相反,您应该看看像 hubot-conversation 这样的第 3 方模块 添加此类功能或实现您自己的逻辑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多