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
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)
)
According to https://github.com/github/hubot/blob/master/docs/scripting.md You can just use:
robot.enter (res) -> res.send res.random enterReplies
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.