public static void Create(AdaptiveOpenUrlAction action, HtmlTag tag, AdaptiveRenderContext renderContext) { tag.Attr("id", AdaptiveCardRenderer.GenerateRandomId()); tag.Attr("data-ac-url", action.Url); tag.Attributes.Add("onclick", "window.blazorAdaptiveCards.openUrl(this.getAttribute('data-ac-url'), this)"); }
private static void AddForcastColumn(AdaptiveColumnSet forecast, AdaptiveColumn column, string place) { forecast.Columns.Add(column); column.Width = "20"; var action = new AdaptiveOpenUrlAction(); action.Url = new Uri($"https://www.bing.com/search?q=forecast in {place}"); column.SelectAction = action; }
protected static HtmlTag OpenUrlActionRender(AdaptiveOpenUrlAction action, AdaptiveRenderContext context) { return(new HtmlTag("a") .AddClass("btn") .AddClass("btn-secondary") .Attr("target", "_blank") .Attr("href", action.Url?.ToString()) .SetInnerText(action.Title)); }
public static void AddReportColumn(AdaptiveColumnSet reports, string url, string name) { var column = new AdaptiveColumn(); reports.Columns.Add(column); column.Items = new List <AdaptiveElement>(); column.Items.Add(new AdaptiveTextBlock() { Text = "**" + name.ToUpper() + "**" }); var action = new AdaptiveOpenUrlAction { Url = new Uri(url) }; column.SelectAction = action; }
public void OpenUrlAction() { var url = new System.Uri("http://www.stuff.com"); AdaptiveOpenUrlAction openUrlAction = new AdaptiveOpenUrlAction { Url = url, IconUrl = "http://www.stuff.com/icon.jpg", Id = "OpenUrlId", Style = "Destructive", Title = "Title" }; ValidateBaseActionProperties(openUrlAction, "http://www.stuff.com/icon.jpg", "OpenUrlId", "Title", "Destructive"); Assert.AreEqual(url, openUrlAction.Url); var jsonString = openUrlAction.ToJson().ToString(); Assert.AreEqual("{\"iconUrl\":\"http://www.stuff.com/icon.jpg\",\"id\":\"OpenUrlId\",\"style\":\"Destructive\",\"title\":\"Title\",\"type\":\"Action.OpenUrl\",\"url\":\"http://www.stuff.com/\"}", jsonString); }
public void CardLevelSelectAction() { var json = @"{ ""type"": ""AdaptiveCard"", ""version"": ""1.0"", ""selectAction"": { ""type"": ""Action.OpenUrl"", ""title"": ""Open URL"", ""url"": ""http://adaptivecards.io"" } }"; var card = AdaptiveCard.FromJson(json).Card; var actualSelectAction = card.SelectAction as AdaptiveOpenUrlAction; var expectedSelectAction = new AdaptiveOpenUrlAction { Title = "Open URL", UrlString = "http://adaptivecards.io" }; Assert.AreEqual(expectedSelectAction.Title, actualSelectAction.Title); Assert.AreEqual(expectedSelectAction.UrlString, actualSelectAction.UrlString); }
public void TestObjectModelActionSetElement() { AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion("1.2")); AdaptiveActionSet actionSet = new AdaptiveActionSet(); card.Body.Add(actionSet); AdaptiveSubmitAction submitAction = new AdaptiveSubmitAction { Title = "Action.Submit", DataJson = "{\"x\": 13}" }; actionSet.Actions.Add(submitAction); AdaptiveOpenUrlAction openUrlAction = new AdaptiveOpenUrlAction { Title = "OpenUrl", UrlString = "http://adaptivecards.io" }; actionSet.Actions.Add(openUrlAction); #pragma warning disable 0618 AdaptiveShowCardAction showCardAction = new AdaptiveShowCardAction { Title = "ShowCard", Card = new AdaptiveCard { Body = new List <AdaptiveElement> { new AdaptiveTextBlock { Text = "This is a show card" } } } }; #pragma warning restore 0618 actionSet.Actions.Add(showCardAction); AdaptiveToggleVisibilityAction toggleVisibilityAction = new AdaptiveToggleVisibilityAction { Title = "Toggle", TargetElements = new List <AdaptiveTargetElement> { "test" } }; actionSet.Actions.Add(toggleVisibilityAction); // This lines are not indented so the comparisson doesn't fail due to extra spaces var expectedJson = @"{ ""type"": ""AdaptiveCard"", ""version"": ""1.2"", ""body"": [ { ""type"": ""ActionSet"", ""actions"": [ { ""type"": ""Action.Submit"", ""data"": { ""x"": 13 }, ""title"": ""Action.Submit"" }, { ""type"": ""Action.OpenUrl"", ""url"": ""http://adaptivecards.io"", ""title"": ""OpenUrl"" }, { ""type"": ""Action.ShowCard"", ""card"": { ""type"": ""AdaptiveCard"", ""version"": ""1.0"", ""body"": [ { ""type"": ""TextBlock"", ""text"": ""This is a show card"" } ] }, ""title"": ""ShowCard"" }, { ""type"": ""Action.ToggleVisibility"", ""targetElements"": [ ""test"" ], ""title"": ""Toggle"" } ] } ] }"; var outputJson = card.ToJson(); Assert.AreEqual(outputJson, expectedJson); }
public virtual void Visit(AdaptiveOpenUrlAction action) { }
public static Activity Recipe(Activity activity, List <EdamamRecipe> recipes, IMessagesService messagesService) { var result = new List <Attachment>(); var reply = activity.CreateReply(); foreach (var item in recipes) { var body = new List <AdaptiveContainer>(); #region Tittle var tittle = new AdaptiveTextBlock { Text = item.label, Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Medium }; body.Add(new AdaptiveContainer { Items = new List <AdaptiveElement> { tittle } }); #endregion #region Imagen var imagen = new AdaptiveImage { Url = new Uri(item.image), Size = AdaptiveImageSize.Large, AltText = item.label }; body.Add(new AdaptiveContainer { Items = new List <AdaptiveElement> { imagen } }); #endregion #region Allergies string allergyText = string.Empty; foreach (var allergy in item.healthLabels) { allergyText += messagesService.Get(allergy).Value; } var allergyEmojis = new AdaptiveTextBlock { Text = allergyText, Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Medium }; body.Add(new AdaptiveContainer { Items = new List <AdaptiveElement> { allergyEmojis } }); #endregion #region Ingredients var ingredientContainer = new AdaptiveContainer() { Items = new List <AdaptiveElement>() }; ingredientContainer.Items.Add(new AdaptiveTextBlock { Text = "Ingredientes:", Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Medium, }); foreach (var ingredient in item.ingredientLines) { ingredientContainer.Items.Add(new AdaptiveTextBlock { Text = ingredient, Weight = AdaptiveTextWeight.Default, Size = AdaptiveTextSize.Default }); } body.Add(ingredientContainer); #endregion #region Button var action = new AdaptiveOpenUrlAction { Title = "ver mas", Url = new Uri(item.url), }; List <AdaptiveAction> actions = new List <AdaptiveAction> { action }; #endregion result.AddRange(CreateAdaptiveCard(body, actions)); } reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = result; reply.Text = messagesService.Get(MessagesKey.Key.RecipeSearch_result.ToString()).Value; return(reply); }
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); FeedParser feedParser = new FeedParser(); List <Item> items = feedParser.Parse("https://blogs.msdn.microsoft.com/appconsult/feed/", FeedType.RSS); var lastNews = items.OrderByDescending(x => x.PublishDate).FirstOrDefault(); AdaptiveCard card = new AdaptiveCard(); AdaptiveTextBlock title = new AdaptiveTextBlock { Text = lastNews.Title, Size = AdaptiveTextSize.Medium, Wrap = true }; AdaptiveColumnSet columnSet = new AdaptiveColumnSet(); AdaptiveColumn photoColumn = new AdaptiveColumn { Width = "auto" }; AdaptiveImage image = new AdaptiveImage { Url = new Uri("https://pbs.twimg.com/profile_images/587911661526327296/ZpWZRPcp_400x400.jpg"), Size = AdaptiveImageSize.Small, Style = AdaptiveImageStyle.Person }; photoColumn.Items.Add(image); AdaptiveTextBlock name = new AdaptiveTextBlock { Text = "Matteo Pagani", Weight = AdaptiveTextWeight.Bolder, Wrap = true }; AdaptiveTextBlock date = new AdaptiveTextBlock { Text = lastNews.PublishDate.ToShortDateString(), IsSubtle = true, Spacing = AdaptiveSpacing.None, Wrap = true }; AdaptiveColumn authorColumn = new AdaptiveColumn { Width = "stretch" }; authorColumn.Items.Add(name); authorColumn.Items.Add(date); columnSet.Columns.Add(photoColumn); columnSet.Columns.Add(authorColumn); AdaptiveTextBlock body = new AdaptiveTextBlock { Text = $"{lastNews.Content.Substring(0, 150)}...", Wrap = true }; AdaptiveOpenUrlAction action = new AdaptiveOpenUrlAction { Url = new Uri(lastNews.Link), Title = "View" }; card.Body.Add(title); card.Body.Add(columnSet); card.Body.Add(body); card.Actions.Add(action); string json = card.ToJson(); return(new OkObjectResult(json)); }