예제 #1
0
        private ImageCardContext CreateImageContext(PickerItem cardPickerItem, Attachment attachment)
        {
            HeroCard         card         = JsonConvert.DeserializeObject <HeroCard>(attachment.Content.ToString());
            ImageCardContext imageContext = new ImageCardContext();

            if (card.Images != null && card.Images.Count > 0)
            {
                imageContext.Image = card.Images[0].Url;
            }
            imageContext.Title       = card.Title;
            imageContext.Subtitle    = card.Subtitle;
            imageContext.Description = card.Text;

            foreach (CardAction action in card.Buttons)
            {
                CardAction        currentAction = action;
                CardActionContext actionContext = new CardActionContext()
                {
                    Text    = currentAction.Title,
                    Command = new Command(() =>
                    {
                        this.chat.Items.Remove(cardPickerItem);
                        this.chat.Items.Add(new TextMessage()
                        {
                            Author = this.chat.Author, Text = currentAction.Value.ToString()
                        });
                    })
                };

                imageContext.Actions.Add(actionContext);
            }

            return(imageContext);
        }
예제 #2
0
        private void RenderCards(JToken attachments)
        {
            string layout = Convert.ToString(attachments.Parent.Parent["attachmentLayout"]);

            if (layout != "carousel")
            {
                return;
            }

            List <CardContext> imageCards     = new List <CardContext>();
            CardPickerContext  cardContext    = new CardPickerContext();
            PickerItem         cardPickerItem = new PickerItem {
                Context = cardContext
            };

            foreach (JToken attachment in attachments)
            {
                List <CardActionContext> actions = new List <CardActionContext>();
                foreach (var action in attachment["buttons"])
                {
                    var localAction = action;
                    actions.Add(new CardActionContext()
                    {
                        Text    = Convert.ToString(localAction["title"]),
                        Command = new Command(() =>
                        {
                            this.chat.Items.Remove(cardPickerItem);
                            string actionText = Convert.ToString(localAction["value"]);
                            this.chat.Items.Add(new TextMessage()
                            {
                                Text = actionText, Author = this.chat.Author
                            });
                        })
                    });
                }

                ImageCardContext imageContext = new ImageCardContext();
                if (attachment["images"] != null && attachment["images"].Count() > 0)
                {
                    imageContext.Image = (Convert.ToString(attachment["images"][0]["url"]));
                }

                imageContext.Title    = Convert.ToString(attachment["title"]);
                imageContext.Subtitle = Convert.ToString(attachment["subtitle"]);
                imageContext.Actions  = actions;

                imageCards.Add(imageContext);
            }

            cardContext.Cards = imageCards;

            this.chat.Items.Add(cardPickerItem);
        }
예제 #3
0
        private ChatItem CreateCarouselPickerItem(Activity activity)
        {
            CardPickerContext  cardContext    = new CardPickerContext();
            List <CardContext> imageCards     = new List <CardContext>();
            PickerItem         cardPickerItem = new PickerItem();

            foreach (Attachment attachment in activity.Attachments)
            {
                if (attachment.ContentType != "application/vnd.microsoft.card.hero")
                {
                    continue;
                }

                ImageCardContext imageContext = this.CreateImageContext(cardPickerItem, attachment);
                imageCards.Add(imageContext);
            }

            cardContext.Cards      = imageCards;
            cardPickerItem.Context = cardContext;

            return(cardPickerItem);
        }