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