gpt4 book ai didi

c# - 使单击的按钮重定向到特定页面

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:38 25 4
gpt4 key购买 nike

public virtual async Task ShowAnnuvalConferenceTicket(IDialogContext context, IAwaitable<IMessageActivity> activity)
{
var message = await activity;

PromptDialog.Choice(
context: context,
resume:ChoiceReceivedAsync ,
options: (IEnumerable<ProductGroups>)Enum.GetValues(typeof(ProductGroups)),
prompt: " ",
promptStyle: PromptStyle.Auto
);
}
public virtual async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<ProductGroups> activity)
{
ProductGroups response = await activity;
context.Call<object>(new AnnualPlanDialog(response.ToString()), ChildDialogComplete);

}
public virtual async Task ChildDialogComplete(IDialogContext context, IAwaitable<object> response)
{
var respond = await response as Activity;
if (respond = ProductGroups.MoreCategories)
{
await context.PostAsync("Click here to view more categories");
context.Done(this);
}

}

public enum ProductGroups {
Toys,
Electronics,
Phones,
Health,
Beauty,
Computers,
Cameras,
Jewelery,
Watches,
Weddings,
MoreCategories
}

你好,我需要这方面的帮助,我一直在尝试获取从枚举常量生成的选项列表,每个选项都将我重定向到不同的页面,但我知道如何去做。有什么帮助吗?

最佳答案

如果你想打开一个url那么你可以使用Hero Cards只有按钮。您可以使用标题和链接创建字典,也可以使用枚举。这是我解决的问题:

而不是发送提示

var reply = context.MakeMessage();
List<CardAction> enumOptions = new List<CardAction>();
foreach(ProductGroups option in Enum.GetValues(typeof(ProductGroups)))
{
enumOptions.Add(new CardAction
{
Title = option.ToString(),
Type = option.ToString().Equals("MoreCategories") ? ActionTypes.ImBack : ActionTypes.OpenUrl,
Value = option.GetType()
.GetMember(option.ToString())
.First()
.GetCustomAttribute<DescribeAttribute>()
.Description
});


}

reply.Attachments.Add(GetHeroCard(null, null, null, null, enumOptions));
await context.PostAsync(reply);

CardAction 中的 Type 属性将决定单击按钮时执行的操作。因此,如果用户单击 MoreCategories 以外的任何按钮,将打开一个链接,如果用户单击 MoreCategories,则机器人将收到 moreCategories 消息,然后您可以对其进行处理。

GetHeroCard 只是一个基本函数,您可以调用它来创建任何英雄卡:

    public static Attachment GetHeroCard(string title, string subTitle, string text, List<CardImage> images, List<CardAction> action)
{

HeroCard card = new HeroCard();
if (!String.IsNullOrEmpty(title))
card.Title = title;
if (!String.IsNullOrEmpty(subTitle))
card.Subtitle = subTitle;
if (!String.IsNullOrEmpty(text))
card.Text = text;
if (images != null)
card.Images = images;
if (action != null)
card.Buttons = action ;
return card.ToAttachment();
}

您可以像这样更新您的枚举:

public enum ProductGroups
{
[Describe("https://stackoverflow.com/")]
Toys,
[Describe("https://stackoverflow.com/")]
Electronics,
[Describe("https://stackoverflow.com/")]
Phones,
[Describe("https://stackoverflow.com/")]
Health,
[Describe("https://stackoverflow.com/")]
Beauty,
[Describe("https://stackoverflow.com/")]
Computers,
[Describe("https://stackoverflow.com/")]
Cameras,
[Describe("https://stackoverflow.com/")]
Jewelery,
[Describe("https://stackoverflow.com/")]
Watches,
[Describe("https://stackoverflow.com/")]
Weddings,
[Describe("More categories")]
MoreCategories
}

输出

Output

关于c# - 使单击的按钮重定向到特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50697260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com