2016-07-27 11 views
0

たぶん私はばかですが、実際にはnode.js version of Microsoft's bot framework sdkの読み方を理解できません。私はbeginDialogAction()またはendConversationAction()ConsoleConnector botにどのように使うかを考えようとしています。ドキュメンテーションには、トリガされたときにアクションが登録されていますが、トリガする方法は記載されていません。私は、通常のフローの外でコールスタックの途中でダイアログを追加できるという考えを活用したいと思います。node.js bot framework 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()については、これを両方の間のクロスとして考えてください。カードのこの例を考えてみましょう:このカードは、ボタンを経由して、パラメータ「https://blog.botframework.com/」と「ニュース」というアクションをトリガーすること

// 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(); 
    } 
]); 

注意。これをカード上のボタンを押してダイアログ内で呼び出す関数と考えてください。今、その関数を定義するために、我々は実行します。

// 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); 
    } 
]); 

だからこれで、私たちは他のダイアログによってトリガ我々は引き渡すパラメータに基づいて、一般的なニュースのダイアログを表示することができます。

意味がありますか?

関連する問題