Skip to content

Instantly share code, notes, and snippets.

@andy51002000
Last active November 1, 2017 09:18
Create a ThumbnailCard for bot framework
var reply = context.MakeMessage();
Dictionary<string, string> cardImageUrls = new Dictionary<string, string>()
{
{"Nitro 5","https://static.acer.com/up/Resource/Acer/Laptops/Nitro_5/Gallery/20170613/Nitro5_gallery_01.png"},
{"Aspire Vx 15","https://static.acer.com/up/Resource/Acer/Laptops/Aspire_VX_15/Overview/20161117/Aspire-VX-15_gallery-01.png"},
{"Swift 7", "https://static.acer.com/up/Resource/Acer/Notebooks/Swift%207/Photogallery/20160824/Swift7-gallery-01.png"}
};
Dictionary<string, string> cardContentList = new Dictionary<string, string>()
{
{"Nitro 5","Windows 10 Home Intel® Core™ i7-7700HQ processor Quad-core 2.80 GHz 39.6 cm (15.6) Full HD (1920 x 1080) 16:9 NVIDIA® GeForce® GTX 1050 with 4 GB Dedicated Memory 16 GB, DDR4 SDRAM 1 TB HDD, 128 GB SSD"},
{"Aspire Vx 15","With its hard edged futuristic design the Aspire VX 15, looks and feels like it will help you take control."},
{"Swift 7", "Windows 10 Home 33.8 cm (13.3) Full HD (1920 x 1080) 16:9 IPS Intel® Shared Memory 8 GB, LPDDR3 Intel® Core™ i5-7Y54 processor 1.20 GHz 256 GB SSD"}
};
foreach(var imgUrl in cardImageUrls)
{
List<CardImage> cardImgs = new List<CardImage>()
{
new CardImage(url:imgUrl.Value)
};
List<CardAction> cardAction = new List<CardAction>()
{
new CardAction()
{
Value = imgUrl.Key,
Type = "imBack",
Title = "Detail"
}
};
var thbCard = new ThumbnailCard()
{
Title = $"{imgUrl.Key}",
Subtitle = $"{cardContentList.FirstOrDefault( c=> c.Key == imgUrl.Key)}",
Images = cardImgs,
Buttons = cardAction
};
Attachment att = thbCard.ToAttachment();
reply.Attachments.Add(att);
}
reply.Text = "Products";
reply.Speak = "Products";
await context.PostAsync(reply);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment