Как мне создать адаптивную карту, которая создаст таблицу для ответа бота, но у этого бота количество строк зависит от строк, выбранных из источника данных, он будет выбирать имя и идентификатор из источника данных, как создать данные и связать эти данные в пользовательском интерфейсе для адаптивной карты здесь, под кодом бота, я не понимаю, как динамически добавлять строки и связывать данные.
public class EchoBot : ActivityHandler
{
private const string WelcomeText = @"This bot will introduce you to AdaptiveCards.
Type anything to see an AdaptiveCard.";
// This array contains the file location of our adaptive cards
private readonly string[] _cards =
{
//Path.Combine(".", "Resources", "FlightItineraryCard.json"),
//Path.Combine(".", "Resources", "ImageGalleryCard.json"),
//Path.Combine(".", "Resources", "LargeWeatherCard.json"),
//Path.Combine(".", "Resources", "RestaurantCard.json"),
// Path.Combine(".", "Resources", "SolitaireCard.json"),
Path.Combine(".", "Resources", "School.json"),
};
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
await SendWelcomeMessageAsync(turnContext, cancellationToken);
}
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
// Random r = new Random();
var fileRead = System.IO.File.ReadAllText("School.json");
var item = (JObject)JsonConvert.DeserializeObject(fileRead);
string classData = item["$data"].ToString();
AdaptiveTransformer transformer = new AdaptiveTransformer();
string cardJson = transformer.Transform(fileRead, classData);
Microsoft.Bot.Schema.Attachment attachment = new Microsoft.Bot.Schema.Attachment();
attachment.ContentType = "application/vnd.microsoft.card.adaptive";
attachment.Content = JsonConvert.DeserializeObject(cardJson);
var attachments = new List<Microsoft.Bot.Schema.Attachment>();
//var reply = MessageFactory.Attachment(attachments);
//reply.Attachments.Add(attachment);
//return reply;
// var cardAttachment = CreateAdaptiveCardAttachment(_cards[r.Next(_cards.Length)]);
//turnContext.Activity.Attachments = new List<Attachment>() { cardAttachment };
await turnContext.SendActivityAsync(MessageFactory.Attachment(attachments), cancellationToken);
await turnContext.SendActivityAsync(MessageFactory.Text("Please enter any text to see another card."), cancellationToken);
}
private static async Task SendWelcomeMessageAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
foreach (var member in turnContext.Activity.MembersAdded)
{
if (member.Id != turnContext.Activity.Recipient.Id)
{
await turnContext.SendActivityAsync(
$"Welcome to Adaptive Cards Bot {member.Name}. {WelcomeText}",
cancellationToken: cancellationToken);
}
}
}
private static Microsoft.Bot.Schema.Attachment CreateAdaptiveCardAttachment(string filePath)
{
var adaptiveCardJson = System.IO.File.ReadAllText(filePath);
var adaptiveCardAttachment = new Microsoft.Bot.Schema.Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCardJson),
};
return adaptiveCardAttachment;
}