node.js bot框架universalbot beginDialogAction的用法?

node.js bot framework universalbot beginDialogAction usage?

可能我比较笨,但是我真的看不懂node.js version of Microsoft's bot framework sdk. I'm trying to figure out how to use beginDialogAction() or endConversationAction() in a ConsoleConnector bot。文档说它在触发时注册一个动作,但没有提到如何触发它。我想利用它可以在正常流程之外的调用堆栈中间添加对话框的想法。

对不起,我不能提供代码,但我可以给这个...

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

我理解和使用它的方式:动作是明确的东西,您可以从对话流中调用它来触发其他对话 + 参数。

这里的示例是您的机器人的正常流程,由对话框输入触发:

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

请注意,这张卡片通过按钮触发了一个名为 "News" 且参数为“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);
    }
]);

因此,我们可以根据我们传递的参数显示由其他对话框触发的通用新闻对话框。

有道理吗?