I have implemented a carousel of Hero Cards to display all the Schedules a perticular Doc can have. In the hero cards i have added a button to select a Particular schedule. Below is the code
private async Task ShowSessionsHeroCard(IDialogContext context)
{
var replyToConversation = context.MakeMessage();
replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel;
replyToConversation.Attachments = await GetSessionHeroCard(context);
//replyToConversation.Attachments.Add(GetSessionHeroCard());
await context.PostAsync(replyToConversation);
}
private async Task<List<Attachment>> GetSessionHeroCard(IDialogContext context)
{
List<Attachment> list = new List<Attachment>();
List<CardAction> cardButtons = new List<CardAction>();
foreach (var sessionDetails in scheduleList)
{
string[] session = GetSplittedDetails(sessionDetails);
hospitalName = session[0]; //Hospital Name: {0}
availableDay = session[1]; //Available Day: {1}
appointmentNo = session[2]; // Appoinment No: {2}
sessionAvailable = session[3]; // Session: {3}
HeroCard hero = new HeroCard()
{
Title = hospitalName,
Subtitle = availableDay,
Text = sessionAvailable + appointmentNo,
Buttons = cardButtons
};
list.Add(hero.ToAttachment());
}
CardAction getSessionValues = new CardAction()
{
Value = hospitalName + availableDay + sessionAvailable + appointmentNo,
Type = ActionTypes.ImBack,
Title = " Select Appointment "
};
cardButtons.Add(getSessionValues);
string selectedAppointment = getSessionValues.Value.ToString();
await GetSelectedAppointment(context, selectedAppointment);
return list;
}
private async Task GetSelectedAppointment(IDialogContext context, string sessionSelected)
{
var replyToConversation = context.MakeMessage();
//replyToConversation.AttachmentLayout = AttachmentLayoutTypes.List;
string[] result = Utility.SplitSelectedApoitmentString(sessionSelected);
var heroCard = new HeroCard()
{
Title = "Appointment Schedule",
Subtitle = "These are the Appointment Details",
Text = "Hospital selected : " + result[0] + "\n" + "Day of Appointment : " + result[1] + "\n" + "Time of Appointment : " + result[2] + "\n" + "Appointment Number" + result[3],
}.ToAttachment();
Attachment attachment = new Attachment()
{
Content = heroCard.Content,
ContentType = heroCard.ContentType
};
replyToConversation.Attachments.Add(attachment);
await context.PostAsync(replyToConversation);
}
My questions are
- Am i defining the Button Correctly?
- The CardAction getSessionValues is getting some values even before i click on the button. How to avoid that.
- How to get the selected card value and pass it to another method.
I cant figure out whats wrong here please help. (Am sure Am doing sumthing very stupid.)
Thanks in Advance :)