I am unable to send an Adaptivecard using the "OnTeamsMessagingExtensionSelectItemAsync" method in MS teams Messageextension. I can able to send the Thumbnail/Harocard, Please let me know if "OnTeamsMessagingExtensionSelectItemAsync" supports returning an AdaptiveCard.
private readonly AdaptiveCardCreator adaptiveCardCreator;
public AdaptiveCard CreateAdaptiveCard(
string title,
string imageUrl,
string summary,
string author,
string buttonTitle,
string buttonUrl)
{
var version = new AdaptiveSchemaVersion(1, 0);
AdaptiveCard card = new AdaptiveCard(version);
card.Body.Add(new AdaptiveTextBlock()
{
Text = title,
Size = AdaptiveTextSize.Default,
Weight = AdaptiveTextWeight.Bolder,
Wrap = true,
});
card.Speak = title;
if (!string.IsNullOrWhiteSpace(imageUrl))
{
card.Body.Add(new AdaptiveImage()
{
Url = new Uri(imageUrl, UriKind.RelativeOrAbsolute),
Spacing = AdaptiveSpacing.Default,
Size = AdaptiveImageSize.Stretch,
AltText = string.Empty,
});
}
if (!string.IsNullOrWhiteSpace(summary))
{
card.Body.Add(new AdaptiveTextBlock()
{
Text = summary,
Wrap = true,
});
}
if (!string.IsNullOrWhiteSpace(author))
{
card.Body.Add(new AdaptiveTextBlock()
{
Text = author,
Size = AdaptiveTextSize.Small,
Weight = AdaptiveTextWeight.Lighter,
Wrap = true,
});
}
if (!string.IsNullOrWhiteSpace(buttonTitle)
&& !string.IsNullOrWhiteSpace(buttonUrl))
{
card.Actions.Add(new AdaptiveOpenUrlAction()
{
Title = buttonTitle,
Url = new Uri(buttonUrl, UriKind.RelativeOrAbsolute),
});
}
return card;
} protected override async Task<MessagingExtensionResponse> OnTeamsMessagingExtensionSelectItemAsync(ITurnContext<IInvokeActivity> turnContext, JObject query, CancellationToken cancellationToken)
{ var adaptiveCard = this.adaptiveCardCreator.CreateAdaptiveCard(
title,
imageLink,
summary,
author,
buttonTitle,
buttonLink
);
var attachment = new MessagingExtensionAttachment
{
ContentType = AdaptiveCard.ContentType,
Content = adaptiveCard,
};
return Task.FromResult(new MessagingExtensionResponse
{
ComposeExtension = new MessagingExtensionResult
{
Type = "result",
AttachmentLayout = "list",
Attachments = new List<MessagingExtensionAttachment> { attachment }
}
});
}