Reputation: 29
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
}
Good day, please I need help on these,I have been trying to get a list of options generated from enumerated constant each redirect me to different pages but know how to go about it. Any help please ?
Upvotes: 1
Views: 427
Reputation: 1153
If you want to open a url then you can use Hero Cards with just buttons. You can create a dictionary with the title and the link or you can also use the enum. Here's something I worked out with:
Instead of sending Prompt
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);
Type Attribute in CardAction will decide what to do when the button is clicked. So if the user clicked any button other than MoreCategories a link will open and if the user clicked MoreCategories the bot will get the message moreCategories and you can process it after that.
The GetHeroCard is just a basic function that you can call to create any hero card:
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();
}
You can update your enum's like this:
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
Upvotes: 6