Reputation: 145
I am trying to send an Adaptive Card to Microsoft Teams and it returns undefined in Teams. It is working fine in emulator. I am using c#. Below is the image from emulator and code used to send response to Teams.
Code:
public async Task EventCardMessage(Activity activity, JToken row)
{
using (var connector = new ConnectorClient(new Uri(activity.ServiceUrl), _config["MicrosoftAppId"], _config["MicrosoftAppPassword"]))
{
//adaptive card
Activity replyToConversation = activity.CreateReply();
replyToConversation.Attachments = new List<Attachment>();
AdaptiveCards.AdaptiveCard card = new AdaptiveCards.AdaptiveCard();
Card adaptiveCard = new Card();
adaptiveCard.Count = row["total_count"].ToString();
// Add text to the card.
card.Body.Add(new TextBlock()
{
Text = "There are " + adaptiveCard.Count + " Holidays this Year",
Size = TextSize.Normal,
Weight = TextWeight.Bolder
});
// Add Columns to card.
var list = row["card"]["data"]["list"];
foreach (var li in list)
{
adaptiveCard.Name = li["label3"].ToString();
adaptiveCard.Date = li["label1"].ToString() + " " + li["label2"].ToString();
adaptiveCard.Time = li["label5"].ToString();
adaptiveCard.Address = li["label4"].ToString();
var current = new ColumnSet();
card.Body.Add(current);
var column1 = new Column();
current.Columns.Add(column1);
var column2 = new Column();
current.Columns.Add(column2);
column1.Size = "40";
AddTextBlock(column1, adaptiveCard.Date, TextSize.Large, TextColor.Accent, false);
column2.Size = "60";
AddTextBlock(column2, adaptiveCard.Name, TextSize.Normal, TextColor.Default, false);
AddTextBlock(column2, adaptiveCard.Address, TextSize.Normal, TextColor.Default, false);
AddTextBlock(column2, adaptiveCard.Time, TextSize.Normal, TextColor.Default, false);
}
// Create the attachment.
Attachment attachment = new Attachment()
{
ContentType = AdaptiveCards.AdaptiveCard.ContentType,
Content = card
};
replyToConversation.Attachments.Add(attachment);
var reply = await connector.Conversations.SendToConversationAsync(replyToConversation);
}
}
Upvotes: 1
Views: 1006
Reputation: 12264
Microsoft Teams currently only supports Adaptive Cards 1.0. This means if you try to send a card with a version higher than 1.0 it will not render. When using the AdaptiveCards NuGet package, your cards will be given the same version as the package by default. This means that if you're using AdaptiveCards 1.2.0, your cards will be constructed with version 1.2.0. Try setting the version of your card explicitly:
var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
If you'd like to learn more about Adaptive Cards you can check out my latest blog post: https://blog.botframework.com/2019/07/02/using-adaptive-cards-with-the-microsoft-bot-framework/
Upvotes: 1