我想创建一个树形问答机器人,hubot 提供支持服务,但我不知道如何做。我希望 Hubot 在有人进入房间时问一个问题(使用 robots.enter),尽管这不适用于 Rocket.Chat,但我找到了一种解决方法。但是如果我想问一个问题并等待用户回复以保存他们的回复并问他们另一个问题,我该怎么做呢?
我什至尝试嵌套 res.send 但它不允许我,在 CoffeeScript 上给我一个索引错误
我想创建一个树形问答机器人,hubot 提供支持服务,但我不知道如何做。我希望 Hubot 在有人进入房间时问一个问题(使用 robots.enter),尽管这不适用于 Rocket.Chat,但我找到了一种解决方法。但是如果我想问一个问题并等待用户回复以保存他们的回复并问他们另一个问题,我该怎么做呢?
我什至尝试嵌套 res.send 但它不允许我,在 CoffeeScript 上给我一个索引错误
如果您想要预构建的东西,有几个框架脚本可以提供此功能:
https://github.com/lmarkus/hubot-conversation https://www.npmjs.com/package/hubot-dynamic-conversation
hubot-conversation 更加 JavaScripty(具有讽刺意味的是,更加动态),而 hubot-dynamic-conversation 以您构建会话流的 JSON 模型为中心。
如果您不喜欢这些选项中的任何一个,您始终可以使用混合使用 robots.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)
)
不知道是否还有解决方案,因为TS提到rocketchat中的robot.enter不起作用。
根据https://github.com/github/hubot/blob/master/docs/scripting.md 你可以使用:
robots.enter (res) -> res.send res.random enterReplies