Search code examples
c#botframeworkslackazure-bot-service

What is the purpose of CardAction.ChannelData?


I'm using the .NET BotFramework v4 with Azure Bot Service and am rendering a HeroCard with a set of buttons in a message like so:

var card = new HeroCard
{
    Buttons = new List<CardAction>()
    {
        new()
        {
            Type = ActionTypes.PostBack,
            Value = "42",
            Title = "The answer"
        },
        new()
        {
            Type = ActionTypes.PostBack,
            Value = "0",
            Title = "Wrong answer"
        }
    }
};
var message = MessageFactory.Text(message.Message);
message.Attachments.Add(heroCard.ToAttachment());

I noticed that CardAction has a ChannelData property. I hoped to use that to customize the style of a button for Slack users.

However, this answer suggests that not possible. If I want to style a single button, it sounds like I have to dump this approach and just override the entire ChannelData for IMessageActivity.

Is that still the case? And if so, how does Azure Bot Service make use of CardAction.ChannelData? What is it for?


Solution

  • I have tried every card action property in every channel. As far as I can tell, the channel data property is never used.

    This might make sense to you when we consider the nature of the Bot Framework schema. The original idea behind the Bot Framework was to have a way to build one bot that works on many different channels. This works very well when it comes to ordinary text messages, but different channels have wildly different ideas of how they handle things like attachments and interactive messages. The Bot Framework team came up with something called "cards" to generalize the UI objects found in different channels, like Facebook Messenger's "templates" and Telegram's "inline keyboards." In order to do this, the team had to account for a lot of different abilities and possibilities found in all the channels. Since it was hard to predict what abilities a card action might need when the schema was designed ahead of time, it's understandable why the developers wanted to err on the side of caution and give a card action extra properties even though they weren't sure to be used.

    So it's very likely that a card action's channel data is just a relic of the Bot Framework schema's original spec.