public virtual void Visit(AdaptiveFactSet factSet) { foreach (var fact in factSet.Facts) { Visit(fact); } }
// Helper Method to modify the Adaptive Card template. public static AdaptiveCard GetAdaptiveCard(Attendee userProfile) { string json = System.IO.File.ReadAllText(@"Assets\\Card.json"); var card = AdaptiveCards.AdaptiveCard.FromJson(json).Card; var body = card.Body; // Fact AdaptiveFactSet adaptiveFactSet = (AdaptiveCards.AdaptiveFactSet)body[2]; // Name AdaptiveFact name = (AdaptiveFact)adaptiveFactSet.Facts[0]; name.Value = userProfile.Name; // Phone Number AdaptiveFact phoneNumber = (AdaptiveFact)adaptiveFactSet.Facts[1]; phoneNumber.Value = userProfile.PhoneNumber; // Email Address AdaptiveFact emailAddr = (AdaptiveFact)adaptiveFactSet.Facts[2]; emailAddr.Value = userProfile.Email; return(card); }
/// <summary> /// Create a enumeration. /// </summary> /// <param name="title">the title</param> /// <param name="items">the items</param> /// <returns>the enumeration</returns> public static Attachment BuildItemize(string title, IEnumerable <string> items) { AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion()); if (!items.Any()) { items = new string[] { "Nothing" } } ; AdaptiveFactSet facts = new AdaptiveFactSet(); foreach (var item in items) { facts.Facts.Add(new AdaptiveFact("*", item)); } card.Body.Add(new AdaptiveTextBlock($"**{title}**") { MaxLines = 3, Wrap = true }); card.Body.Add(facts); var attachement = new Attachment { ContentType = AdaptiveCard.ContentType, Content = card }; return(attachement); }
// Helper Method to modify the Adaptive Card template. public static AdaptiveCard GetAdaptiveCard(Prospect userProfile) { // Found flight number, just return the flight details now. string json = System.IO.File.ReadAllText(@"Data\\Assets\\Card.json"); var card = AdaptiveCards.AdaptiveCard.FromJson(json).Card; var body = card.Body; // Fact AdaptiveFactSet adaptiveFactSet = (AdaptiveCards.AdaptiveFactSet)body[2]; // Name AdaptiveFact name = (AdaptiveFact)adaptiveFactSet.Facts[0]; name.Value = userProfile.Name; // Phone Number AdaptiveFact phoneNumber = (AdaptiveFact)adaptiveFactSet.Facts[1]; phoneNumber.Value = userProfile.PhoneNumber; // Email Address AdaptiveFact emailAddr = (AdaptiveFact)adaptiveFactSet.Facts[2]; emailAddr.Value = userProfile.Email; return(card); }
public static FrameworkElement Render(AdaptiveFactSet factSet, AdaptiveRenderContext context) { var uiFactSet = new Grid(); // grid.Margin = factSet.Theme.FactSetMargins; uiFactSet.Style = context.GetStyle("Adaptive.FactSet"); uiFactSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); uiFactSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); int iRow = 0; foreach (var fact in factSet.Facts) { var uiTitle = context.Render(new AdaptiveTextBlock() { Size = context.Config.FactSet.Title.Size, Color = context.Config.FactSet.Title.Color, IsSubtle = context.Config.FactSet.Title.IsSubtle, Weight = context.Config.FactSet.Title.Weight, Wrap = context.Config.FactSet.Title.Wrap, Text = fact.Title }); uiTitle.Style = context.GetStyle("Adaptive.Fact.Title"); uiTitle.Margin = new Thickness(left: 0, top: 0, right: context.Config.FactSet.Spacing, bottom: 0); var uiValue = context.Render(new AdaptiveTextBlock() { Size = context.Config.FactSet.Value.Size, Color = context.Config.FactSet.Value.Color, IsSubtle = context.Config.FactSet.Value.IsSubtle, Weight = context.Config.FactSet.Value.Weight, Wrap = context.Config.FactSet.Value.Wrap, Text = fact.Value }); uiValue.Style = context.GetStyle("Adaptive.Fact.Value"); uiFactSet.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); Grid.SetColumn(uiTitle, 0); Grid.SetRow(uiTitle, iRow); uiFactSet.Children.Add(uiTitle); Grid.SetColumn(uiValue, 1); Grid.SetRow(uiValue, iRow++); uiFactSet.Children.Add(uiValue); } return(uiFactSet); }
public static void ShowReservations(ITurnContext context, List <Reservation> reservations) { if ((reservations == null) || (reservations.Count == 0)) { context.SendActivity("You have no reservations."); return; } IMessageActivity activity; if (reservations.Count == 1) { activity = context.Activity.CreateReply(); var card = new AdaptiveCard(); var factset = new AdaptiveFactSet(); factset.Facts.Add(new AdaptiveFact("Start Date", reservations[0].StartDay.ToString("dd/MM/yyyy"))); factset.Facts.Add(new AdaptiveFact("Location", reservations[0].Location)); factset.Facts.Add(new AdaptiveFact("Duration", reservations[0].Duration.ToString())); factset.Facts.Add(new AdaptiveFact("People", reservations[0].PeopleNumber.ToString())); card.Body.Add(new AdaptiveTextBlock() { Text = "Your reservation", Size = AdaptiveTextSize.Default, Wrap = true, Weight = AdaptiveTextWeight.Default }); card.Body.Add(factset); activity.Attachments.Add(new Attachment(AdaptiveCard.ContentType, content: card)); context.SendActivity(activity); return; } string message = $"You have { reservations.Count } reservations: \n\n"; var attachments = new List <Attachment>(); foreach (var res in reservations) { var card = new AdaptiveCard(); var factset = new AdaptiveFactSet(); factset.Facts.Add(new AdaptiveFact("Start Date", res.StartDay.ToString("dd/MM/yyyy"))); factset.Facts.Add(new AdaptiveFact("Location", res.Location)); factset.Facts.Add(new AdaptiveFact("Duration", res.Duration.ToString())); factset.Facts.Add(new AdaptiveFact("People", res.PeopleNumber.ToString())); card.Body.Add(new AdaptiveTextBlock() { Text = "Your reservation", Size = AdaptiveTextSize.Default, Wrap = true, Weight = AdaptiveTextWeight.Default }); card.Body.Add(factset); attachments.Add(new Attachment(AdaptiveCard.ContentType, content: card)); } activity = MessageFactory.Carousel(attachments); context.SendActivity(activity); }
protected static Element FactSetRender(AdaptiveFactSet factSet, ElementAdaptiveRenderContext context) { var uiFactSet = new List() .AddClass($"ac-{factSet.Type.Replace(".", "").ToLower()}") .Style("overflow", "hidden"); foreach (var fact in factSet.Facts) { AdaptiveTextBlock factTitle = new AdaptiveTextBlock() { Text = fact.Title, Size = context.Config.FactSet.Title.Size, Color = context.Config.FactSet.Title.Color, Weight = context.Config.FactSet.Title.Weight, IsSubtle = context.Config.FactSet.Title.IsSubtle, Wrap = context.Config.FactSet.Title.Wrap, MaxWidth = context.Config.FactSet.Title.MaxWidth }; var uiTitle = context.Render(factTitle) .AddClass("ac-facttitle") .Style("margin-right", $"{context.Config.FactSet.Spacing}px"); AdaptiveTextBlock factValue = new AdaptiveTextBlock() { Text = fact.Value, Size = context.Config.FactSet.Value.Size, Color = context.Config.FactSet.Value.Color, Weight = context.Config.FactSet.Value.Weight, IsSubtle = context.Config.FactSet.Value.IsSubtle, Wrap = context.Config.FactSet.Value.Wrap, // MaxWidth is not supported on the Value of FactSet. Do not set it. }; var uiValue = context.Render(factValue) .AddClass("ac-factvalue"); // create row in factset var uiRow = new ListItem(); uiRow.Style("height", "1px"); // add elements as cells uiRow.AppendChild(new Heading(3) .AddClass("ac-factset-titlecell").Style("height", "inherit") .Style("max-width", $"{context.Config.FactSet.Title.MaxWidth}px") .AppendChild(uiTitle)); uiRow.AppendChild(new Span() .AddClass("ac-factset-valuecell") .Style("height", "inherit") .AppendChild(uiValue)); uiFactSet.AppendChild(uiRow); } return(uiFactSet); }
// <GetEventCardSnippet> public static AdaptiveCard GetEventCard(Event calendarEvent, string dateTimeFormat) { // Build an Adaptive Card for the event var eventCard = new AdaptiveCard("1.2"); // Add subject as card title eventCard.Body.Add(new AdaptiveTextBlock { Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder, Text = calendarEvent.Subject }); // Add organizer eventCard.Body.Add(new AdaptiveTextBlock { Size = AdaptiveTextSize.Default, Weight = AdaptiveTextWeight.Lighter, Spacing = AdaptiveSpacing.None, Text = calendarEvent.Organizer.EmailAddress.Name }); // Add details var details = new AdaptiveFactSet(); details.Facts.Add(new AdaptiveFact { Title = "Start", Value = DateTime.Parse(calendarEvent.Start.DateTime).ToString(dateTimeFormat) }); details.Facts.Add(new AdaptiveFact { Title = "End", Value = DateTime.Parse(calendarEvent.End.DateTime).ToString(dateTimeFormat) }); if (calendarEvent.Location != null && !string.IsNullOrEmpty(calendarEvent.Location.DisplayName)) { details.Facts.Add(new AdaptiveFact { Title = "Location", Value = calendarEvent.Location.DisplayName }); } eventCard.Body.Add(details); return(eventCard); }
public static AdaptiveCard GetCard(ConsultingRequestDetails value) { var project = value.project; var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0)); card.Body.Add(new AdaptiveTextBlock($"You billed {value.workHours} hours to {project.Client.Name}") { Weight = AdaptiveTextWeight.Default, Size = AdaptiveTextSize.Large, }); // Display details in a fact set var factSet = new AdaptiveFactSet(); factSet.Facts.Add(new AdaptiveFact("Client", project.Client.Name)); factSet.Facts.Add(new AdaptiveFact("Project", project.Name)); factSet.Facts.Add(new AdaptiveFact("Hours", value.workHours.ToString())); factSet.Facts.Add(new AdaptiveFact("Date worked", value.workDate)); card.Body.Add(new AdaptiveColumnSet() { Columns = new List <AdaptiveCards.AdaptiveColumn>() { new AdaptiveColumn() { Width = "15%", Items = new List <AdaptiveElement>() { new AdaptiveImage(value.project.Client.LogoUrl) } }, new AdaptiveColumn() { Width = "85%", Items = new List <AdaptiveElement>() { factSet } }, } }); return(card); }
private async Task ReplyWithVisitedRestaurantAsync(Restaurant restaurant, Activity activity, ITurnContext context) { AdaptiveCard card = new AdaptiveCard(); card.Speak = $"You have already been to {restaurant.Location}"; card.Body.Add(new AdaptiveTextBlock() { Text = $"You have already been to {restaurant.Location}.", Weight = AdaptiveTextWeight.Default }); var set = new AdaptiveFactSet(); set.Facts.Add(new AdaptiveFact() { Title = "Chosen By", Value = restaurant.PickedBy }); set.Facts.Add(new AdaptiveFact() { Title = "On", Value = restaurant.Date.ToShortDateString() }); card.Body.Add(set); var attachment = new Attachment() { Content = card, ContentType = "application/vnd.microsoft.card.adaptive", Name = "AlreadyChosen" }; var reply = activity.CreateReply(); reply.Attachments = new List <Attachment>() { attachment }; await context.SendActivityAsync(reply); }
private IMessageActivity BuildConfirmationMessageForTeams(IDialogContext context) { var summary = new AdaptiveFactSet { Facts = new List <AdaptiveFact> { new AdaptiveFact("Who", context.Activity.From.Name), new AdaptiveFact("What", _description), new AdaptiveFact("Additional Info", _additionalInfoFromUser), new AdaptiveFact("When", _deadline.ToString()), } }; AdaptiveCard responseCard = new AdaptiveCard(); responseCard.Body.Add(new AdaptiveTextBlock { Text = "Okay, here is what I will send to the freelancer.", Size = AdaptiveTextSize.Default, Wrap = true, Separator = true }); responseCard.Body.Add(summary); var responseMessage = context.MakeMessage(); responseMessage.Attachments = new List <Attachment> { new Attachment() { ContentType = AdaptiveCard.ContentType, Content = responseCard }, new HeroCard { Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, "Send it", value: "yes"), } }.ToAttachment() }; return(responseMessage); }
private List <AdaptiveElement> TransformGroupAsFactSetToElements(List <AdaptiveBlock> group, AdaptiveBlockTransformContext context) { AdaptiveFactSet factSet = new AdaptiveFactSet(); foreach (var block in group) { AdaptiveFact fact = new AdaptiveFact() { Title = block.View?.Content?.Title, Value = block.View?.Content?.Subtitle }; factSet.Facts.Add(fact); } return(new List <AdaptiveElement>() { factSet }); }
// Create FactSet public static AdaptiveElement CreateFactSet(IList <Fact> facts) { var factSet = new AdaptiveFactSet() { Id = "FactSet", Facts = new List <AdaptiveFact>() }; if (facts == null || facts.Count == 0) { return(null); } foreach (var fact in facts) { factSet.Facts.Add(CreateFact(fact)); } return(factSet); }
protected static HtmlTag FactSetRender(AdaptiveFactSet factSet, AdaptiveRendererContext context) { var uiFactSet = (TableTag) new TableTag() .AddClass($"ac-{factSet.Type.Replace(".", "").ToLower()}") .Style("overflow", "hidden"); foreach (var fact in factSet.Facts) { AdaptiveTextBlock factTitle = new AdaptiveTextBlock() { Text = fact.Title, Size = context.Config.FactSet.Title.Size, Color = context.Config.FactSet.Title.Color, Weight = context.Config.FactSet.Title.Weight, IsSubtle = context.Config.FactSet.Title.IsSubtle, }; var uiTitle = context.Render(factTitle) .AddClass("ac-facttitle") .Style("margin-right", $"{context.Config.FactSet.Spacing}px"); AdaptiveTextBlock factValue = new AdaptiveTextBlock() { Text = fact.Value, Size = context.Config.FactSet.Value.Size, Color = context.Config.FactSet.Value.Color, Weight = context.Config.FactSet.Value.Weight, IsSubtle = context.Config.FactSet.Value.IsSubtle, }; var uiValue = context.Render(factValue) .AddClass("ac-factvalue"); // create row in factset var uiRow = uiFactSet .AddBodyRow(); // add elements as cells uiRow.AddCell().AddClass("ac-factset-titlecell").Append(uiTitle); uiRow.AddCell().AddClass("ac-factset-valuecell").Append(uiValue); } return(uiFactSet); }
private void SetValue(AdaptiveFactSet factSet, object value) { if (value is List <AdaptiveFact> ) { factSet.Facts = value as List <AdaptiveFact>; } else if (value is List <Fact> ) { factSet = AdaptiveElementBuilder.CreateFactSet(value as List <Fact>) as AdaptiveFactSet; } else if (value is Dictionary <string, object> ) { factSet.Facts = new List <AdaptiveFact>(); var dictionary = value as Dictionary <string, object>; var keys = dictionary.Keys; foreach (var key in keys) { factSet.Facts.Add(new AdaptiveFact(key, Convert.ToString(dictionary[key]))); } } }
public static IMessageActivity ReservationRecapCard(ITurnContext context, Reservation reservation) { IMessageActivity activity = context.Activity.CreateReply(); var card = new AdaptiveCard(); var factset = new AdaptiveFactSet(); factset.Facts.Add(new AdaptiveFact("Start Date", reservation.StartDay.ToString("dd/MM/yyyy"))); factset.Facts.Add(new AdaptiveFact("Location", reservation.Location)); factset.Facts.Add(new AdaptiveFact("Duration", reservation.Duration.ToString())); factset.Facts.Add(new AdaptiveFact("People", reservation.PeopleNumber.ToString())); card.Body.Add(new AdaptiveTextBlock() { Text = "Your reservation", Size = AdaptiveTextSize.Default, Wrap = true, Weight = AdaptiveTextWeight.Default }); card.Body.Add(factset); activity.Attachments.Add(new Attachment(AdaptiveCard.ContentType, content: card)); return(activity); }
public void FactSet() { AdaptiveFact fact1 = new AdaptiveFact { Title = "Title1", Value = "Value1", Language = "en" }; Assert.AreEqual("Title1", fact1.Title); Assert.AreEqual("Value1", fact1.Value); Assert.AreEqual("en", fact1.Language); AdaptiveFact fact2 = new AdaptiveFact { Title = "Title2", Value = "Value2", }; AdaptiveFactSet factSet = new AdaptiveFactSet { Height = HeightType.Stretch, Id = "FactSetId", IsVisible = false, Separator = true, Spacing = Spacing.Medium, }; ValidateBaseElementProperties(factSet, "FactSetId", false, true, Spacing.Medium, HeightType.Stretch); factSet.Facts.Add(fact1); factSet.Facts.Add(fact2); Assert.AreEqual("Value1", factSet.Facts[0].Value); Assert.AreEqual("Value2", factSet.Facts[1].Value); var jsonString = factSet.ToJson().ToString(); Assert.AreEqual("{\"facts\":[{\"title\":\"Title1\",\"value\":\"Value1\"},{\"title\":\"Title2\",\"value\":\"Value2\"}],\"height\":\"Stretch\",\"id\":\"FactSetId\",\"isVisible\":false,\"separator\":true,\"spacing\":\"medium\",\"type\":\"FactSet\"}", jsonString); }
private HtmlTag FactSetRender(AdaptiveFactSet factSet, AdaptiveRenderContext context) { var definitionList = new HtmlTag("dl") .AddClass("row") .Attr("hidden", !factSet.IsVisible); foreach (var fact in factSet.Facts) { var dt = new HtmlTag("dt") .AddClass("col-sm-3") .SetInnerText(fact.Title); var dd = new HtmlTag("dd") .AddClass("col-sm-9") .SetInnerText(fact.Value); definitionList.Append(dt); definitionList.Append(dd); } return(definitionList); }
public static AdaptiveCard CreateFullCardForCandidate(Candidate c) { AdaptiveCard card = new AdaptiveCard(); card.Body = new List <AdaptiveElement>(); AdaptiveContainer header = new AdaptiveContainer(); card.Body.Add(header); header.Items = new List <AdaptiveElement>(); header.Items.Add(new AdaptiveTextBlock() { Text = c.Name, Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Large }); AdaptiveColumnSet headerDetails = new AdaptiveColumnSet(); header.Items.Add(headerDetails); AdaptiveColumn col1 = new AdaptiveColumn(); col1.Width = AdaptiveColumnWidth.Auto; col1.Items = new List <AdaptiveElement> { new AdaptiveImage() { Url = new Uri(c.ProfilePicture), Size = AdaptiveImageSize.Small, Style = AdaptiveImageStyle.Person } }; AdaptiveColumn col2 = new AdaptiveColumn(); col2.Width = AdaptiveColumnWidth.Stretch; col2.Items = new List <AdaptiveElement> { new AdaptiveTextBlock() { Text = $"Applied {DateTime.Today.ToString("MM/dd/yyyy")}", Wrap = true }, new AdaptiveTextBlock() { Text = $"Current role {c.CurrentRole}", Spacing = AdaptiveSpacing.None, Wrap = true, IsSubtle = true } }; headerDetails.Columns = new List <AdaptiveColumn> { col1, col2 }; AdaptiveContainer details = new AdaptiveContainer(); AdaptiveTextBlock candidateSummary = new AdaptiveTextBlock() { Text = new CandidatesDataController().GetCandidateBio(c), Wrap = true }; AdaptiveFactSet factsCol1 = new AdaptiveFactSet(); factsCol1.Facts = new List <AdaptiveFact> { new AdaptiveFact("Applied to position", c.ReqId), new AdaptiveFact("Interview date", "Not set") }; AdaptiveFactSet factsCol2 = new AdaptiveFactSet(); factsCol2.Facts = new List <AdaptiveFact> { new AdaptiveFact("Hires", c.Hires.ToString()), new AdaptiveFact("No hires", c.NoHires.ToString()) }; AdaptiveColumnSet factColumns = new AdaptiveColumnSet() { Columns = new List <AdaptiveColumn> { new AdaptiveColumn() { Items = new List <AdaptiveElement> { factsCol1 }, Width = AdaptiveColumnWidth.Stretch }, new AdaptiveColumn() { Items = new List <AdaptiveElement> { factsCol2 }, Width = AdaptiveColumnWidth.Stretch } } }; details.Items = new List <AdaptiveElement> { candidateSummary, factColumns }; card.Body.Add(details); AdaptiveImageSet referrals = new AdaptiveImageSet(); referrals.ImageSize = AdaptiveImageSize.Small; referrals.Images = new List <AdaptiveImage>(); foreach (Candidate referral in new CandidatesDataController().GetReferrals(c)) { referrals.Images.Add(new AdaptiveImage() { Url = new Uri(referral.ProfilePicture), Style = AdaptiveImageStyle.Person }); } card.Body.Add(new AdaptiveTextBlock() { Text = "Referrals", Size = AdaptiveTextSize.Large }); card.Body.Add(referrals); AdaptiveAction setInterview = new AdaptiveShowCardAction() { Title = "Set interview date", Card = new AdaptiveCard() { Body = new List <AdaptiveElement> { new AdaptiveDateInput() { Id = "InterviewDate", Placeholder = "Enter in a date for the interview" } }, Actions = new List <AdaptiveAction> { new AdaptiveSubmitAction() { Title = "OK" } } } }; AdaptiveAction setComment = new AdaptiveShowCardAction() { Title = "Add comment", Card = new AdaptiveCard() { Body = new List <AdaptiveElement> { new AdaptiveTextInput() { Id = "Comment", Placeholder = "Add a comment for this candidate", IsMultiline = true } }, Actions = new List <AdaptiveAction> { new AdaptiveSubmitAction() { Title = "OK" } } } }; card.Actions = new List <AdaptiveAction> { setInterview, setComment }; return(card); }
private AdaptiveCard ShowDetailsCard(IDialogContext context, Response viewBalanceResponse, string accrualCodeName) { var message = context.MakeMessage(); var vacationBalance = viewBalanceResponse?.AccrualData?.AccrualBalances?.AccrualBalanceSummary?.Find(x => x.AccrualCodeName == accrualCodeName); AdaptiveCard card = new AdaptiveCard("1.0"); var container = new AdaptiveContainer(); var items = new List <AdaptiveElement>(); var title = new AdaptiveTextBlock { Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder, Text = accrualCodeName == KronosResourceText.VacationBalanceCodePersonal ? KronosResourceText.VacationBalanceCardPersonalLabel : accrualCodeName, }; var factList = new List <AdaptiveFact> { new AdaptiveFact { Title = KronosResourceText.VacationBalanceCardVestedHoursLabel, Value = $"{vacationBalance.VestedBalanceInTime} hours", }, new AdaptiveFact { Title = KronosResourceText.VacationBalanceCardProbationHoursLabel, Value = $"{vacationBalance.ProbationaryBalanceInTime ?? "0:00"} hours", }, new AdaptiveFact { Title = KronosResourceText.VacationBalanceCardPlannedTakingsLabel, Value = $"{vacationBalance.ProjectedTakingAmountInTime} hours", }, new AdaptiveFact { Title = KronosResourceText.VacationBalanceCardPendingGrantsLabel, Value = $"{vacationBalance.ProjectedGrantAmountInTime} hours", }, }; var facts = new AdaptiveFactSet { Facts = factList, }; items.Add(title); items.Add(facts); container.Items = items; card.Body.Add(container); card.Actions.Add( new AdaptiveSubmitAction() { Title = KronosResourceText.RequestTimeOff, Data = new AdaptiveCardAction { msteams = new Msteams { type = "messageBack", displayText = KronosResourceText.TimeOffRequest, text = Constants.CreateTimeOff, }, }, }); if (message.Attachments == null) { message.Attachments = new List <Attachment>(); } message.Attachments.Add(new Attachment() { Content = card, ContentType = "application/vnd.microsoft.card.adaptive", Name = "Show Vacation Balance Details", }); return(card); }
private async Task OnDeadlineSelected(IDialogContext context, IAwaitable<IEnumerable<DateTime>> result) { try { // "result" contains the date (or array of dates) returned from the prompt IEnumerable<DateTime> momentOrRange = await result; var deadline = momentOrRange.First(); // DeadlinePrompt.MomentOrRangeToString(momentOrRange); // Store date context.ConversationData.SetValue("deadline", deadline); var description = context.ConversationData.GetValue<string>("description"); string mobilePhone = string.Empty; string alias = string.Empty; if (!context.UserData.TryGetValue(UserProfileHelper.UserProfileKey, out UserProfile userProfile)) { mobilePhone = userProfile.MobilePhone; alias = userProfile.Alias; } var vsoTicketNumber = await VsoHelper.CreateTaskInVso(VsoHelper.VirtualAssistanceTaskType, context.Activity.From.Name, description, ConfigurationManager.AppSettings["AgentToAssignVsoTasksTo"], deadline, "", null, context.Activity.ChannelId); MicrosoftAppCredentials.TrustServiceUrl(ActivityHelper.TeamsServiceEndpoint); AdaptiveCard card = new AdaptiveCard(); card.Body.Add(new AdaptiveTextBlock() { Text = $"New Virtual Assistance request from {context.Activity.From.Name}. VSO:{vsoTicketNumber}", Size = AdaptiveTextSize.Large, Wrap = true, Separator = true }); var summary = new AdaptiveFactSet { Facts = new List<AdaptiveFact> { new AdaptiveFact("Who", context.Activity.From.Name), new AdaptiveFact("What", description), new AdaptiveFact("When", deadline.ToString()), new AdaptiveFact("Vso", vsoTicketNumber.ToString()), } }; card.Body.Add(summary); using (var connectorClient = await BotConnectorUtility.BuildConnectorClientAsync(ActivityHelper.TeamsServiceEndpoint)) { var channelInfo = GetHardcodedChannelId(); context.ConversationData.SetValue("VsoId", vsoTicketNumber); context.ConversationData.SetValue("EndUserConversationId", context.Activity.Conversation.Id); var conversationResourceResponse = await ConversationHelpers.CreateAgentConversation(channelInfo, card, $"New research request from {context.Activity.Recipient.Name}", connectorClient, vsoTicketNumber, context.Activity as IMessageActivity); EndUserAndAgentConversationMappingState state = new EndUserAndAgentConversationMappingState(vsoTicketNumber.ToString(), context.Activity.From.Name, context.Activity.From.Id, context.Activity.Conversation.Id, conversationResourceResponse.Id); await state.SaveInVso(vsoTicketNumber.ToString()); } await context.PostWithRetryAsync("Thank you! I have posted following to internal agents. " + "I will be in touch with you shortly. " + $"Please use reference #{vsoTicketNumber} for this request in future. " + $"What: {description}. When: {deadline}."); context.Done<object>(null); } catch (TooManyAttemptsException) { await context.PostWithRetryAsync("TooManyAttemptsException. Restarting now..."); } catch (System.Exception e) { WebApiConfig.TelemetryClient.TrackException(e, new Dictionary<string, string> { {"dialog", "InternetResearchDialog" }, {"function", "OnDeadlineSelected" } }); throw; } }
public async Task <IActionResult> GetShippingCardJson( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("GetInventoryCardJson function processed a request."); int orderId = Convert.ToInt32(req.Query["orderId"]); var order = await ApplicationDbContext.Order.Include(x => x.Items).FirstAsync(x => x.Id == orderId); AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0)); // add the heading card.Body.Add(new AdaptiveTextBlock() { Text = $"Order #{orderId} Received", Size = AdaptiveTextSize.Large, Weight = AdaptiveTextWeight.Bolder }); // add the call to action card.Body.Add(new AdaptiveTextBlock() { Text = $"Inventory verified. Please ship:", Weight = AdaptiveTextWeight.Bolder }); // show the items in the order and their quantities var cartItemFactSet = new AdaptiveFactSet(); foreach (var cartItem in order.Items) { var product = ApplicationDbContext.Products.Find(cartItem.ProductId); cartItemFactSet.Facts.Add(new AdaptiveFact { Title = product.Name, Value = cartItem.Quantity.ToString() }); } card.Body.Add(cartItemFactSet); // add the choices var choices = new AdaptiveChoiceSetInput() { Id = "ShipmentConfirmed" }; choices.Choices.Add(new AdaptiveChoice { Title = "Yes", Value = "true" }); choices.Choices.Add(new AdaptiveChoice { Title = "No", Value = "false" }); card.Body.Add(choices); // add the submit button card.Actions.Add(new AdaptiveSubmitAction { Id = "ShipmentConfirmedOkButton", Title = "OK", Data = new { OrderId = order.Id } }); // get the json for the card var json = card.ToJson(); return(new OkObjectResult(json)); }
/// <summary> /// Create the Adaptive Card to display the Orchestrations in particular BizTalk application /// </summary> /// <param name="orchestrations">List of BizTalk orchestrations</param> /// <param name="appName">BizTalk Application Name</param> /// <returns>Adaptive Card Json String</returns> public static string CreateGetOrchestrationsAdaptiveCard(List <Orchestration> orchestrations, string appName) { #region TopLevelColumn AdaptiveColumnSet topLevelColumnSet = CreateTopLevelColumnSet(); #endregion #region Container AdaptiveContainer container = new AdaptiveContainer() { Id = "container", Spacing = AdaptiveSpacing.Default, Separator = true, Items = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Id = "OrchestrationByAppName", Color = AdaptiveTextColor.Default, IsSubtle = true, Separator = true, Spacing = AdaptiveSpacing.Default, Text = string.Format("Orchestrations in {0}", appName) } } }; #endregion #region FactSet foreach (Orchestration orchestration in orchestrations) { string name = orchestration.FullName; name = name.Substring(orchestration.AssemblyName.Length + 1); AdaptiveFactSet orchFactSet = new AdaptiveFactSet() { Id = name, Separator = true, Facts = new List <AdaptiveFact>() { new AdaptiveFact() { Title = "Name", Value = name, }, new AdaptiveFact() { Title = "Host", Value = orchestration.Host }, new AdaptiveFact() { Title = "Status", Value = orchestration.Status } } }; container.Items.Add(orchFactSet); } #endregion AdaptiveCard adaptiveCard = new AdaptiveCard(); adaptiveCard.Body.Add(topLevelColumnSet); adaptiveCard.Body.Add(container); string adaptiveCardJson = adaptiveCard.ToJson(); adaptiveCardJson = RenderStaticImage(adaptiveCardJson, Constants.BizManDummyUrl, Constants.BizManImagePath); return(adaptiveCardJson); }
/// <summary> /// Create the Adaptive Card to display the Receive Locations in particular BizTalk application /// </summary> /// <param name="receiveLocations">List of Receive Locations</param> /// <param name="appName">BizTalk Application Name</param> /// <returns>Adaptive Card Json String</returns> public static string CreateGetReceiveLocationsByAppAdaptiveCard(List <ReceiveLocation> receiveLocations, string appName) { #region TopLevelColumn AdaptiveColumnSet topLevelColumnSet = CreateTopLevelColumnSet(); #endregion #region Container AdaptiveContainer container = new AdaptiveContainer() { Id = "container", Spacing = AdaptiveSpacing.Default, Separator = true, Items = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Id = "ReceiveLocationsByAppName", Color = AdaptiveTextColor.Default, IsSubtle = true, Separator = true, Spacing = AdaptiveSpacing.Default, Text = string.Format("Receive Locations in {0}", appName) } } }; #endregion #region FactSet foreach (ReceiveLocation receiveLocation in receiveLocations) { string name = receiveLocation.Name; AdaptiveFactSet receiveLocationFactSet = new AdaptiveFactSet() { Id = name, Separator = true, Facts = new List <AdaptiveFact>() { new AdaptiveFact() { Title = "Name", Value = name, }, new AdaptiveFact() { Title = "Handler", Value = receiveLocation.ReceiveHandler }, new AdaptiveFact() { Title = "Status", Value = receiveLocation.Enable ? "Enabled" : "Disabled" } } }; container.Items.Add(receiveLocationFactSet); } #endregion AdaptiveCard adaptiveCard = new AdaptiveCard(); adaptiveCard.Body.Add(topLevelColumnSet); adaptiveCard.Body.Add(container); string adaptiveCardJson = adaptiveCard.ToJson(); adaptiveCardJson = RenderStaticImage(adaptiveCardJson, Constants.BizManDummyUrl, Constants.BizManImagePath); return(adaptiveCardJson); }
/// <summary> /// Create the Adaptive Card to display the Send Ports in particular BizTalk application /// </summary> /// <param name="sendPorts">List of Send Ports</param> /// <param name="appName">BizTalk Application Name</param> /// <returns>Adaptive Card Json String</returns> public static string CreateGetSendPortsByAppAdaptiveCard(List <SendPort> sendPorts, string appName) { #region TopLevelColumn AdaptiveColumnSet topLevelColumnSet = CreateTopLevelColumnSet(); #endregion #region Container AdaptiveContainer container = new AdaptiveContainer() { Id = "container", Spacing = AdaptiveSpacing.Default, Separator = true, Items = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Id = "SendPortsByAppName", Color = AdaptiveTextColor.Default, IsSubtle = true, Separator = true, Spacing = AdaptiveSpacing.Default, Text = string.Format("Send Ports in {0}", appName) } } }; #endregion #region FactSet foreach (SendPort sendPort in sendPorts) { string name = sendPort.Name; AdaptiveFactSet sendPortFactSet = new AdaptiveFactSet() { Id = name, Separator = true, Facts = new List <AdaptiveFact>() { new AdaptiveFact() { Title = "Name", Value = name, }, new AdaptiveFact() { Title = "Handler", Value = sendPort.PrimaryTransport.SendHandler }, new AdaptiveFact() { Title = "Status", Value = sendPort.Status } } }; container.Items.Add(sendPortFactSet); } #endregion AdaptiveCard adaptiveCard = new AdaptiveCard(); adaptiveCard.Body.Add(topLevelColumnSet); adaptiveCard.Body.Add(container); string adaptiveCardJson = adaptiveCard.ToJson(); adaptiveCardJson = RenderStaticImage(adaptiveCardJson, Constants.BizManDummyUrl, Constants.BizManImagePath); return(adaptiveCardJson); }
private AdaptiveCard CreateGroupCard(Models.GroupModel group) { AdaptiveCard groupCard = new AdaptiveCard("1.0") { Type = "AdaptiveCard" }; AdaptiveContainer infoContainer = new AdaptiveContainer(); AdaptiveColumnSet infoColSet = new AdaptiveColumnSet(); bool noPic = String.IsNullOrEmpty(group.Thumbnail); if (!noPic) { AdaptiveColumn picCol = new AdaptiveColumn() { Width = AdaptiveColumnWidth.Auto }; picCol.Items.Add(new AdaptiveImage() { Url = new Uri(group.Thumbnail), Size = AdaptiveImageSize.Small, Style = AdaptiveImageStyle.Default }); infoColSet.Columns.Add(picCol); } AdaptiveColumn txtCol = new AdaptiveColumn() { Width = AdaptiveColumnWidth.Stretch }; var titleBlock = new AdaptiveTextBlock() { Text = NullSafeString(group.Name), Weight = AdaptiveTextWeight.Bolder }; if (noPic) { titleBlock.Size = AdaptiveTextSize.Large; } txtCol.Items.Add(titleBlock); txtCol.Items.Add(new AdaptiveTextBlock() { Text = NullSafeString(group.Description), Spacing = AdaptiveSpacing.None, IsSubtle = true }); infoColSet.Columns.Add(txtCol); infoContainer.Items.Add(infoColSet); groupCard.Body.Add(infoContainer); AdaptiveContainer factContainer = new AdaptiveContainer(); AdaptiveFactSet factSet = new AdaptiveFactSet(); if (!String.IsNullOrEmpty(group.Classification)) { factSet.Facts.Add(new AdaptiveFact() { Title = "Classification", Value = group.Classification }); } if (!String.IsNullOrEmpty(group.Visibility)) { factSet.Facts.Add(new AdaptiveFact() { Title = "Visibility", Value = group.Visibility }); } if (!String.IsNullOrEmpty(group.GroupType)) { factSet.Facts.Add(new AdaptiveFact() { Title = "Type", Value = NullSafeString(group.GroupType) }); } if (group.CreatedDateTime.HasValue) { factSet.Facts.Add(new AdaptiveFact() { Title = "Created", Value = $"{{{{DATE({group.CreatedDateTime.Value.UtcDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ")},SHORT)}}}}" }); } if (!String.IsNullOrEmpty(group.Policy) && group.RenewedDateTime.HasValue) { factSet.Facts.Add(new AdaptiveFact() { Title = "Policy", Value = NullSafeString(group.Policy) }); factSet.Facts.Add(new AdaptiveFact() { Title = "Renewed", Value = $"{{{{DATE({group.RenewedDateTime.Value.UtcDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ")},SHORT)}}}}" }); } factContainer.Items.Add(factSet); groupCard.Body.Add(factContainer); return(groupCard); }
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); }