在Bot Framework的第3版中,我可以叫一张卡,然后等待用户的响应:
context.Call(new MyHeroCardOptions(), MyResumeAfter);
有人可以指导我如何在Bot Framework V4中做到这一点。请不要包括“ ChoicePrompt”,我的目标是使用HeroCard,因为它是附件。
我正在使用以下表格:
private static async Task<DialogTurnResult> TransportStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
await OptionHeroCard.GetHeroCard(stepContext.Context);
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions());
}
public static class OptionHeroCard
{
public static async Task GetHeroCard(ITurnContext context)
{
var heroCard = new HeroCard
{
Title = "Documentation",
Subtitle = "Microsoft Bot Framework Documentation",
Images = new List<CardImage> { new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg") },
Buttons = new List<CardAction> {
new CardAction(ActionTypes.ImBack, title: "Opción 1", value: "Opción 1"),
new CardAction(ActionTypes.ImBack, title: "Opción 2", value: "Opción 2"),
new CardAction(ActionTypes.OpenUrl, "Ir a a web", value: "https://docs.microsoft.com/bot-framework"),
},
};
var reply = context.Activity.CreateReply();
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
reply.Attachments.Add(heroCard.ToAttachment());
await context.SendActivityAsync(reply);
}
}
我目前使用带有“瀑布”的“文本提示”来生成等待,但是我不知道这是否合适。
答案 0 :(得分:2)
对于bot 4.7预览版,我通过调用2个操作来完成
new SendActivity("@{YourHeroCardTemplate()}"),
new TextInput()
{
Property = "dialog.heroCardResponse",
Prompt = new ActivityTemplate("Please select an option"),
},
希望它可以帮助您了解其他版本的bot框架
答案 1 :(得分:1)
如果您只是希望将选择自动转换为英雄卡,则可以使用ListStyle.HeroCard
:
new ChoicePrompt(nameof(ChoicePrompt)) { Style = ListStyle.HeroCard }
如果要使用自己的自定义英雄卡,可以执行以下操作:
private static async Task<DialogTurnResult> TransportStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
string[] options = new[] { "Opción 1", "Opción 2" };
return await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions
{
Choices = ChoiceFactory.ToChoices(options),
Prompt = CreateHeroCardActivity(options),
Style = ListStyle.None, // We're displaying the choices ourselves so we don't want ChoicePrompt to do it for us
});
}
private static Activity CreateHeroCardActivity(IEnumerable<string> options)
{
var heroCard = new HeroCard
{
Title = "Documentation",
Subtitle = "Microsoft Bot Framework Documentation",
Images = new List<CardImage>
{
new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg"),
},
Buttons = options.Select(option => new CardAction(ActionTypes.ImBack, title: option, value: option))
.Append(new CardAction(ActionTypes.OpenUrl, "Ir a a web", value: "https://docs.microsoft.com/bot-framework"))
.ToList(),
};
return MessageFactory.Attachment(heroCard.ToAttachment()) as Activity;
}