2017-05-05 76 views
0

我最近開始使用Microsoft BOT框架和Node.js SDK開發BOT應用程序。我想知道是否可以在對話框中檢查匹配的意圖。例如,Microsoft BOT框架意圖加工

var builder = require('botbuilder'); 
var bot = new builder.UniversalBot(connector); 
var intents = new builder.IntentDialog(); 
bot.dialog('/', intents); 

這個意圖將檢查問候。

intents.matchesAny([/^hi/i, /^hello/i], [ 
    function (session) { 
     var displayName = session.message.user.name; 
     var firstName = displayName.substr(0, displayName.indexOf(' ')); 
     session.send('Hello I’m M2C2! How can I help you %s? If you need help just say HELP.', firstName); 
    } 
]); 

這個意圖將匹配支票卡餘額。

intents.matchesAny([/^balance/i, /^card balance/i], [ 
    function (session) { 
     session.beginDialog('/check-balance'); 
    } 
]); 

這是檢查平衡的對話框。

bot.dialog('/check-balance', [ 
    function (session) { 
     builder.Prompts.text(session, "Sure, I can find the balance for you! May I know the card number that you want to check the balance of?"); 
    }, 
    function (session, results) { 
     if (isNaN(results.response)) { 
      session.send('Invalid card number %s', results.response); 
     } else { 
      session.send('The balance on your %s card is $ 50', results.response); 
     } 
     session.endDialog(); 
    } 
]); 

什麼,我想知道的是,是否有可能來檢查任何支票餘額對話框內的匹配意圖。假設用戶輸入一個無效的卡號,並且我想確保該命令與任何已定義的意圖都不匹配,這樣我就可以顯示無效的卡號響應,如果匹配,則執行匹配的意圖。

+0

回答「平衡」或「嗨」的提示不會觸發其對應的對話框。當使用'Prompts.text()'時,它不應該試圖匹配意圖。但是,如果您使用'triggerAction()',那麼匹配其匹配屬性的任何話語都會觸發。 –

回答

0
intents.matches(/^(exit)|(quit)/, [ 
function (session) { 
    session.beginDialog('/exit'); 
}]); 


bot.dialog('/exit',[ 
function(session){ 
    if(session.message.text=='exit'||'quit'){ 
     session.send("Yor are exit"); 
    } else { session.send("you are not exit"); }                
}]) 
+0

所以在這種情況下,我將不得不通過一系列if語句檢查每個意圖。 – Lakmal

相關問題