[Question] The CardAction of Hero card in Carousel card not working as actionable button.
System Information (Required)
- SDK Language: .NET/C#
- SDK Version: 4.6
- Development Environment: OTHER
Issue Description
I have tried ImBack as a action type in the value field i am getting text. When i click on the Hero card the value which i have written in code is displayed after clicking now the problem is the text should passed as a value in the method so that the method should be called after clicking that. Please provide solution.
Code Example
public static IList<Attachment> GetCardsAttachments(IDialogContext context)
{
return new List<Attachment>()
{
GetHeroCard(
"NoSQL",
"Blazing fast, planet-scale NoSQL",
"NoSQL service for highly available, globally distributed apps—take full advantage of SQL and JavaScript over document and key-value data without the hassles of on-premises or virtual machine-based cloud database options.",
new CardImage(url: "https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png"),
new CardAction(ActionTypes.ImBack, "Click here", value: "see the below options:")),
};
}
Expected Behavior
As from above code, i am getting the card with button name as "Click here" after clicking it my input is given to bot as "see the below options:", After this i want to initiate a function. I want the value to be passed to the function. So i can handle it further. Please tell me how i can i use this value of CardAction.
The Value of the Card Action ends up being sent in the Text property.
Please see here for documentation: https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-add-rich-card-attachments#process-events-within-rich-cards
You can check the text property and respond accordingly:
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;
if (!HandleButtonClick(context, activity))
{
//do other things in MessageReceivedAsync
int length = (activity.Text ?? string.Empty).Length;
var reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
await context.PostAsync(reply);
}
context.Wait(MessageReceivedAsync);
}
public static bool HandleButtonClick(IDialogContext context, Activity activity)
{
//check the text property, to see if it matches the card action value
if(activity.Text == "see the below options:")
{
//handle "ShowUserOptions"
return true;
}
return false;
}
Please note: The Microsoft Bot Framework team prefers that how to questions be submitted on Stack Overflow. The official Bot Framework Github repo is the preferred platform for submitting bug fixes and feature requests. I have closed this issue.