2016-07-25 84 views
1

主要试图检查我是否有可能尝试做,因为我一直努力在网上找到任何类似的例子。hubot是否具有与botkit的对话功能类似的功能/解决方法? (&使hubot忘记响应)

我想创建一系列使用hubot框架的菜单,以便不必记忆单个命令和值。相反,您只需在开始时输入一个命令,并将相关信息提供一次,以便将这些值存储在菜单后多次使用。

事情是这样的:

robot.hear /blah/i, id:'start', (msg) -> 
    currentPosition = 'start' 
    msg.send "Please select an Option" 
    selectOption msg 

selectOption = (msg) -> 
    currentPosition = 'selectOption' 
    msg.send "Option 1" 
    msg.send "Option 2" 
    robot.hear /(.*)/i, id:'selectOption', (msg) -> 
    displayOption1 msg if msg.match is '1' 
    displayOption2 msg if msg.match is '2' 

displayOption1 = (msg) -> 
    currentPosition = 'displayOption1' 
    msg.send "Please enter some information" 
    robot.hear /(.*)/i, id: 'displayOption1', (msg) -> 
    # if information is entered do something with information 
    # pass the information onto another method etc... 

# .... 
# methods to do something with information and feedback results 
# .... 

# .... 
# methods corresponding to option 2 
# .... 

# .... 
# methods to do something with information and feedback results 
# .... 

end = (msg) -> 
    currentPosition = 'none' 
    msg.send "Thank you for using our service" 

我一直在使用监听器中间件,以确保您不能访问的命令菜单的出来:

robot.listenerMiddleware (context, next, done) -> 
    listenerID = context.listener.options?.id 
    return unless listenerID? 

    try 
    if listenerID is 'start' 
     if currentPosition is 'none' 
     next() 
     else 
     done() 

    if listenerID is 'selectOption' 
     if currentPosition is 'selectOption' 
     next() 
     # etc... 

    # Other similar examples to above for every "menu" ... 

    catch err 
    robot.emit ('error', err, context.response)  

一切似乎都如预期的首次合作我浏览菜单,但是如果我尝试第二次从头开始启动,问题就会出现。值似乎被记住,即使我在我的方法的开始或结束时将它们设置为null。当我接近尾声时,它会开始打印两次。

我认为这是因为值被缓存/存储在其他地方,我需要重置它。我还假设它打印两次的原因是因为hubot记得我已经通过菜单一次,并且有两个实例同时运行(如果我经历第三次,它将开始打印三次)。然而,它似乎只是为了达到目的,并且会按照预期为前几种方法打印出来。

简单地说,有没有办法让hubot在“最终”方法中忘记一切,这样它就像我每次第一次运行它一样运行?我研究过这个,但是像robot.shutdown这样的东西似乎不起作用。

如果上述不可行,是否有解决方法?

编辑:如果它在所有帮助,我试图做类似的东西,以botkit的谈话特点:https://github.com/howdyai/botkit#multi-message-replies-to-incoming-messages

回答

1

我被链接到该对我的线程在GitHub上问同样的问题:

https://github.com/lmarkus/hubot-conversation

当前正在尝试查看它是否解决了我遇到的问题,如果不希望它能帮助其他与我有类似问题的人。

+0

是的,这的确的工作只是通过两次确切的代码,并没有重复的值/记忆从先前runthrough [: –

相关问题