[英]Hubot nesting commands
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. 我想创建一个树形的问答机器人,由hubot提供支持服务,但我一直无法弄清楚该怎么做。 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.
我希望Hubot在有人进入房间(使用robot.enter)时问一个问题,尽管这不适用于Rocket.Chat,我发现了一种解决方法。 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 我尝试甚至嵌套一个res.send,但它不允许我这样做,给我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 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. hubot-conversation有点像JavaScript(讽刺的是,它有点动态),而hubot-dynamic-conversation围绕您构建会话流的JSON模型。
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. 如果您不喜欢这些选项中的任何一个,则始终可以使用混合使用robot.listen来动态地匹配消息,并使用大脑来跟踪状态来实现自己的流程。
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: 根据https://github.com/github/hubot/blob/master/docs/scripting.md的说明,您可以使用:
robot.enter (res) -> res.send res.random enterReplies
robot.enter(res)-> res.send res.random enterReplies
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.