HeroCard 中的多个按钮
Multiple buttons in HeroCard
我想在 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
}
]);
在 ResumeAfter 函数中使用 switch-case,在默认情况下将用户转到上一个函数。
您还可以将 CardAction.dialogAction 和 link 每个按钮用于 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。尽管如此,我认为这是值得的,因为可以确保在整个机器人使用过程中保持一致的用户体验。
希望这对您有所帮助。您可以构建点击对话框,link 将它们转化为操作并传递您需要的数据。用户将能够按点击、咔嗒、点击,机器人仍然可以工作。 :)
我想在 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
}
]);
在 ResumeAfter 函数中使用 switch-case,在默认情况下将用户转到上一个函数。
您还可以将 CardAction.dialogAction 和 link 每个按钮用于 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。尽管如此,我认为这是值得的,因为可以确保在整个机器人使用过程中保持一致的用户体验。
希望这对您有所帮助。您可以构建点击对话框,link 将它们转化为操作并传递您需要的数据。用户将能够按点击、咔嗒、点击,机器人仍然可以工作。 :)