我正在开发Teams Message Extension,并且正在使用ThumbnailCard显示我的结果,但是我想使用自定义的自适应卡。那可能吗?
var resultCardList = GetAttachments(title);
var response = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
response.ComposeExtension.Attachments = resultCardList.ToList();
return response;
foreach (var contract in contractItems)
{
var lastModified = (DateTime)contract["Modified"];
var justificativa = contract["JustificativaContrato"];
var card = new ThumbnailCard
{
Title = $"{contract.Client_Title} - {lastModified.ToShortDateString()} {lastModified.ToLongTimeString()}",
Text = $"Justificativa: {justificativa}",
Tap = new CardAction { Type = "openUrl", Value = $"{Tenant}{ContractList.DefaultEditFormUrl}?ID={contract.Id}" },
Images = new List<CardImage> { new CardImage("http://lorempixel.com/640/480?rand=" + DateTime.Now.Ticks.ToString()) }
};
cardList.Add(card
.ToAttachment()
.ToComposeExtensionAttachment());
}
return cardList;
我尝试使用以下方法来生成自适应卡并将其添加到列表中:
private static Microsoft.Bot.Connector.Attachment CreateAdaptiveCardAttachment()
{
// combine path for cross platform support
string[] paths = { ".", "Cards", "welcomeCard.json" };
string fullPath = Path.Combine(paths);
var adaptiveCard = System.IO.File.ReadAllText(@"Cards\welcomeCard.json");
return new Microsoft.Bot.Connector.Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCard),
};
}
答案 0 :(得分:0)
消息传递扩展名不允许发送类似的自适应卡。 它要求使用框架的“ MessagingExtensionResult”,而仅使用响应中发送的卡。这里缺少文档。
当您从消息传递分机接到电话时,其操作的类型为“ composeExtension /查询”
像这样创建常规的“结果”列表:
var invokeResponse = new MessagingExtensionResponse();
var results = new MessagingExtensionResult
{
AttachmentLayout = "list",
Type = "result",
Attachments = new List<MessagingExtensionAttachment>(),
};
对于列表中的每个结果,您需要创建一个MessagingExtensionAttachment,如下所示:(注意:卡片需要预览!)
results.Attachments.Add(new MessagingExtensionAttachment
{
ContentType = "application/vnd.microsoft.teams.card.adaptive",
Content = JsonConvert.DeserializeObject(cardData),
Preview = new Attachment
{
ContentType = "application/vnd.microsoft.card.thumbnail",
Content = new AttachmentContent
{
text = "Project: " + task.ProjectName,
title = task.Name,
},
}
});
最后将结果发送为“ InvokeResponse”
return new InvokeResponse
{
Body = invokeResponse,
Status = 200,
};
附件的“内容”是完整的自适应卡。 您可以在json中找到响应示例: https://docs.microsoft.com/de-de/microsoftteams/platform/concepts/messaging-extensions/search-extensions#response-example
您可以基于此自由混合卡类型,但是据我所知,到目前为止我还没有得到有效的解决。据我所知,您现在需要限制为一种特定的卡类型。
以上全部是如果您使用的是 Microsoft.Bot.Builder.Teams
Microsoft.Bot.Connector.Teams
Microsoft.Bot.Schema.Teams
在最新版本中。