2016-07-25 81 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 [: –

相關問題