node.js - HeroCard 中的多个按钮

标签 node.js botframework

我想在 HeroCard 上有多个按钮 并能够一个接一个地按下所有按钮 但是当我按下 click 按钮时,程序跳转到 waterfall 中的下一个函数 并期待下一个 Action 而不是再次按钮 Action 这种情况我该怎么办?

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

最佳答案

您还可以使用 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。尽管如此,我认为这是值得的,因为可以确保在整个机器人使用过程中保持一致的用户体验。

希望这对您有所帮助。您可以构建点击对话框,将它们链接到操作并传递您需要的数据。用户将能够按点击、咔嗒、点击,机器人仍然可以工作。 :)

关于node.js - HeroCard 中的多个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44407242/

相关文章:

azure - 发布机器人 - Composer - 从现有资源导入

mysql - 如何使用 Node Mysql Api 在 bot 框架 v4 中存储用户对话

node.js - NodeJS + Mongodb 性能问题

node.js - 错误: unsatisfiable constraints: nodejs-npm (missing)

javascript - Angular 6,请求httpClient(类型错误)

javascript - Nodejs JavaScript 事件

css - 如何更改机器人背景颜色

node.js - 如何在 Nodejs 中处理 KML/GeoJSON?

bots - 单击卡片中的按钮时如何识别特定附件?

python - 通过 BotFramework 的 REST API 回复消息的最小示例?