我想创建一个树形的问答机器人,由hubot提供支持服务,但我还不能想出怎么做。我想让Hubot在有人进入房间(使用robot.enter)时提问,虽然这在Rocket.Chat上不起作用,但我找到了一个变通办法。但是,如果我想问一个问题,然后等待用户回复保存他们的回复,然后再问他们另一个问题,我该怎么做呢?
我甚至尝试过嵌套一个res.send,但它不允许我嵌套,这给了我一个CoffeeScript上的索引错误
发布于 2017-05-24 05:55:45
如果你想要一些预构建的东西,有几个框架脚本可以提供这个功能:
https://github.com/lmarkus/hubot-conversation https://www.npmjs.com/package/hubot-dynamic-conversation
hubot- JavaScripty更具动态性(讽刺的是,也更具动态性),而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)
)发布于 2017-05-18 18:07:50
根据https://github.com/github/hubot/blob/master/docs/scripting.md的说法,你可以直接使用:
robot.enter (res) -> res.send res.random enterReplies
(Res)->res.send res.random enterReplies
发布于 2021-09-07 02:41:48
不知道在这个问题上是否还有解决方案,因为TS在rocketchat中提到robot.enter不起作用。
https://stackoverflow.com/questions/43600466
复制相似问题