簡體   English   中英

Hubot嵌套命令

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM