2017-04-11 19 views
4

我已經使用LUIS.ai意圖使用A和B.在意圖A中,我使用builder.Prompts.text來詢問用戶幾個問題。然而,有時候取決於答案,它會轉換爲意圖B.我猜這恰好符合我的意圖B,即使我認爲它不應該。有沒有辦法來防止這種情況發生?如果我正在通過意向A的對話,我不希望任何其他意圖中斷,直到我完成。這是我的代碼的一個例子。Botframework否從其他意圖對話中斷直到用當前意圖對話框完成

bot.dialog('A', [ 
    function (session, args, next) { 
     ... 
    }, 
    function (session, args, next) { 
     ... 
    }, 
    function (session, args) { 
     ... 
    } 
]).triggerAction({ 
    matches: 'A' 
}); 


bot.dialog('B', [ 
    function (session, args, next) { 
     ... 
    }, 
    function (session, args, next) { 
     ... 
    }, 
    function (session, args) { 
     ... 
    } 
]).triggerAction({ 
    matches: 'B' 
}); 

回答

6

這就是triggerAction s對你做的。他們可以非常方便地保持對話框打開(http://www.pveller.com/smarter-conversations-part-2-open-dialogs),但在你的情況下,他們阻礙。

如果您將它們放置在IntentDialog之下,您可以將您的對話框免疫到全局路由系統。如果你要做的就是AB,那麼這將是你的代碼的未中斷相當於:

const intents = new builder.IntentDialog({ 
    recognizers: [ 
     new builder.LuisRecognizer(process.env.LUIS_ENDPOINT) 
    ] 
}); 

intents.matches('A', 'A'); 
intents.matches('B', 'B'); 

bot.dialog('/', intents); 
bot.dialog('A', []); 
bot.dialog('B', []); 
+1

原因我從切換到''triggerAction'是IntentDialog'使用'cancelAction'能夠取消用戶鍵入「取消/停止」時的對話框。有沒有辦法做到這一點,如果我把我的意圖下的'IntentDialog'? – user3128376

+1

你確定可以用Intent.Dialog的[cancelAction](https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.intentdialog.html#cancelaction)。但是在Pavel的代碼中,他在'intents.matches'中傳入了第二個參數的dialogId。這個dialogId引用了你原來沒有'triggerAction'的同樣的對話框。所以當IntentDialog處理意圖時,它會重定向到目前爲止所使用的內容('UniversalBot.dialog'),允許您繼續使用'cancelAction'。 –

+0

不知道如果我使用它不正確,但當我做'intent.matches('A',[...])。cancelAction(...);'任何時候它符合我的關鍵字'取消'它意味着意圖A的'cancelAction'而不是我的意圖(即意圖B)。我將如何讓它不是全球?我基本上擁有Pavel的功能,但我只想添加'cancelAction'並使其不是全局的。謝謝 – user3128376