0

I want to create a tree-style question and answer bot with hubot doing support services and I haven't been able to figure out how. I wanted Hubot to ask a question upon someone entering the room (with robot.enter) though that doesn't work with Rocket.Chat, I've found a workaround. But if I want to ask a question and wait for a user to reply to save their reply and ask them another question, how would I go about doing this?

I tried nesting even a res.send and it wouldn't allow me, giving me an index error on CoffeeScript

asegier
  • 55
  • 5

3 Answers3

1

If you want something prebuilt, there are a couple framework scripts that provide this capability:

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

hubot-conversation is a little more JavaScripty (and ironically, a little more dynamic), whereas hubot-dynamic-conversation centers around you building a JSON model of the conversation flow.

If you don't like either of those options, you can always implement your own flow using a mixture of robot.listen to dynamically match messages and the brain to track state.

Example (that I haven't actually tested, but should give the right idea):

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)
  )
0

According to https://github.com/github/hubot/blob/master/docs/scripting.md You can just use:

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

boaz shor
  • 299
  • 1
  • 3
  • 16
  • Unfortunately with Rocket.chat, robot.enter does not work. It's what I stated I tried as well originally – asegier May 22 '17 at 11:35
0

don't know whether still have solution on this, since TS mention robot.enter in rocketchat does not work.

wmk92
  • 1
  • 1
  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 07 '21 at 05:15