|
private void AddCardMessage(Activity activity)
{
CardMessage cardMessage = new CardMessage();
cardMessage.Text = activity.Text;
cardMessage.Author = this.ViewModel.Bot;
ObservableCollection<Card> cards = new ObservableCollection<Card>();
System.Collections.Generic.IList<Microsoft.Bot.Schema.Attachment> attachments = activity.Attachments as System.Collections.Generic.IList<Microsoft.Bot.Schema.Attachment>;
HeroCard heroCard = new HeroCard();
foreach (Attachment attachment in attachments)
{
var type = attachment.ContentType;
if (type == "application/vnd.microsoft.card.hero")
{
var temp = JsonConvert.SerializeObject(attachment.Content);
heroCard = JsonConvert.DeserializeObject<HeroCard>(temp);
}
WebClient Client = new WebClient();
var byteArray = Client.DownloadData(heroCard.Images[0].Url.ToString());
Card card = new Card()
{
Title = heroCard.Title.ToString(),
Description = heroCard.Text.ToString(),
Image = ImageSource.FromStream(() => new MemoryStream(byteArray))
};
card.Buttons.Add(new CardButton() { Value = heroCard.Buttons[0].Value.ToString(), Title = heroCard.Buttons[0].Title });
cards.Add(card);
}
cardMessage.Cards = cards;
this.ViewModel.Messages?.Add(cardMessage);
} |