HeroCard中的多个按钮

时间:2017-06-07 08:19:58

标签: node.js botframework

我想在HeroCard上有多个按钮 并能够一个接一个地按下所有按钮 但是当我按下click按钮程序跳转到瀑布中的下一个功能时 并期望再次执行下一个操作而不是按钮操作 在这种情况下我该怎么做?

bot.dialog("/showCards", [
    (session) => {
        const msg = new Message(session)
            .textFormat(TextFormat.xml)
            .attachmentLayout(AttachmentLayout.carousel)
            .attachments([{
                title: "title",
                url: "https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png"
            }].map(obj =>
                new HeroCard(session)
                    .title(obj.title)
                    .images([
                        CardImage.create(session, obj.url)
                            .tap(CardAction.showImage(session, obj.url)),
                    ])
                    .buttons([
                        CardAction.openUrl(session, obj.url),
                        CardAction.imBack(session, `click`, "Click"),
                        CardAction.imBack(session, `clack`, "Clack")
                    ])
            ));
        Prompts.choice(session, msg, ["click", "clack"]);

    },
    (session, results) => {
        // todo use results.response.entity
    }
]);

2 个答案:

答案 0 :(得分:2)

您还可以使用CardAction.dialogAction并将每个按钮链接到beginDialogAction。

let card = new builder.HeroCard(session)
    .title(title)
    .subtitle(subtitle)
    .buttons([builder.CardAction.dialogAction(session, 'dialogAAction', 'dataYouNeedInDialogA', 'ButtonTitleA'), builder.CardAction.dialogAction(session, 'dialogBAction', 'dataYouNeedInDialogA', 'ButtonTitleB')]);

let msg = new builder.Message(session)
    .attachments([card])

session.endDialog(msg); 
// use one of these two to either end the dialog and start a new one  or to stay in the current dialog and wait for user input
session.send(msg);

// don't forget to add the dialogs to your bot / library later in your code (outside your current dialog) 
bot.dialog('dialogA', dialogA); // initialized somewhere in your code
bot.dialog('dialogB', dialogB); 
bot.beginDialogAction('dialogAAction', 'dialogA');
bot.beginDialogAction('dialogBAction', 'dialogB', {
onSelectAction: (session, args, next) => {
    // you might want to clear the dialogStack if the button is pressed. Otherwise, if the button is pressed multiple times, instances of dialogB are pilled up on the dialog stack.
    session.clearDialogStack();
    next();
  }
});

在我看来,这是实现您目前所描述的行为的最佳方式。只要用户按下它们,所有按钮都会起作用,即使它们在对话中向后滚动并再次按下相同的按钮。唯一的权衡是您必须将数据传递到新对话框,并且不能在整个流程中使用dialogData。尽管如此,我认为这是值得的,因为在整个机器人的使用过程中确保了一致的用户体验。

希望这会有所帮助。您可以构建单击和克拉对话框,将它们链接到操作并传递所需的数据。用户可以按下单击,咔嗒声,单击,机器人仍然可以工作。 :)

答案 1 :(得分:0)

在ResumeAfter函数中使用switch-case,在默认情况下将用户发送到上一个函数。