2016-07-27 17 views
0

也許我很笨,但我真的不懂如何閱讀node.js version of Microsoft's bot framework sdk。我試圖弄清楚如何在ConsoleConnector bot中使用beginDialogAction()或。文件說它在觸發時註冊一個動作,但沒有提及如何觸發它。我想利用它可以在正常流程之外的callstack中添加一個對話框的想法。node.js bot框架universalbot beginDialogAction用法?

我很抱歉,我不能提供代碼,但我可以給這個...

var connector = new builder.ConsoleConnector().listen(); 
var connector = new builder.ConsoleConnector().listen(); 
var bot = new builder.UniversalBot(connector); 

bot.dialog('/', [ 
    function(session) { 
     builder.Prompts.text(session, "blah blah blah?"); 
    }, 
    function(session, results) { 
     // ... 

     session.beginDialog('/foo'); 
     session.endDialog(); 
    } 
]); 

bot.dialog('/foo', [ 
    function(session, args) { 
     // ... 
    }, 
    function(session, results) { 
     // ... 
     session.endDialog(); 
    } 
]); 

bot.use({ botbuilder: function(session, next) { 

    // CALL THE ACTION 'bar' HERE TO ADD '/help' to the callstack 

    // ... 
    next(); 
}}); 

bot.beginDialogAction('bar', '/help'); 

bot.dialog('/help', [ 
    function(session, args) { 
     // ... 
    }, 
    function(session, results) { 
     // ... 
     session.endDialog(); 
    } 
]); 

回答

3

我理解和使用它的方式:一個動作是明確的東西,你可以從你的對話框中調用流程來觸發其他對話框+參數。

此處作爲一例是用於機器人,一個正常的流動,通過對話框輸入觸發:

bot.dialog('/', new builder.IntentDialog() 
.matches(/^command1/i, '/command1') 
.matches(/command2/i, '/command2') 
.onDefault(..)); 

bot.dialog('/command1', [ 
    function (session) { 
     session.send('Hello.'); 
    } 
]); 

例如,你可以使用對話動作以觸發一個動作,而不是直接路由到一個功能:

.onDefault(builder.DialogAction.send("Hello World!")) 

至於beginDialogAction(),可以認爲這是兩者之間的交叉。考慮卡的這個例子:

// An actions is just a normal card of any type that 
// features a dialogAction with the respective parameters. 
bot.dialog('/Action', [ 
    function (session) { 
     // Create a new message. Note that cards are managed as attachments 
     // that each channel can interpret as they see fit. Remember that some 
     // channels are text only, so they will have to adapt. 
     var msg = new builder.Message(session) 
      .textFormat(builder.TextFormat.xml) 
      .attachments([ 
       // This is the actual hero card. For each card you can add the 
       // specific options like title, text and so on. 
       new builder.HeroCard(session) 
        .title("Hero Card") 
        .subtitle("Microsoft Bot Framework") 
        .text("Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.") 
        .images([ 
         builder.CardImage.create(session, "https://bot-framework.azureedge.net/bot-icons-v1/bot-framework-default-7.png") 
        ]) 
        .buttons([ 
         builder.CardAction.dialogAction(session, "News", "https://blog.botframework.com/", "Get news") 
        ]) 
      ]); 

     // Send the message to the user and end the dialog 
     session.send(msg); 
     session.endDialog(); 
    } 
]); 

請注意,此卡將觸發所謂的「新聞」通過一個按鈕參數「https://blog.botframework.com/」的動作。可以將此視爲通過按下卡上的按鈕在對話框中調用的功能。我們定義函數,我們這樣做:所以用這個

// An action is essentially a card calling a global dialog method 
// with respective parameters. So instead of using choice prompts 
// or a similar waterfall approach, you can link to separate 
// dialogs. 
// The dialog action will route the action command to a dialog. 
bot.beginDialogAction('News', '/News'); 

// Create the dialog itself. 
bot.dialog('/News', [ 
    function (session, args) { 
     session.endDialog("Loading news from: " + args.data); 
    } 
]); 

我們可以顯示基於參數我們交出,由其他對話觸發通用消息對話框。

有意義嗎?