Exemplo n.º 1
0
        // Create AdaptiveCard from ReceiptCard
        public static AdaptiveCard CreateReceiptCard(ReceiptCard card, string totalTitle = "Total", string vatTitle = "VAT", string taxTitle = "Tax", string version = "1.0")
        {
            var adaptiveCard = new AdaptiveCard();
            var body         = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };

            // Add Title
            body.Items.AddRange(AdaptiveElementBuilder.CreateTitle(card.Title));

            // Add Receipt Fact
            if (card.Facts != null && card.Facts.Count != 0)
            {
                body.Items.AddRange(CreateReceiptFactSet(card.Facts));
            }

            // Add Separator
            body.Items.Add(CreateReceiptSeparator());

            // Add Receipt Item
            if (card.Items != null && card.Items.Count != 0)
            {
                body.Items.AddRange(CreateReceiptItems(card.Items.ToList()));
            }

            // Add Separator
            body.Items.Add(CreateReceiptSeparator());

            // Add VAT
            if (!string.IsNullOrEmpty(card.Vat))
            {
                body.Items.Add(CreateReceiptOtherInfo(vatTitle, card.Vat, "Vat"));
            }

            // Add Tax
            if (!string.IsNullOrEmpty(card.Tax))
            {
                body.Items.Add(CreateReceiptOtherInfo(taxTitle, card.Tax, "Tax"));
            }

            // Add Total
            if (!string.IsNullOrEmpty(card.Total))
            {
                body.Items.Add(CreateReceiptTotalInfo(totalTitle, card.Total));
            }

            // Set Tap Action
            if (card.Tap != null)
            {
                body.SelectAction = AdaptiveElementBuilder.CreateAction(card.Tap);
            }

            // Set Body and Actions
            adaptiveCard.Body = new List <AdaptiveElement>()
            {
                body
            };
            adaptiveCard.Actions = AdaptiveElementBuilder.CreateActions(card.Buttons);
            adaptiveCard.Version = version;

            return(adaptiveCard);
        }
Exemplo n.º 2
0
        private void TestPayloadsInDirectory(string path, string[] excludedCards)
        {
            var exceptions = new List <Exception>();
            var files      = Directory.GetFiles(path, "*.json").ToList();

            Assert.IsTrue(files.Count >= 1);
            foreach (var file in files)
            {
                bool excluded = false;
                if (excludedCards != null)
                {
                    foreach (var card in excludedCards)
                    {
                        if (file.Contains(card))
                        {
                            excluded = true;
                            break;
                        }
                    }
                }

                try
                {
                    var json = File.ReadAllText(file, Encoding.UTF8);
                    AdaptiveCardParseResult parseResult;
                    try
                    {
                        parseResult = AdaptiveCard.FromJson(json);
                    }
                    catch
                    {
                        // If the card is excluded we might not parse properly
                        // skip it if there was a parse failure.
                        if (!excluded)
                        {
                            throw;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    Assert.IsNotNull(parseResult.Card);
                    if (excluded)
                    {
                        // If the card was excluded but parsed, then it would have warnings
                        // If it doesn't then it shouldn't be excluded
                        Assert.AreNotEqual(0, parseResult.Warnings.Count);
                        Assert.IsNotNull(parseResult.Card.Body);
                    }
                    else
                    {
                        Assert.AreEqual(0, parseResult.Warnings.Count);
                        Assert.IsNotNull(parseResult.Card.Body);
                    }

                    // Make sure JsonConvert works also
                    var card = JsonConvert.DeserializeObject <AdaptiveCard>(json, new JsonSerializerSettings
                    {
                        Converters = { new StrictIntConverter() }
                    });
                    Assert.AreEqual(parseResult.Card.Body.Count, card.Body.Count);
                    Assert.AreEqual(parseResult.Card.Actions.Count, card.Actions.Count);
                }
                catch (Exception ex)
                {
                    exceptions.Add(new Exception($"Payload file failed: {Path.GetFileName(file)}", ex));
                }
            }

            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
        }
Exemplo n.º 3
0
        public void RichTextBlock()
        {
            var card = new AdaptiveCard("1.2");

            var richTB = new AdaptiveRichTextBlock();

            richTB.HorizontalAlignment = AdaptiveHorizontalAlignment.Center;

            // Build text runs
            var textRun1 = new AdaptiveTextRun("Start the rich text block ");

            richTB.Inlines.Add(textRun1);

            var textRun2 = new AdaptiveTextRun("with some cool looking stuff. ");

            textRun2.Color         = AdaptiveTextColor.Accent;
            textRun2.FontStyle     = AdaptiveFontStyle.Monospace;
            textRun2.IsSubtle      = true;
            textRun2.Italic        = true;
            textRun2.Strikethrough = true;
            textRun2.Highlight     = true;
            textRun2.Size          = AdaptiveTextSize.Large;
            textRun2.Weight        = AdaptiveTextWeight.Bolder;
            richTB.Inlines.Add(textRun2);

            var textRun3 = new AdaptiveTextRun("This run has a link!");

            textRun3.SelectAction = new AdaptiveOpenUrlAction()
            {
                Title     = "Open URL",
                UrlString = "http://adaptivecards.io/"
            };
            richTB.Inlines.Add(textRun3);

            card.Body.Add(richTB);

            // Indentation needs to be kept as-is to match the result of card.ToJson
            var expected = @"{
  ""type"": ""AdaptiveCard"",
  ""version"": ""1.2"",
  ""body"": [
    {
      ""type"": ""RichTextBlock"",
      ""horizontalAlignment"": ""center"",
      ""inlines"": [
        {
          ""type"": ""TextRun"",
          ""text"": ""Start the rich text block ""
        },
        {
          ""type"": ""TextRun"",
          ""size"": ""large"",
          ""weight"": ""bolder"",
          ""color"": ""accent"",
          ""isSubtle"": true,
          ""italic"": true,
          ""strikethrough"": true,
          ""highlight"": true,
          ""text"": ""with some cool looking stuff. "",
          ""fontStyle"": ""monospace""
        },
        {
          ""type"": ""TextRun"",
          ""text"": ""This run has a link!"",
          ""selectAction"": {
            ""type"": ""Action.OpenUrl"",
            ""url"": ""http://adaptivecards.io/"",
            ""title"": ""Open URL""
          }
        }
      ]
    }
  ]
}";

            Assert.AreEqual(expected, card.ToJson());
        }
        public static IList <Attachment> GetFlightsAdaptiveCards(IEnumerable <Flight> flights)
        {
            //List<Attachment> attachments = new List<Attachment>();

            //foreach (var flight in flights)
            //{
            //    AdaptiveCard adaptiveCard = new AdaptiveCard();
            //    adaptiveCard.Body.Add(new AdaptiveTextBlock()
            //    {
            //        Text = flight.Airline_Name,
            //        Size = AdaptiveTextSize.ExtraLarge,
            //        Separator = true,
            //    });
            //    adaptiveCard.Body.Add(new AdaptiveTextBlock()
            //    {
            //        Text = $"$:{flight.Price}",
            //        Size = AdaptiveTextSize.Large,
            //        Separator = true,
            //    });
            //    Attachment attachment = new Attachment()
            //    {
            //        ContentType = AdaptiveCard.ContentType,
            //        Content = adaptiveCard
            //    };
            //    attachments.Add(attachment);
            //}
            //return attachments;

            List <Attachment> attachments = new List <Attachment>();

            foreach (var flight in flights)
            {
                AdaptiveCard adaptiveCard = new AdaptiveCard();

                adaptiveCard.Body.Add(new AdaptiveTextBlock()
                {
                    Text     = $"{flight.Airline_Name}",
                    Size     = AdaptiveTextSize.ExtraLarge,
                    Weight   = AdaptiveTextWeight.Bolder,
                    IsSubtle = false,
                });
                adaptiveCard.Body.Add(new AdaptiveTextBlock()
                {
                    Text      = $"ID: {flight.ID}",
                    Weight    = AdaptiveTextWeight.Bolder,
                    Separator = true
                });
                adaptiveCard.Body.Add(new AdaptiveTextBlock()
                {
                    Text = $"Ticket Type: {flight.Ticket_Type}",
                    //Weight = AdaptiveTextWeight.Bolder,
                    Separator = true
                });
                adaptiveCard.Body.Add(new AdaptiveTextBlock()
                {
                    Text      = $"Date:{flight.Departure_Time.DayOfWeek},{flight.Departure_Time.Date.ToString("dd/MM/yyyy")}",
                    Weight    = AdaptiveTextWeight.Bolder,
                    Separator = true
                });
                adaptiveCard.Body.Add(new AdaptiveColumnSet()
                {
                    Separator = true,
                    Columns   = new List <AdaptiveColumn>()
                    {
                        new AdaptiveColumn()
                        {
                            Width = "1",
                            Items = new List <AdaptiveElement>()
                            {
                                new AdaptiveTextBlock()
                                {
                                    Text     = $"{flight.Departue_City}",
                                    IsSubtle = true
                                },
                                new AdaptiveTextBlock()
                                {
                                    Text     = $"{flight.Departue_City_Code}",
                                    Size     = AdaptiveTextSize.ExtraLarge,
                                    Color    = AdaptiveTextColor.Accent,
                                    Spacing  = AdaptiveSpacing.None,
                                    IsSubtle = true
                                },
                                new AdaptiveTextBlock()
                                {
                                    Text     = $"Time: {flight.Departure_Time.Hour}:{flight.Departure_Time.Minute}",
                                    IsSubtle = true
                                }
                            }
                        },
                        new AdaptiveColumn()
                        {
                            Width = AdaptiveColumnWidth.Auto,
                            Items = new List <AdaptiveElement>()
                            {
                                new AdaptiveTextBlock()
                                {
                                    Text = " "
                                },
                                new AdaptiveImage()
                                {
                                    Url     = new Uri("http://adaptivecards.io/content/airplane.png"),
                                    Size    = AdaptiveImageSize.Small,
                                    Spacing = AdaptiveSpacing.None,
                                }
                            }
                        },
                        new AdaptiveColumn()
                        {
                            Width = "1",
                            Items = new List <AdaptiveElement>()
                            {
                                new AdaptiveTextBlock()
                                {
                                    Text                = $"{flight.Arrival_City}",
                                    IsSubtle            = true,
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Right
                                },
                                new AdaptiveTextBlock()
                                {
                                    Text = $"{flight.Arrival_City_Code}",
                                    Size = AdaptiveTextSize.ExtraLarge,
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                    Color    = AdaptiveTextColor.Accent,
                                    Spacing  = AdaptiveSpacing.None,
                                    IsSubtle = true
                                },
                                new AdaptiveTextBlock()
                                {
                                    Text = $"Time: {flight.Arrival_Time.Hour}:{flight.Arrival_Time.Minute}",
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                    IsSubtle            = true
                                }
                            }
                        }
                    }
                });
                adaptiveCard.Body.Add(new AdaptiveTextBlock()
                {
                    Text      = $"Total: $ {flight.Price}",
                    Size      = AdaptiveTextSize.ExtraLarge,
                    Weight    = AdaptiveTextWeight.Bolder,
                    Separator = true,
                    IsSubtle  = false,
                });
                Attachment attachment = new Attachment()
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = adaptiveCard
                };
                attachments.Add(attachment);
            }
            return(attachments);
        }
        /// <summary>
        /// Returns an attachment based on the state and information of the ticket.
        /// </summary>
        /// <param name="ticketDetail"> ticket values entered by user.</param>
        /// <param name="applicationBasePath">Represents the Application base URI.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>Returns the attachment that will be sent in a message.</returns>
        public Attachment GetTicketDetailsForSMEChatCard(TicketDetail ticketDetail, string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            ticketDetail = ticketDetail ?? throw new ArgumentNullException(nameof(ticketDetail));

            Dictionary <string, string> ticketAdditionalDetail = JsonConvert.DeserializeObject <Dictionary <string, string> >(ticketDetail.AdditionalProperties);
            var dynamicElements        = new List <AdaptiveElement>();
            var ticketAdditionalFields = new List <AdaptiveElement>();

            foreach (KeyValuePair <string, string> item in ticketAdditionalDetail)
            {
                ticketAdditionalFields.Add(CardHelper.GetAdaptiveCardColumnSet(item.Key, item.Value));
            }

            dynamicElements.AddRange(new List <AdaptiveElement>
            {
                new AdaptiveColumnSet
                {
                    Columns = new List <AdaptiveColumn>
                    {
                        new AdaptiveColumn
                        {
                            Width = "12",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text   = localizer.GetString("RequestDetailsText"),
                                    Weight = AdaptiveTextWeight.Bolder,
                                    Size   = AdaptiveTextSize.Large,
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            Width = "3",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveImage
                                {
                                    Url       = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/images/Urgent.png", applicationBasePath?.Trim('/'))),
                                    Size      = AdaptiveImageSize.Large,
                                    AltText   = localizer.GetString("UrgentText"),
                                    IsVisible = ticketDetail.RequestType == Constants.UrgentString,
                                },
                            },
                        },
                    },
                },
                new AdaptiveTextBlock()
                {
                    Text    = localizer.GetString("SmeRequestDetailText", this.ticket.RequesterName),
                    Spacing = AdaptiveSpacing.None,
                },
                CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("RequestNumberText"), $"#{ticketDetail.RowKey}"),
                CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("RequestTypeText"), ticketDetail.RequestType),
                CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("RequestStatusText"), $"{(TicketState)ticketDetail.TicketStatus}"),
                CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("TitleDisplayText"), ticketDetail.Title),
            });
            dynamicElements.AddRange(ticketAdditionalFields);
            dynamicElements.Add(CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("DescriptionText"), ticketDetail.Description));

            AdaptiveCard getTicketDetailsForSMEChatCard = new AdaptiveCard(Constants.AdaptiveCardVersion)
            {
                Body    = dynamicElements,
                Actions = this.BuildActions(localizer),
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = getTicketDetailsForSMEChatCard,
            });
        }
Exemplo n.º 6
0
        public static Attachment CreateItemAttachment(ItemDto item)
        {
            string seperate          = ":      ";
            var    generalTitleBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "General",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var noBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(item.Number) + seperate + item.Number.ToString(),
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var nameBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(item.DisplayName) + seperate + item.DisplayName,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var generalColumnOne = new Column
            {
                items = new List <CardBlock> {
                    noBlock, nameBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var blockedBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(item.Blocked) + seperate + item.Blocked,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var categoryBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(item.ItemCategoryCode) + seperate + item.ItemCategoryCode,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var generalColumnTwo = new Column
            {
                items = new List <CardBlock> {
                    blockedBlock, categoryBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var generalSet = new ColumnSet
            {
                columns = new List <Column> {
                    generalColumnOne, generalColumnTwo
                },
                separator = true,
                spacing   = "medium",
                type      = "ColumnSet"
            };

            var PricingTitleBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "Pricing",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var unitPriceBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(item.UnitPrice) + seperate + item.UnitPrice,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var typeBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(item.Type) + seperate + item.Type,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var pricingColumnOne = new Column
            {
                items = new List <CardBlock> {
                    unitPriceBlock, typeBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var quantityUnitBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(item.Inventory) + seperate + item.Inventory,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var baseUnitBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(item.BaseUnitOfMeasure) + seperate + item.BaseUnitOfMeasure.Code,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var pricingColumnTwo = new Column
            {
                items = new List <CardBlock> {
                    quantityUnitBlock, baseUnitBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var pricingSet = new ColumnSet
            {
                columns = new List <Column> {
                    pricingColumnOne, pricingColumnTwo
                },
                separator = true,
                spacing   = "medium",
                type      = "ColumnSet"
            };


            var blocks = new List <CardBlock>();

            blocks.Add(generalTitleBlock);
            blocks.Add(generalSet);
            blocks.Add(PricingTitleBlock);
            blocks.Add(pricingSet);

            SmallerTextBlocks(blocks);
            var adaptiveCard = new AdaptiveCard
            {
                type    = "AdaptiveCard",
                schema  = null,
                version = "1.0",
                speak   = "Your Order have been confirmed",
                body    = blocks
            };

            var adaptive = JsonConvert.SerializeObject(adaptiveCard);
            var card     = JsonConvert.DeserializeObject(adaptive);

            var adaptiveCardAttachment = new Attachment
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content     = card
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 7
0
        public static Attachment CreatePostedSalesOrderAttachment(GetSalesOrderDto getSalesOrderDto,
                                                                  List <GetSalesOrderLineDto> salesOrderLinesDto, CustomerDto customerDto)
        {
            string seperate = ":      ";


            var numberBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "OrderNumber" + seperate + getSalesOrderDto.Number,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var generalTitleBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "General",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var customerNameBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(customerDto.DisplayName) + seperate + customerDto.DisplayName,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var orderDateBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text = nameof(getSalesOrderDto.OrderDate) + seperate +
                       getSalesOrderDto.OrderDate.Date.ToString("M/d/yy"),
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var generalColumnOne = new Column
            {
                items = new List <CardBlock> {
                    customerNameBlock, orderDateBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var requestedDelivaryBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = "DeliveryDate" + seperate + getSalesOrderDto.RequestedDeliveryDate.Date.ToString("M/d/yy"),
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var statusBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = "Status" + seperate + getSalesOrderDto.Status,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var generalColumnTwo = new Column
            {
                items = new List <CardBlock> {
                    requestedDelivaryBlock, statusBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var generalSet = new ColumnSet
            {
                columns = new List <Column> {
                    generalColumnOne, generalColumnTwo
                },
                separator = true,
                spacing   = "medium",
                type      = "ColumnSet"
            };


            var LinesTitleBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "Lines",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var descriptionBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Description",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var quantityBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "No.",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var unitOfMeasureBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Unit",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var unitPriceExcludingVatBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Unit Price",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var lineAmountExcludingVatBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Line Amount",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };


            var descriptionColumn = new Column
            {
                items = new List <CardBlock> {
                    descriptionBlock
                },
                type  = "Column",
                width = "4"
            };

            var quantityColumn = new Column
            {
                items = new List <CardBlock> {
                    quantityBlock
                },
                type  = "Column",
                width = "1"
            };

            var unitOfMeasureColumn = new Column
            {
                items = new List <CardBlock> {
                    unitOfMeasureBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var unitPriceExcludingVatColumn = new Column
            {
                items = new List <CardBlock> {
                    unitPriceExcludingVatBlock
                },
                type  = "Column",
                width = "3"
            };

            var lineAmountExcludingVatColumn = new Column
            {
                items = new List <CardBlock> {
                    lineAmountExcludingVatBlock
                },
                type  = "Column",
                width = "3"
            };

            foreach (var line in salesOrderLinesDto)
            {
                var descriptionLineBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "left",
                    isSubtle            = false,
                    text      = line.Description,
                    color     = null,
                    separator = false,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                var quantityLineBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "left",
                    isSubtle            = false,
                    text      = line.Quantity.ToString(),
                    color     = null,
                    separator = false,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                var unitOfMeasureLineBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "left",
                    isSubtle            = false,
                    text      = line.UnitOfMeasure.Code,
                    color     = null,
                    separator = false,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                var unitPriceExcludingVatLineBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "left",
                    isSubtle            = false,
                    text      = line.UnitPrice.ToString() + getSalesOrderDto.CurrencyCode,
                    color     = null,
                    separator = false,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                var lineAmountExcludingVatLineBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "left",
                    isSubtle            = false,
                    text      = line.AmountExcludingTax.ToString() + getSalesOrderDto.CurrencyCode,
                    color     = null,
                    separator = false,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                descriptionColumn.items.Add(descriptionLineBlock);
                quantityColumn.items.Add(quantityLineBlock);
                unitOfMeasureColumn.items.Add(unitOfMeasureLineBlock);
                unitPriceExcludingVatColumn.items.Add(unitPriceExcludingVatLineBlock);
                lineAmountExcludingVatColumn.items.Add(lineAmountExcludingVatLineBlock);
            }
            var TotalExcludingVatBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Total Ex. VAT:",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var TotalVatBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Total VAT:",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var TotalIncludingVatBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Total Inc. VAT:",
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            unitPriceExcludingVatColumn.items.Add(TotalExcludingVatBlock);
            unitPriceExcludingVatColumn.items.Add(TotalVatBlock);
            unitPriceExcludingVatColumn.items.Add(TotalIncludingVatBlock);

            var TotalExcludingVatAmountBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = getSalesOrderDto.TotalAmountExcludingTax.ToString() + getSalesOrderDto.CurrencyCode,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var TotalVatAmountBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = getSalesOrderDto.TotalTaxAmount.ToString() + getSalesOrderDto.CurrencyCode,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var TotalIncludingAmountVatBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = getSalesOrderDto.TotalAmountIncludingTax.ToString() + getSalesOrderDto.CurrencyCode,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            lineAmountExcludingVatColumn.items.Add(TotalExcludingVatAmountBlock);
            lineAmountExcludingVatColumn.items.Add(TotalVatAmountBlock);
            lineAmountExcludingVatColumn.items.Add(TotalIncludingAmountVatBlock);

            var linesSet = new ColumnSet
            {
                columns = new List <Column>
                {
                    descriptionColumn, quantityColumn, unitOfMeasureColumn, unitPriceExcludingVatColumn,
                    lineAmountExcludingVatColumn
                },
                separator = true,
                spacing   = "medium",
                type      = "ColumnSet"
            };


            var blocks = new List <CardBlock>();

            blocks.Add(numberBlock);
            blocks.Add(generalTitleBlock);
            blocks.Add(generalSet);
            blocks.Add(LinesTitleBlock);
            blocks.Add(linesSet);
            SmallerTextBlocks(blocks);
            var block = blocks[0] as TextBlock;

            block.size = "Large";
            blocks[0]  = block;
            var adaptiveCard = new AdaptiveCard
            {
                type    = "AdaptiveCard",
                schema  = null,
                version = "1.0",
                speak   = "Your Order have been confirmed",
                body    = blocks
            };

            var adaptive = JsonConvert.SerializeObject(adaptiveCard);
            var card     = JsonConvert.DeserializeObject(adaptive);

            var adaptiveCardAttachment = new Attachment
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content     = card
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 8
0
        /// <summary>
        /// User detail card attachment for given user profile.
        /// </summary>
        /// <param name="userDetail">User profile details.</param>
        /// <returns>User profile details card attachment.</returns>
        public static Attachment GetUserCard(Models.SharePoint.UserProfileDetail userDetail)
        {
            var skills    = string.IsNullOrEmpty(userDetail.Skills) ? Strings.NoneText : userDetail.Skills;
            var interests = string.IsNullOrEmpty(userDetail.Interests) ? Strings.NoneText : userDetail.Interests;
            var schools   = string.IsNullOrEmpty(userDetail.Schools) ? Strings.NoneText : userDetail.Schools;

            var userDetailCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextBlock
                    {
                        Text   = userDetail.PreferredName,
                        Wrap   = true,
                        Weight = AdaptiveTextWeight.Bolder,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = userDetail.JobTitle,
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = $"_{Strings.SkillsTitle}_",
                        Wrap = true,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = skills,
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveOpenUrlAction
                    {
                        Title = Strings.ChatTitle,
                        Url   = new System.Uri($"{InitiateChatUrl}{userDetail.WorkEmail}"),
                    },
                    new AdaptiveShowCardAction
                    {
                        Title = Strings.DetailsTitle,
                        Card  = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
                        {
                            Body = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text      = Strings.AboutMeTitle,
                                    Separator = true,
                                    Wrap      = true,
                                    Weight    = AdaptiveTextWeight.Bolder,
                                },
                                new AdaptiveTextBlock
                                {
                                    Text    = userDetail.AboutMe,
                                    Wrap    = true,
                                    Spacing = AdaptiveSpacing.None,
                                },
                                new AdaptiveTextBlock
                                {
                                    Text      = Strings.InterestTitle,
                                    Separator = true,
                                    Wrap      = true,
                                    Weight    = AdaptiveTextWeight.Bolder,
                                },
                                new AdaptiveTextBlock
                                {
                                    Text    = interests,
                                    Wrap    = true,
                                    Spacing = AdaptiveSpacing.None,
                                },
                                new AdaptiveTextBlock
                                {
                                    Text      = Strings.SchoolsTitle,
                                    Separator = true,
                                    Wrap      = true,
                                    Weight    = AdaptiveTextWeight.Bolder,
                                },
                                new AdaptiveTextBlock
                                {
                                    Text    = schools,
                                    Wrap    = true,
                                    Spacing = AdaptiveSpacing.None,
                                },
                            },
                            Actions = new List <AdaptiveAction>
                            {
                                new AdaptiveOpenUrlAction
                                {
                                    Title = Strings.GotoProfileTitle,
                                    Url   = new System.Uri($"{userDetail.Path}&v=profiledetails"),
                                },
                            },
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = userDetailCard,
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create adaptive card attachment for a team which needs to be sent after creating new event.
        /// </summary>
        /// <param name="applicationBasePath">Base URL of application.</param>
        /// <param name="localizer">String localizer for localizing user facing text.</param>
        /// <param name="eventEntity">Event details of newly created event.</param>
        /// <param name="createdByName">Name of person who created event.</param>
        /// <returns>An adaptive card attachment.</returns>
        public static Attachment GetEventCreationCardForTeam(string applicationBasePath, IStringLocalizer <Strings> localizer, EventEntity eventEntity, string createdByName)
        {
            eventEntity = eventEntity ?? throw new ArgumentNullException(nameof(eventEntity), "Event details cannot be null");

            AdaptiveCard lnDTeamCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Height = AdaptiveHeight.Auto,
                                Width  = AdaptiveColumnWidth.Auto,
                                Items  = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url = new Uri(eventEntity.Photo),
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        PixelHeight         = 45,
                                        PixelWidth          = 45,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = eventEntity.Name,
                                        Size   = AdaptiveTextSize.Large,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = eventEntity.CategoryName,
                                        Wrap    = true,
                                        Size    = AdaptiveTextSize.Small,
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Color   = AdaptiveTextColor.Warning,
                                        Spacing = AdaptiveSpacing.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DateAndTimeLabel")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = string.Format(CultureInfo.CurrentCulture, "{0} {1}-{2}", "{{DATE(" + eventEntity.StartDate.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ", SHORT)}}", "{{TIME(" + eventEntity.StartTime.Value.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}", "{{TIME(" + eventEntity.EndTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}"),
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = eventEntity.Type != (int)EventType.InPerson ? new List <AdaptiveColumn>() : new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Venue")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Venue,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DescriptionLabelCard")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Description,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("NumberOfRegistrations")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.RegisteredAttendeesCount.ToString(CultureInfo.InvariantCulture),
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = $"{localizer.GetString("CreatedByLabel")} **{createdByName}**",
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveImage
                    {
                        IsVisible           = eventEntity.Audience == (int)EventAudience.Private,
                        Url                 = new Uri($"{applicationBasePath}/images/Private.png"),
                        PixelWidth          = 84,
                        PixelHeight         = 32,
                        Spacing             = AdaptiveSpacing.Large,
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("EditEventCardButton"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type = "task/fetch",
                                Text = localizer.GetString("EditEventCardButton"),
                            },
                            Command = BotCommands.EditEvent,
                            EventId = eventEntity.EventId,
                            TeamId  = eventEntity.TeamId,
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("CloseRegistrationCardButton"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type = "task/fetch",
                                Text = localizer.GetString("CloseRegistrationCardButton"),
                            },
                            Command = BotCommands.CloseRegistration,
                            EventId = eventEntity.EventId,
                            TeamId  = eventEntity.TeamId,
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = lnDTeamCard,
            });
        }
Exemplo n.º 10
0
        public void Card()
        {
            AdaptiveCard card = new AdaptiveCard
            {
                BackgroundImage = new AdaptiveBackgroundImage
                {
                    Url = "https://www.stuff.com/background.jpg"
                },
                FallbackText             = "Fallback Text",
                Height                   = HeightType.Stretch,
                Language                 = "en",
                Speak                    = "This is a card",
                Style                    = ContainerStyle.Emphasis,
                Version                  = "1.3",
                VerticalContentAlignment = VerticalContentAlignment.Center,
            };

            Assert.AreEqual("https://www.stuff.com/background.jpg", card.BackgroundImage.Url);
            Assert.AreEqual("Fallback Text", card.FallbackText);
            Assert.AreEqual(HeightType.Stretch, card.Height);
            Assert.AreEqual("en", card.Language);
            Assert.AreEqual("This is a card", card.Speak);
            Assert.AreEqual(ContainerStyle.Emphasis, card.Style);
            Assert.AreEqual("1.3", card.Version);
            Assert.AreEqual(VerticalContentAlignment.Center, card.VerticalContentAlignment);

            card.SelectAction = new AdaptiveSubmitAction
            {
                Title = "Select Action"
            };
            Assert.IsNotNull(card.SelectAction);
            Assert.AreEqual("Select Action", card.SelectAction.Title);

            AdaptiveTextBlock textBlock = new AdaptiveTextBlock
            {
                Text = "This is a text block"
            };

            card.Body.Add(textBlock);

            AdaptiveTextBlock textBlock2 = new AdaptiveTextBlock
            {
                Text = "This is another text block"
            };

            card.Body.Add(textBlock2);

            Assert.AreEqual("This is a text block", (card.Body[0] as AdaptiveTextBlock).Text);
            Assert.AreEqual("This is another text block", (card.Body[1] as AdaptiveTextBlock).Text);

            AdaptiveSubmitAction submitAction = new AdaptiveSubmitAction
            {
                Title = "Submit One"
            };

            card.Actions.Add(submitAction);

            AdaptiveSubmitAction submitAction2 = new AdaptiveSubmitAction
            {
                Title = "Submit Two"
            };

            card.Actions.Add(submitAction2);

            Assert.AreEqual("Submit One", card.Actions[0].Title);
            Assert.AreEqual("Submit Two", card.Actions[1].Title);

            var jsonString = card.ToJson().ToString();

            Assert.AreEqual("{\"actions\":[{\"title\":\"Submit One\",\"type\":\"Action.Submit\"},{\"title\":\"Submit Two\",\"type\":\"Action.Submit\"}],\"backgroundImage\":\"https://www.stuff.com/background.jpg\",\"body\":[{\"text\":\"This is a text block\",\"type\":\"TextBlock\"},{\"text\":\"This is another text block\",\"type\":\"TextBlock\"}],\"fallbackText\":\"Fallback Text\",\"height\":\"Stretch\",\"lang\":\"en\",\"speak\":\"This is a card\",\"style\":\"Emphasis\",\"type\":\"AdaptiveCard\",\"version\":\"1.3\",\"verticalContentAlignment\":\"Center\"}", jsonString);
        }
        /// <summary>
        /// This method will construct the user welcome card when bot is added in team scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base URL.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>Welcome card.</returns>
        public static Attachment GetCard(string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(Constants.AdaptiveCardVersion))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/AppIcon.png", applicationBasePath?.Trim('/'))),
                                        Size = AdaptiveImageSize.Large,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Stretch,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = localizer.GetString("WelcomeCardTitle"),
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Large,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = localizer.GetString("WelcomeTeamCardContent"),
                                        Wrap    = true,
                                        Spacing = AdaptiveSpacing.None,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                        Text    = localizer.GetString("WelcomeSubHeaderText"),
                        Spacing = AdaptiveSpacing.Small,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("SetAdminBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("ManageAwardsBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("SetRewardCycleBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("NominateBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("ContentText"),
                        Spacing = AdaptiveSpacing.Small,
                    },
                },

                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("SetAdminButtonText"),
                        Data  = new AdaptiveCardAction
                        {
                            MsteamsCardAction = new CardAction
                            {
                                Type = Constants.FetchActionType,
                            },
                            Command = Constants.ConfigureAdminAction,
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = card,
            });
        }
Exemplo n.º 12
0
        private static void AddCurrentWeather(AirQuality model, AdaptiveCard card)
        {
            var headerContainer = new AdaptiveContainer();
            var header          = new AdaptiveColumnSet();

            card.Body.Add(headerContainer);
            var headerColumn = new AdaptiveColumn();
            var textHeader   = new AdaptiveTextBlock();

            textHeader.Size    = AdaptiveTextSize.Medium;
            textHeader.Weight  = AdaptiveTextWeight.Bolder;
            textHeader.Text    = "AQMD Air Quality";
            headerColumn.Width = AdaptiveColumnWidth.Stretch;
            headerColumn.Items.Add(textHeader);
            header.Columns.Add(headerColumn);
            headerContainer.Bleed = true;
            headerContainer.Style = AdaptiveContainerStyle.Default;
            headerContainer.Items.Add(header);

            var bodyContainer = new AdaptiveContainer();
            var data          = new AdaptiveFactSet();

            data.Spacing = AdaptiveSpacing.ExtraLarge;
            data.Facts.Add(new AdaptiveFact()
            {
                Title = "Area Number", Value = model.AreaNumber.ToString()
            });
            data.Facts.Add(new AdaptiveFact()
            {
                Title = "Area Name", Value = model.AreaName.ToString()
            });
            data.Facts.Add(new AdaptiveFact()
            {
                Title = "AQI  Value", Value = model.AQI.ToString()
            });
            data.Facts.Add(new AdaptiveFact()
            {
                Title = "Reading Date", Value = model.ForecastDateTime.ToString()
            });
            data.Facts.Add(new AdaptiveFact()
            {
                Title = "AQI Category", Value = model.AQICategory.ToString()
            });
            data.Facts.Add(new AdaptiveFact()
            {
                Title = "Pollutants", Value = model.Pollutant.ToString()
            });
            bodyContainer.Items.Add(data);
            card.Body.Add(bodyContainer);
            var detailContainer = new AdaptiveContainer();

            detailContainer.Id = "details1";
            var info = new AdaptiveFactSet();

            info.Spacing = AdaptiveSpacing.ExtraLarge;
            info.Facts.Add(new AdaptiveFact()
            {
                Title = "Ozone", Value = model.Ozone.ToString()
            });
            info.Facts.Add(new AdaptiveFact()
            {
                Title = "PM 10", Value = model.PMTen.ToString()
            });
            info.Facts.Add(new AdaptiveFact()
            {
                Title = "PM 2.5", Value = model.PMTwoFive.ToString()
            });
            detailContainer.Items.Add(info);
            card.Body.Add(detailContainer);
            // body.Facts.Add(new AdaptiveFact() { Title = "Area Name", Value = model.AreaNumber.ToString() });

            //card.Actions.Add(new AdaptiveToggleVisibilityAction { Title = "Show Detail", TargetElements = new List<AdaptiveTargetElement> { "details1" } });
            //var showdetailContainer = new AdaptiveContainer();
            //var showDetailColumnSet = new AdaptiveColumnSet();
            //card.Body.Add(showdetailContainer);
            //var showDetailColumn = new AdaptiveColumn();
            //showDetailColumn.Id = "chevronDown4";
            //showDetailColumn.SelectAction.Type = "Action.ToggleVisibility";
            //showDetailColumn.SelectAction.Title = "show detail";
            //showDetailColumn.SelectAction. = "show detail";
            //var textHeader = new AdaptiveTextBlock();
            //textHeader.Size = AdaptiveTextSize.Medium;
            //textHeader.Weight = AdaptiveTextWeight.Bolder;
            //textHeader.Text = "AQMD Air Quality";
            //headerColumn.Width = AdaptiveColumnWidth.Stretch;
            //headerColumn.Items.Add(textHeader);
            //header.Columns.Add(headerColumn);
            //headerContainer.Bleed = true;
            //headerContainer.Style = AdaptiveContainerStyle.Default;
            //headerContainer.Items.Add(header);

            //card.Body.Add(headerContainer);

            //var headerColumn = new AdaptiveColumn();
            //var textHeader = new AdaptiveTextBlock();
            //textHeader.Size = AdaptiveTextSize.Medium;
            //textHeader.Weight = AdaptiveTextWeight.Bolder;
            //textHeader.Text = "AQMD Air Quality";
            //headerColumn.Width = AdaptiveColumnWidth.Auto;
            //headerColumn.Items.Add(textHeader);
            //header.Columns.Add(headerColumn);
            //headerContainer.Items.Add(header);

            //var currentContainer = new AdaptiveContainer();
            //currentContainer.Style = AdaptiveContainerStyle.Emphasis;
            //var current = new AdaptiveColumnSet();


            //card.Body.Add(currentContainer);



            //var currentColumn2 = new Column();
            //current.Columns.Add(currentColumn2);
            //currentColumn2.Size = "65";

            //string date = DateTime.Parse(model.current.last_updated).DayOfWeek.ToString();

            //AddTextBlock(currentColumn2, $"{model.location.name} ({date})", TextSize.Large, false);
            //AddTextBlock(currentColumn2, $"{model.current.temp_f.ToString().Split('.')[0]}° F", TextSize.Large);
            //AddTextBlock(currentColumn2, $"{model.current.condition.text}", TextSize.Medium);
            //AddTextBlock(currentColumn2, $"Winds {model.current.wind_mph} mph {model.current.wind_dir}", TextSize.Medium);
        }
Exemplo n.º 13
0
        /// <summary>
        /// This method will construct the user welcome card when bot is added in personal scope.
        /// </summary>
        /// <param name="welcomeText">Gets welcome text.</param>
        /// <returns>User welcome card.</returns>
        public static Attachment GetCard(string welcomeText)
        {
            AdaptiveCard userWelcomeCard = new AdaptiveCard("1.0")
            {
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.ComoSacoTurno,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.ComoSacoTurno,
                                Text        = AskHRBot.ComoSacoTurno
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.ComoCanceloTurno,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.ComoCanceloTurno,
                                Text        = AskHRBot.ComoCanceloTurno
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.QueHagoRetire,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.QueHagoRetire,
                                Text        = AskHRBot.QueHagoRetire
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.QuePuedoRetirar,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.QuePuedoRetirar,
                                Text        = AskHRBot.QuePuedoRetirar
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.ComoTrasladoEdificio,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.ComoTrasladoEdificio,
                                Text        = AskHRBot.ComoTrasladoEdificio
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.ComoReservoCochera,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.ComoReservoCochera,
                                Text        = AskHRBot.ComoReservoCochera
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.ComoSolicitoTaxi,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.ComoSolicitoTaxi,
                                Text        = AskHRBot.ComoSolicitoTaxi
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.ComoGenerousuario,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.ComoGenerousuario,
                                Text        = AskHRBot.ComoGenerousuario
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.ComoTiempo,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.ComoTiempo,
                                Text        = AskHRBot.ComoTiempo
                            }
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = AskHRBot.PuedoSolicitar,
                        Data  = new TeamsAdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = AskHRBot.PuedoSolicitar,
                                Text        = AskHRBot.PuedoSolicitar
                            }
                        },
                    }
                }
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = userWelcomeCard,
            });
        }
        /// <summary>
        /// Get welcome card attachment to show on Microsoft Teams personal scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base path to get the logo of the application.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="applicationManifestId">Application manifest id.</param>
        /// <param name="discoverTabEntityId">Discover tab entity id for personal Bot.</param>
        /// <returns>User welcome card attachment.</returns>
        public static Attachment GetWelcomeCardAttachmentForPersonal(
            string applicationBasePath,
            IStringLocalizer <Strings> localizer,
            string applicationManifestId,
            string discoverTabEntityId)
        {
            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri($"{applicationBasePath}/Artifacts/applicationLogo.png"),
                                        Size = AdaptiveImageSize.Medium,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Spacing = AdaptiveSpacing.None,
                                        Text    = localizer.GetString("WelcomeCardTitle"),
                                        Wrap    = true,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Spacing  = AdaptiveSpacing.None,
                                        Text     = localizer.GetString("WelcomeCardContent"),
                                        Wrap     = true,
                                        IsSubtle = true,
                                        Size     = AdaptiveTextSize.Small,
                                    },
                                },
                                Width = AdaptiveColumnWidth.Stretch,
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardDescriptionText"),
                        Wrap = true,
                        Size = AdaptiveTextSize.Medium,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardGetStartedText"),
                        Wrap = true,
                        Size = AdaptiveTextSize.Medium,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveOpenUrlAction
                    {
                        Title = localizer.GetString("PersonalWelcomeCardDiscoverButtonText"),
                        Url   = new Uri($"https://teams.microsoft.com/l/entity/{applicationManifestId}/{discoverTabEntityId}"), // All projects tab (deep link).
                    },
                },
            };
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card,
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 15
0
        private static IMessageActivity GetAdaptiveCardMessage(IDialogContext context, AskQuestionRequest request, AskQuestionResult result)
        {
            // Create message
            IMessageActivity message = context.MakeMessage();

            // Create adaptive card
            AdaptiveCard card = new AdaptiveCard();

            if (string.IsNullOrEmpty(result.Title) == false)
            {
                card.Body.Add(new AdaptiveTextBlock()
                {
                    Text = result.Title,
                    Size = AdaptiveTextSize.Large,
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                    IsSubtle            = false,
                    Weight = AdaptiveTextWeight.Bolder,
                    Wrap   = true
                });
            }

            if (string.IsNullOrEmpty(result.Answer) == false)
            {
                card.Body.Add(new AdaptiveTextBlock()
                {
                    Text = result.Answer,
                    Size = AdaptiveTextSize.Medium,
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                    IsSubtle            = false,
                    Wrap = true
                });
            }

            if (string.IsNullOrEmpty(result.ImageUrl) == false)
            {
                AdaptiveImage currentImage = new AdaptiveImage();
                currentImage.Url  = new Uri(result.ImageUrl);
                currentImage.Size = AdaptiveImageSize.Stretch;
                card.Body.Add(currentImage);
            }

            if (string.IsNullOrEmpty(result.Url) == false)
            {
                card.Actions.Add(new AdaptiveOpenUrlAction()
                {
                    Title = string.IsNullOrEmpty(result.UrlDisplayName) == false ? result.UrlDisplayName : "Open Url...",
                    Url   = new Uri(result.Url)
                });
            }

            // Attach card to message
            Attachment attachment = new Attachment()
            {
                Content     = card,
                ContentType = "application/vnd.microsoft.card.adaptive"
            };

            message.Attachments.Add(attachment);

            return(message);
        }
Exemplo n.º 16
0
        public async Task aBot(IDialogContext context, IAwaitable <IMessageActivity> argument)//broadcasts the message
        {
            var      result = await argument;
            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Attachments = new List <Attachment>();
            AdaptiveCard card = new AdaptiveCard();


            Models.DBotDBEntities db = new Models.DBotDBEntities();
            var sendLists            = (from DbotTable in db.DbotTables
                                        where DbotTable.conversationID != null
                                        select DbotTable)
                                       .ToList();

            foreach (var sendList in sendLists)
            {
                toId           = sendList.toID;
                toName         = sendList.toName;
                fromId         = sendList.fromID;
                fromName       = sendList.fromName;
                serviceURL     = sendList.serviceURL;
                conversationID = sendList.conversationID;
                channelID      = sendList.channelID;
                status         = sendList.Status;
                date           = sendList.Date;

                var userAccount = new ChannelAccount(toId, toName);
                var botAccount  = new ChannelAccount(fromId, fromName);
                var connector   = new ConnectorClient(new Uri(serviceURL));

                IMessageActivity message = Activity.CreateMessageActivity();
                if (!string.IsNullOrEmpty(conversationID) && !string.IsNullOrEmpty(channelID))
                {
                    replyToConversation.ChannelId = channelID;
                }
                else
                {
                    conversationID = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
                }

                // Set the address-related properties in the message and send the message.
                //message.From = botAccount;
                //message.Recipient = userAccount;
                //message.Conversation = new ConversationAccount(id: conversationID);
                //message.Text = "Delivery status: " + status + " .Delivery date: " + date;
                //message.Locale = "en-Us";
                replyToConversation.From         = botAccount;
                replyToConversation.Recipient    = userAccount;
                replyToConversation.Conversation = new ConversationAccount(id: conversationID);
                replyToConversation.Locale       = "en-Us";

                card.Body.Add(new TextBlock()
                {
                    Text   = "Daily Update",
                    Size   = TextSize.Large,
                    Weight = TextWeight.Bolder
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Delivery status: " + status
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Delivery Date: " + date
                });

                Attachment attachment = new Attachment()
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = card
                };
                card.Speak = "Update coming";
                replyToConversation.Attachments.Add(attachment);


                await connector.Conversations.SendToConversationAsync(replyToConversation);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// This method will construct the card for ask an expert bot menu.
        /// </summary>
        /// <param name="cardPayload">Data from the ask an expert card.</param>
        /// <param name="showValidationErrors">Determines whether we show validation errors.</param>
        /// <returns>Ask an expert card.</returns>
        private static Attachment GetCard(AskAnExpertCardPayload cardPayload, bool showValidationErrors)
        {
            AdaptiveCard askAnExpertCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextBlock
                    {
                        Weight = AdaptiveTextWeight.Bolder,
                        Text   = Strings.AskAnExpertTitleText,
                        Size   = AdaptiveTextSize.Large,
                        Wrap   = true,
                    },
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = Strings.TitleRequiredText,
                                        Wrap = true,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text  = (showValidationErrors && string.IsNullOrWhiteSpace(cardPayload?.Title)) ? Strings.MandatoryTitleFieldText : string.Empty,
                                        Color = AdaptiveTextColor.Attention,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveTextInput
                    {
                        Id          = nameof(AskAnExpertCardPayload.Title),
                        Placeholder = Strings.ShowCardTitleText,
                        IsMultiline = false,
                        Spacing     = AdaptiveSpacing.Small,
                        Value       = cardPayload?.Title,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = Strings.DescriptionLabel,
                        Wrap = true,
                    },
                    new AdaptiveTextInput
                    {
                        Id          = nameof(AskAnExpertCardPayload.Description),
                        Placeholder = Strings.AskAnExpertPlaceholderText,
                        IsMultiline = true,
                        Spacing     = AdaptiveSpacing.Small,
                        Value       = cardPayload?.Description,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = Strings.AskAnExpertButtonText,
                        Data  = new AskAnExpertCardPayload
                        {
                            MsTeams = new CardAction
                            {
                                Type        = ActionTypes.MessageBack,
                                DisplayText = Strings.AskAnExpertDisplayText,
                                Text        = AskAnExpertSubmitText,
                            },
                            UserQuestion          = cardPayload?.UserQuestion,
                            KnowledgeBaseAnswer   = cardPayload?.KnowledgeBaseAnswer,
                            KnowledgeBaseQuestion = cardPayload?.KnowledgeBaseQuestion,
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = askAnExpertCard,
            });
        }
Exemplo n.º 18
0
        //public virtual async Task wBot(IDialogContext context, IAwaitable<IMessageActivity> argument)
        //{
        //    await context.PostAsync("Hi Awesome ! I am delivery bot!Just tell me your order number");
        //    context.Wait(oBot);
        //}

        public virtual async Task oBot(IDialogContext context, IAwaitable <IMessageActivity> argument)//display the status
        {
            var value     = await argument;
            var connector = new ConnectorClient(new Uri(value.ServiceUrl));

            orderNumber = Convert.ToString(value.Text);
            Models.DBotDBEntities db = new Models.DBotDBEntities();
            var sStatus = (from DbotTable in db.DbotTables
                           where DbotTable.OrderNumber == orderNumber
                           select DbotTable.Status);

            status = Convert.ToString(sStatus.FirstOrDefault());
            var dDate = (from DbotTable in db.DbotTables
                         where DbotTable.OrderNumber == orderNumber
                         select DbotTable.Date);

            date = Convert.ToString(dDate.FirstOrDefault());
            var dOrderName = (from DbotTable in db.DbotTables
                              where DbotTable.OrderNumber == orderNumber
                              select DbotTable.OrderName);

            OrderName = Convert.ToString(dOrderName.FirstOrDefault());
            var dTags = (from DbotTable in db.DbotTables
                         where DbotTable.OrderNumber == orderNumber
                         select DbotTable.PTAGS);

            tags = Convert.ToString(dTags.FirstOrDefault());

            var dimageLink = (from adTable in db.adTables
                              where adTable.Tags == tags
                              select adTable.PhotoLinks);

            imageLink = Convert.ToString(dimageLink.FirstOrDefault());

            var dproductLink = (from adTable in db.adTables
                                where adTable.Tags == tags
                                select adTable.ProductLinks);

            productLink = Convert.ToString(dproductLink.FirstOrDefault());



            if (status == null || date == null)
            {
                await context.PostAsync("No such record");

                context.Wait(usertBot);
            }
            else
            {
                Activity replyToConversation = (Activity)context.MakeMessage();
                replyToConversation.Attachments = new List <Attachment>();
                AdaptiveCard card = new AdaptiveCard();
                card.Body.Add(new TextBlock()
                {
                    Text   = "Result",
                    Size   = TextSize.Normal,
                    Weight = TextWeight.Bolder
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Order Name: " + OrderName
                });
                card.Body.Add(new TextBlock()
                {
                    Text = "Delivery Date: " + date + " , " + "Delivery status: " + status
                });
                card.Body.Add(new TextBlock()
                {
                    Text   = "This can be handy",
                    Size   = TextSize.Normal,
                    Weight = TextWeight.Bolder
                });
                card.Body.Add(new Image()
                {
                    Url   = imageLink,
                    Size  = ImageSize.Stretch,
                    Style = ImageStyle.Normal
                });
                card.Actions.Add(new OpenUrlAction()
                {
                    Url   = productLink,
                    Type  = "Action.OpenUrl",
                    Title = "Buy"
                });



                Attachment attachment = new Attachment()
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = card
                };
                replyToConversation.Attachments.Add(attachment);
                await connector.Conversations.SendToConversationAsync(replyToConversation);

                context.Wait(msBot);
            }
        }
Exemplo n.º 19
0
        public static Attachment CreateSalesOrderAttachment(List <SalesOrderLine> lines)
        {
            var titleBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "Sales Order Items",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var itemBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = "Item",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var quantityBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "center",
                isSubtle            = false,
                text      = "Quantity",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var pricesBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "right",
                isSubtle            = false,
                text      = "Total Price",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var itemColumn = new Column
            {
                type  = "Column",
                width = "1.2",
                items = new List <CardBlock> {
                    itemBlock
                }
            };

            var quantityColumn = new Column
            {
                type  = "Column",
                width = "1.2",
                items = new List <CardBlock> {
                    quantityBlock
                }
            };

            var priceColumn = new Column
            {
                type  = "Column",
                width = "1.2",
                items = new List <CardBlock> {
                    pricesBlock
                }
            };

            var headerSet = new ColumnSet
            {
                separator = false,
                spacing   = "medium",
                type      = "ColumnSet",
                columns   = new List <Column> {
                    itemColumn, quantityColumn, priceColumn
                }
            };

            var sets = new List <ColumnSet>();

            sets.Add(headerSet);

            foreach (var line in lines)
            {
                var lineNameBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "left",
                    isSubtle            = false,
                    text      = line.Item.DisplayName,
                    color     = null,
                    separator = true,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                var lineQuantityBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "center",
                    isSubtle            = false,
                    text      = line.Quantity.ToString(),
                    color     = null,
                    separator = true,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                var linePriceBlock = new TextBlock
                {
                    type = "TextBlock",
                    horizontalAlignment = "right",
                    isSubtle            = false,
                    text      = line.Quantity * line.UnitPrice + "$",
                    color     = null,
                    separator = true,
                    size      = null,
                    spacing   = null,
                    weight    = null
                };

                var lineNameColumn = new Column
                {
                    type  = "Column",
                    width = "1.2",
                    items = new List <CardBlock> {
                        lineNameBlock
                    }
                };

                var lineQuantityColumn = new Column
                {
                    type  = "Column",
                    width = "1.2",
                    items = new List <CardBlock> {
                        lineQuantityBlock
                    }
                };

                var linePriceColumn = new Column
                {
                    type  = "Column",
                    width = "1.2",
                    items = new List <CardBlock> {
                        linePriceBlock
                    }
                };

                var set = new ColumnSet
                {
                    separator = false,
                    spacing   = "medium",
                    type      = "ColumnSet",
                    columns   = new List <Column> {
                        lineNameColumn, lineQuantityColumn, linePriceColumn
                    }
                };

                sets.Add(set);
            }

            var blocks = new List <CardBlock>();

            blocks.Add(titleBlock);
            blocks.AddRange(sets);
            SmallerTextBlocks(blocks);
            var adaptiveCard = new AdaptiveCard
            {
                type    = "AdaptiveCard",
                schema  = null,
                version = "1.0",
                speak   = "Your Order have been confirmed",
                body    = blocks
            };

            var adaptive = JsonConvert.SerializeObject(adaptiveCard);
            var card     = JsonConvert.DeserializeObject(adaptive);

            var adaptiveCardAttachment = new Attachment
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content     = card
            };

            return(adaptiveCardAttachment);
        }
        /// <summary>
        /// Get adaptive card attachment for sending event updation card to attendees.
        /// </summary>
        /// <param name="localizer">String localizer for localizing user facing text.</param>
        /// <param name="eventEntity">Event details which is cancelled.</param>
        /// <param name="applicationManifestId">The unique manifest ID for application</param>
        /// <returns>An adaptive card attachment.</returns>
        public static Attachment GetEventUpdateCard(IStringLocalizer <Strings> localizer, EventEntity eventEntity, string applicationManifestId)
        {
            eventEntity = eventEntity ?? throw new ArgumentNullException(nameof(eventEntity), "Event details cannot be null");

            AdaptiveCard autoRegisteredCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("EventUpdatedCardTitle")}**",
                                        Size   = AdaptiveTextSize.Large,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Height = AdaptiveHeight.Auto,
                                Width  = AdaptiveColumnWidth.Auto,
                                Items  = !string.IsNullOrEmpty(eventEntity.Photo) ? new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url = new Uri(eventEntity.Photo),
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        PixelHeight         = 45,
                                        PixelWidth          = 45,
                                    },
                                }
                                :
                                new List <AdaptiveElement>(),
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = eventEntity.Name,
                                        Size   = AdaptiveTextSize.Default,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = eventEntity.CategoryName,
                                        Wrap    = true,
                                        Size    = AdaptiveTextSize.Small,
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Color   = AdaptiveTextColor.Warning,
                                        Spacing = AdaptiveSpacing.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DateAndTimeLabel")}:**",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = string.Format(CultureInfo.CurrentCulture, "{0} {1}-{2}", "{{DATE(" + eventEntity.StartDate.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ", SHORT)}}", "{{TIME(" + eventEntity.StartTime.Value.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}", "{{TIME(" + eventEntity.EndTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}"),
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = eventEntity.Type != (int)EventType.InPerson ? new List <AdaptiveColumn>() : new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Venue")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Venue,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Description")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Description,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.ExtraLarge,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveActionSet
                                    {
                                        Actions = new List <AdaptiveAction>
                                        {
                                            new AdaptiveOpenUrlAction
                                            {
                                                Url   = new Uri($"https://teams.microsoft.com/l/entity/{applicationManifestId}/my-events"),
                                                Title = $"{localizer.GetString("ReminderCardRegisteredEventButton")}",
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = autoRegisteredCard,
            });
        }
Exemplo n.º 21
0
        public static Attachment CreateCustomerAttachment(CustomerDto customer)
        {
            string seperate          = ":      ";
            var    generalTitleBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "General",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var noBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(customer.Number) + seperate + customer.Number.ToString(),
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var nameBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.DisplayName) + seperate + customer.DisplayName,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var balanceBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.Balance) + seperate + customer.Balance,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var balanceDueBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.OverdueAmount) + seperate + customer.OverdueAmount,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var generalColumnOne = new Column
            {
                items = new List <CardBlock> {
                    noBlock, nameBlock, balanceBlock, balanceDueBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var blockedBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(customer.Blocked) + seperate + customer.Blocked,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var totalSalesBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.TotalSalesExcludingTax) + seperate + customer.TotalSalesExcludingTax,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var generalColumnTwo = new Column
            {
                items = new List <CardBlock> {
                    blockedBlock, totalSalesBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var generalSet = new ColumnSet
            {
                columns = new List <Column> {
                    generalColumnOne, generalColumnTwo
                },
                separator = true,
                spacing   = "medium",
                type      = "ColumnSet"
            };

            var contactTitleBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Center",
                isSubtle            = false,
                text      = "Address & Contact",
                color     = null,
                separator = true,
                size      = null,
                spacing   = null,
                weight    = "bolder"
            };

            var addressBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(customer.Address.Street) + seperate + customer.Address.Street.ToString(),
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var cityBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.Address.City) + seperate + customer.Address.City,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var stateBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.Address.State) + seperate + customer.Address.State,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var postCodeDueBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.Address.PostalCode) + seperate + customer.Address.PostalCode,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var countryCodeDueBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.Address.CountryLetterCode) + seperate + customer.Address.CountryLetterCode,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var contactColumnOne = new Column
            {
                items = new List <CardBlock> {
                    addressBlock, cityBlock, stateBlock, postCodeDueBlock, countryCodeDueBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var phoneBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "Left",
                isSubtle            = false,
                text      = nameof(customer.PhoneNumber) + seperate + customer.PhoneNumber,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var emailBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.Email) + seperate + customer.Email,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var homepageBlock = new TextBlock
            {
                type = "TextBlock",
                horizontalAlignment = "left",
                isSubtle            = false,
                text      = nameof(customer.Website) + seperate + customer.Website,
                color     = null,
                separator = false,
                size      = null,
                spacing   = null,
                weight    = null
            };

            var contactColumnTwo = new Column
            {
                items = new List <CardBlock> {
                    phoneBlock, emailBlock, homepageBlock
                },
                type  = "Column",
                width = "1.5"
            };

            var contactSet = new ColumnSet
            {
                columns = new List <Column> {
                    contactColumnOne, contactColumnTwo
                },
                separator = true,
                spacing   = "medium",
                type      = "ColumnSet"
            };


            var blocks = new List <CardBlock>();

            blocks.Add(generalTitleBlock);
            blocks.Add(generalSet);
            blocks.Add(contactTitleBlock);
            blocks.Add(contactSet);

            SmallerTextBlocks(blocks);
            var adaptiveCard = new AdaptiveCard
            {
                type    = "AdaptiveCard",
                schema  = null,
                version = "1.0",
                speak   = "Your Order have been confirmed",
                body    = blocks
            };
            var adaptive = JsonConvert.SerializeObject(adaptiveCard);
            var card     = JsonConvert.DeserializeObject(adaptive);

            var adaptiveCardAttachment = new Attachment
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content     = card
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 22
0
        public static FrameworkElement RenderAdaptiveCardWrapper(AdaptiveCard card, AdaptiveRenderContext context)
        {
            var outerGrid = new Grid();

            outerGrid.Style      = context.GetStyle("Adaptive.Card");
            outerGrid.Background = context.GetColorBrush(context.Config.ContainerStyles.Default.BackgroundColor);
            outerGrid.SetBackgroundSource(card.BackgroundImage, context);

            if (context.CardRoot == null)
            {
                context.CardRoot = outerGrid;
            }

            var grid = new Grid();

            grid.Style  = context.GetStyle("Adaptive.InnerCard");
            grid.Margin = new Thickness(context.Config.Spacing.Padding);

            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });

            switch (card.VerticalContentAlignment)
            {
            case AdaptiveVerticalContentAlignment.Center:
                grid.VerticalAlignment = VerticalAlignment.Center;
                break;

            case AdaptiveVerticalContentAlignment.Bottom:
                grid.VerticalAlignment = VerticalAlignment.Bottom;
                break;

            case AdaptiveVerticalContentAlignment.Top:
            default:
                break;
            }

            AdaptiveContainerRenderer.AddContainerElements(grid, card.Body, context);
            AdaptiveActionSetRenderer.AddActions(grid, card.Actions, context);

            // Only handle Action show cards for the main card
            if (context.CardDepth == 1)
            {
                // Define a new row to contain all the show cards
                if (context.ActionShowCards.Count > 0)
                {
                    grid.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = GridLength.Auto
                    });
                }

                foreach (var showCardTuple in context.ActionShowCards)
                {
                    var currentShowCard = showCardTuple.Item1;
                    var uiButton        = showCardTuple.Item2;

                    Grid.SetRow(currentShowCard, grid.RowDefinitions.Count - 1);
                    grid.Children.Add(currentShowCard);

                    // Assign on click function to all button elements
                    uiButton.Click += (sender, e) =>
                    {
                        bool isCardCollapsed = (currentShowCard.Visibility != Visibility.Visible);

                        // Collapse all the show cards
                        foreach (var t in context.ActionShowCards)
                        {
                            var showCard = t.Item1;
                            showCard.Visibility = Visibility.Collapsed;
                        }

                        // If current card is previously collapsed, show it
                        if (isCardCollapsed)
                        {
                            currentShowCard.Visibility = Visibility.Visible;
                        }
                    };
                }
            }

            outerGrid.Children.Add(grid);

            if (card.SelectAction != null)
            {
                var outerGridWithSelectAction = context.RenderSelectAction(card.SelectAction, outerGrid);

                return(outerGridWithSelectAction);
            }

            return(outerGrid);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Get welcome card attachment to show on Microsoft Teams personal scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base URL.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>User welcome card attachment.</returns>
        public static Attachment GetWelcomeCardAttachmentForPersonal(string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri($"{applicationBasePath}/Artifacts/appLogo.png"),
                                        Size = AdaptiveImageSize.Medium,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Weight  = AdaptiveTextWeight.Default,
                                        Spacing = AdaptiveSpacing.None,
                                        Text    = localizer.GetString("WelcomeCardTitle"),
                                        Wrap    = true,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Spacing  = AdaptiveSpacing.None,
                                        Text     = localizer.GetString("WelcomeCardContent"),
                                        Wrap     = true,
                                        IsSubtle = true,
                                    },
                                },
                                Width = AdaptiveColumnWidth.Stretch,
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardThingsContentText"),
                        Wrap = true,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardResponseListContentText"),
                        Wrap = true,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardSuggestResponseContentText"),
                        Wrap = true,
                    },
                },
            };
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card,
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 24
0
        private async Task <RenderedAdaptiveCardImage> RenderCardToImageInternalAsync(AdaptiveCard card, int width, CancellationToken cancellationToken)
        {
            RenderedAdaptiveCardImage renderCard = null;

            try
            {
                var cardAssets = await LoadAssetsForCardAsync(card, cancellationToken);

                var context = new AdaptiveRenderContext(null, null, null)
                {
                    CardAssets        = cardAssets,
                    ResourceResolvers = ResourceResolvers,
                    ActionHandlers    = ActionHandlers,
                    Config            = HostConfig ?? new AdaptiveHostConfig(),
                    Resources         = Resources,
                    ElementRenderers  = ElementRenderers,
                    Lang             = card.Lang,
                    ForegroundColors = (HostConfig != null) ? HostConfig.ContainerStyles.Default.ForegroundColors : new ContainerStylesConfig().Default.ForegroundColors
                };

                var stream = context.Render(card).RenderToImage(width);
                renderCard = new RenderedAdaptiveCardImage(stream, card, context.Warnings);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"RENDER Failed. {e.Message}");
            }

            return(renderCard);
        }
Exemplo n.º 25
0
        //private async Task<DialogTurnResult> UserSignInStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        //{

        //    var signInMessage = MessageFactory.Text("Would you like to sign-in into your dignity health account?", null, InputHints.ExpectingInput);
        //    return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = signInMessage }, cancellationToken);

        //}

        private async Task <DialogTurnResult> UserSignInStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var choices = new[] { "Sign-in" };

            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                Body =
                {
                    new AdaptiveTextBlock
                    {
                        Text  = "Login in to Dignity Health",
                        Size  = AdaptiveTextSize.ExtraLarge,
                        Color = AdaptiveTextColor.Good
                    },
                    new AdaptiveTextBlock
                    {
                        Text = "Email:",
                        Wrap = true
                    },
                    new AdaptiveTextInput
                    {
                        //IsRequired = true,
                        // ErrorMessage = "Please enter a valid email",
                        Id    = "Email",
                        Value = "sample"
                                //Style = AdaptiveTextInputStyle.Email
                                // Style = AdaptiveTextInputStyle.Text
                    },
                    new AdaptiveTextBlock
                    {
                        Text = "Password:"******"Please provide a valid input",
                        Id    = "Password",
                        Value = "sample"
                                //Style = AdaptiveTextInputStyle.Text
                    }
                },
                Actions =
                {
                    new AdaptiveSubmitAction
                    {
                        Title = "Submit",
                        Style = "Positive",
                        Data  = "Submit"
                    }
                }
            };

            return(await stepContext.PromptAsync(
                       nameof(TextPrompt),
                       new PromptOptions
            {
                Prompt = (Activity)MessageFactory.Attachment(new Attachment
                {
                    ContentType = AdaptiveCard.ContentType,
                    // Convert the AdaptiveCard to a JObject
                    Content = JObject.FromObject(card),
                }),
                //Choices = ChoiceFactory.ToChoices(choices),
                // Don't render the choices outside the card
                Style = ListStyle.None,
            },
                       cancellationToken));

            //return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);
        }
        /// <summary>
        /// Get result for messaging extension tab.
        /// </summary>
        /// <param name="searchServiceResults">List of tickets from Azure search service.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="commandId">Command id to determine which tab in message extension has been invoked.</param>
        /// <param name="onCallSMEUsers">OncallSMEUsers to give support from group-chat or on-call.</param>
        /// <returns><see cref="Task"/> Returns MessagingExtensionResult which will be shown in messaging extension tab.</returns>
        public static MessagingExtensionResult GetMessagingExtensionResult(
            IList <TicketDetail> searchServiceResults,
            IStringLocalizer <Strings> localizer,
            string commandId      = "",
            string onCallSMEUsers = "")
        {
            MessagingExtensionResult composeExtensionResult = new MessagingExtensionResult
            {
                Type             = "result",
                AttachmentLayout = AttachmentLayoutTypes.List,
                Attachments      = new List <MessagingExtensionAttachment>(),
            };

            if (searchServiceResults != null)
            {
                foreach (var ticket in searchServiceResults)
                {
                    var dynamicElements = new List <AdaptiveElement>
                    {
                        CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("RequestNumberText"), $"#{ticket.TicketId}"),
                        CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("TitleDisplayText"), ticket.Title),
                        CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("DescriptionText"), ticket.Description),
                        CardHelper.GetAdaptiveCardColumnSet(localizer.GetString("CreatedOnText"), ticket.CreatedOn.ToString(CultureInfo.InvariantCulture)),
                    };

                    AdaptiveCard commandIdCard = new AdaptiveCard(Constants.AdaptiveCardVersion)
                    {
                        Body    = dynamicElements,
                        Actions = new List <AdaptiveAction>(),
                    };

                    if (commandId == Constants.ActiveCommandId && !string.IsNullOrEmpty(onCallSMEUsers))
                    {
                        commandIdCard.Actions.Add(
                            new AdaptiveOpenUrlAction
                        {
                            Title = localizer.GetString("EscalateButtonText"),
                            Url   = new Uri(CreateGroupChat(onCallSMEUsers, ticket.TicketId, ticket.RequesterName, localizer)),
                        });
                    }
                    else if ((commandId == Constants.UrgentCommandId || commandId == Constants.AssignedCommandId || commandId == Constants.UnassignedCommandId) && ticket.SmeConversationId != null)
                    {
                        commandIdCard.Actions.Add(
                            new AdaptiveOpenUrlAction
                        {
                            Title = localizer.GetString("GoToOriginalThreadButtonText"),
                            Url   = new Uri(CreateDeepLinkToThread(ticket.SmeConversationId)),
                        });
                    }

                    ThumbnailCard previewCard = new ThumbnailCard
                    {
                        Title                          = $"<b>{HttpUtility.HtmlEncode(ticket.Title)} | {HttpUtility.HtmlEncode(ticket.Severity == (int)TicketSeverity.Urgent ? localizer.GetString("UrgentText") : localizer.GetString("NormalText"))}</b>",
                        Subtitle                       = ticket.Description.Length <= TruncateDescriptionLength?HttpUtility.HtmlEncode(ticket.Description) : HttpUtility.HtmlEncode(ticket.Description.Substring(0, 45)) + Ellipsis,
                                                  Text = ticket.RequesterName,
                    };
                    composeExtensionResult.Attachments.Add(new Attachment
                    {
                        ContentType = AdaptiveCard.ContentType,
                        Content     = commandIdCard,
                    }.ToMessagingExtensionAttachment(previewCard.ToAttachment()));
                }
            }

            return(composeExtensionResult);
        }
Exemplo n.º 27
0
        public void BackgroundImage()
        {
            var card = new AdaptiveCard("1.2");

            card.BackgroundImage = new AdaptiveBackgroundImage("http://adaptivecards.io/content/cats/1.png", AdaptiveImageFillMode.Repeat, AdaptiveHorizontalAlignment.Right, AdaptiveVerticalAlignment.Bottom);

            var columnSet = new AdaptiveColumnSet();
            var column1   = new AdaptiveColumn();

            column1.BackgroundImage = new AdaptiveBackgroundImage("http://adaptivecards.io/content/cats/1.png", AdaptiveImageFillMode.RepeatVertically, AdaptiveHorizontalAlignment.Center, AdaptiveVerticalAlignment.Top);
            columnSet.Columns.Add(column1);
            var column2 = new AdaptiveColumn();

            column2.BackgroundImage = new AdaptiveBackgroundImage("http://adaptivecards.io/content/cats/2.png", AdaptiveImageFillMode.Cover, AdaptiveHorizontalAlignment.Right, AdaptiveVerticalAlignment.Bottom);
            columnSet.Columns.Add(column2);
            card.Body.Add(columnSet);

            var container1 = new AdaptiveContainer();

            container1.BackgroundImage = new AdaptiveBackgroundImage("http://adaptivecards.io/content/cats/2.png", AdaptiveImageFillMode.RepeatHorizontally, AdaptiveHorizontalAlignment.Left, AdaptiveVerticalAlignment.Center);
            card.Body.Add(container1);

            var container2 = new AdaptiveContainer();

            container2.BackgroundImage = new AdaptiveBackgroundImage("http://adaptivecards.io/content/cats/3.png");
            card.Body.Add(container2);

            var expected = @"{
  ""type"": ""AdaptiveCard"",
  ""version"": ""1.2"",
  ""backgroundImage"": {
    ""url"": ""http://adaptivecards.io/content/cats/1.png"",
    ""fillMode"": ""repeat"",
    ""horizontalAlignment"": ""right"",
    ""verticalAlignment"": ""bottom""
  },
  ""body"": [
    {
      ""type"": ""ColumnSet"",
      ""columns"": [
        {
          ""type"": ""Column"",
          ""backgroundImage"": {
            ""url"": ""http://adaptivecards.io/content/cats/1.png"",
            ""fillMode"": ""repeatVertically"",
            ""horizontalAlignment"": ""center""
          },
          ""items"": []
        },
        {
          ""type"": ""Column"",
          ""backgroundImage"": {
            ""url"": ""http://adaptivecards.io/content/cats/2.png"",
            ""horizontalAlignment"": ""right"",
            ""verticalAlignment"": ""bottom""
          },
          ""items"": []
        }
      ]
    },
    {
      ""type"": ""Container"",
      ""backgroundImage"": {
        ""url"": ""http://adaptivecards.io/content/cats/2.png"",
        ""fillMode"": ""repeatHorizontally"",
        ""verticalAlignment"": ""center""
      },
      ""items"": []
    },
    {
      ""type"": ""Container"",
      ""backgroundImage"": ""http://adaptivecards.io/content/cats/3.png"",
      ""items"": []
    }
  ]
}";

            Assert.AreEqual(expected, card.ToJson());
        }
Exemplo n.º 28
0
 public RenderedAdaptiveCard(FrameworkElement frameworkElement, AdaptiveCard originatingCard)
     : base(originatingCard)
 {
     _framworkElement = frameworkElement;
 }
Exemplo n.º 29
0
        public void RichTextBlockFromJson()
        {
            var json = @"{
              ""type"": ""AdaptiveCard"",
              ""version"": ""1.2"",
              ""body"": [
                {
                  ""type"": ""RichTextBlock"",
                  ""horizontalAlignment"": ""center"",
                  ""inlines"": [
                      {
                        ""type"": ""TextRun"",
                        ""text"": ""Start the rich text block ""
                      },
                      {
                          ""type"": ""TextRun"",
                          ""size"": ""large"",
                          ""weight"": ""bolder"",
                          ""color"": ""accent"",
                          ""isSubtle"": true,
                          ""italic"": true,
                          ""highlight"": true,
                          ""strikethrough"": true,
                          ""text"": ""with some cool looking stuff. "",
                          ""fontStyle"": ""monospace""
                      },
                      {
                        ""type"": ""TextRun"",
                        ""text"": ""This run has a link!"",
                        ""selectAction"": {
                          ""type"": ""Action.OpenUrl"",
                          ""url"": ""http://adaptivecards.io/"",
                          ""title"": ""Open URL""
                      }
                  }
                  ]
                }
              ]
            }";

            var card = AdaptiveCard.FromJson(json).Card;

            var richTB = card.Body[0] as AdaptiveRichTextBlock;

            Assert.AreEqual(richTB.HorizontalAlignment, AdaptiveHorizontalAlignment.Center);

            var inlines1 = richTB.Inlines;
            var run1     = inlines1[0] as AdaptiveTextRun;

            Assert.AreEqual("Start the rich text block ", run1.Text);

            var run2 = inlines1[1] as AdaptiveTextRun;

            Assert.AreEqual(run2.Text, "with some cool looking stuff. ");
            Assert.IsTrue(run2.Italic);
            Assert.IsTrue(run2.Strikethrough);
            Assert.IsTrue(run2.Highlight);

            var run3 = inlines1[2] as AdaptiveTextRun;

            Assert.AreEqual(run3.Text, "This run has a link!");
            Assert.AreEqual("Action.OpenUrl", run3.SelectAction.Type);
            Assert.AreEqual("Open URL", run3.SelectAction.Title);
            Assert.AreEqual("http://adaptivecards.io/", (run3.SelectAction as AdaptiveOpenUrlAction).UrlString);;
        }
Exemplo n.º 30
0
        public AdaptiveCard TaskInformationCard(TaskInfo taskInfo)
        {
            var Card = new AdaptiveCard(new AdaptiveSchemaVersion("1.0"))
            {
                Body = new List <AdaptiveElement>()
                {
                    new AdaptiveColumnSet()
                    {
                        Columns = new List <AdaptiveColumn>()
                        {
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text   = taskInfo.taskNumber + " : " + (taskInfo.title.Length > 30 ? taskInfo.title.Substring(0, 30) : taskInfo.title),
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Large,
                                        Wrap   = true
                                    }
                                },
                                Width = "auto",
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = "",
                                    }
                                },
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveImage()
                                    {
                                        Url = new Uri(_configuration["BaseUri"] + "/Images/" + taskInfo.priority + ".png")
                                    }
                                },
                                Width = "60px",
                            }
                        }
                    },
                    new AdaptiveColumnSet()
                    {
                        Columns = new List <AdaptiveColumn>()
                        {
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = "Owner:",
                                        Size = AdaptiveTextSize.Medium
                                    }
                                },
                                Width = "auto"
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = taskInfo.taskAssignedTo
                                    }
                                }
                            }
                        }
                    },
                    new AdaptiveColumnSet()
                    {
                        Columns = new List <AdaptiveColumn>()
                        {
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = "Status:",
                                        Size = AdaptiveTextSize.Medium
                                    }
                                },
                                Width = "auto"
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = taskInfo.status,
                                    }
                                }
                            }
                        }
                    },
                    new AdaptiveColumnSet()
                    {
                        Columns = new List <AdaptiveColumn>()
                        {
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = "Depends on: ",
                                        Size = AdaptiveTextSize.Medium,
                                    }
                                },
                                Width = "auto"
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = taskInfo.allDependentTaskIDs == null ? " " : string.Join(", ", taskInfo.allDependentTaskIDs),
                                        Wrap = true
                                    }
                                }
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveImage()
                                    {
                                        Url          = new Uri(_configuration["BaseUri"] + "/Images/AddDep.png"),
                                        SelectAction = new AdaptiveSubmitAction()
                                        {
                                            Type     = "Action.Submit",
                                            Title    = "Depends On",
                                            DataJson = @"{'type':'task/fetch','taskId':'" + taskInfo.taskID + "'}",
                                            Data     =
                                                new TaskModuleActionHelper.AdaptiveCardValue <TaskModuleActionDetails>()
                                            {
                                                Data = new TaskModuleActionDetails()
                                                {
                                                    type       = "task/fetch",
                                                    URL        = _configuration["BaseUri"] + "/createNewTask/",
                                                    CreateType = "Depends on",
                                                    TaskId     = taskInfo.taskNumber,
                                                }
                                            }
                                        },
                                    }
                                },
                                Width = "auto"
                            }
                        }
                    },
                    new AdaptiveColumnSet()
                    {
                        Columns = new List <AdaptiveColumn>()
                        {
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text  = "Blocks:",
                                        Size  = AdaptiveTextSize.Medium,
                                        Color = taskInfo.blocks == null ? AdaptiveTextColor.Default : AdaptiveTextColor.Attention
                                    }
                                },
                                Width = "auto"
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = taskInfo.allBlocksTaskIDs == null ? " " : string.Join(", ", taskInfo.allBlocksTaskIDs),
                                        Wrap = true
                                    }
                                }
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveImage()
                                    {
                                        Url          = new Uri(_configuration["BaseUri"] + "/Images/AddDep.png"),
                                        SelectAction = new AdaptiveSubmitAction()
                                        {
                                            Type     = "Action.Submit",
                                            Title    = "Depends On",
                                            DataJson = @"{'type':'task/fetch','taskId':'" + taskInfo.taskID + "'}",
                                            Data     =
                                                new TaskModuleActionHelper.AdaptiveCardValue <TaskModuleActionDetails>()
                                            {
                                                Data = new TaskModuleActionDetails()
                                                {
                                                    type       = "task/fetch",
                                                    URL        = _configuration["BaseUri"] + "/createNewTask/",
                                                    CreateType = "Blocks",
                                                    TaskId     = taskInfo.taskNumber,
                                                }
                                            }
                                        },
                                    }
                                },
                                Width = "auto"
                            }
                        }
                    },
                    new AdaptiveColumnSet()
                    {
                        Columns = new List <AdaptiveColumn>()
                        {
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = "Due date:",
                                        Size = AdaptiveTextSize.Medium
                                    }
                                },
                                Width = "auto"
                            },
                            new AdaptiveColumn()
                            {
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text = taskInfo.dueDate.ToString("M-dd-yyyy"),
                                    }
                                }
                            }
                        }
                    }
                },
                Actions = new List <AdaptiveAction>()
                {
                    new AdaptiveSubmitAction()
                    {
                        Type     = "Action.Submit",
                        Title    = "View Details",
                        DataJson = @"{'type':'task/fetch','taskId':'" + taskInfo.taskID + "' }",
                        Data     =
                            new TaskModuleActionHelper.AdaptiveCardValue <TaskModuleActionDetails>()
                        {
                            Data = new TaskModuleActionDetails()
                            {
                                type = "task/fetch",
                                URL  = _configuration["BaseUri"] + "/EditTask/" + taskInfo.taskID
                            }
                        }
                    },
                }
            };

            return(Card);
        }