首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hubot嵌套命令

Hubot嵌套命令
EN

Stack Overflow用户
提问于 2017-04-25 10:12:37
回答 3查看 812关注 0票数 0

我想创建一个树形的问答机器人,由hubot提供支持服务,但我还不能想出怎么做。我想让Hubot在有人进入房间(使用robot.enter)时提问,虽然这在Rocket.Chat上不起作用,但我找到了一个变通办法。但是,如果我想问一个问题,然后等待用户回复保存他们的回复,然后再问他们另一个问题,我该怎么做呢?

我甚至尝试过嵌套一个res.send,但它不允许我嵌套,这给了我一个CoffeeScript上的索引错误

EN

回答 3

Stack Overflow用户

发布于 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来动态匹配消息和大脑来跟踪状态来实现自己的流。

示例(我还没有实际测试过,但应该给出正确的想法):

代码语言:javascript
复制
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)
  )
票数 1
EN

Stack Overflow用户

发布于 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

票数 0
EN

Stack Overflow用户

发布于 2021-09-07 02:41:48

不知道在这个问题上是否还有解决方案,因为TS在rocketchat中提到robot.enter不起作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43600466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档