private Attachment CreateBookingConfimrationCardAttachment(FlightitineraryModel data) { try { var cardResourcePath = "TravelBookingBot.Cards.flightCard.json"; using (var stream = GetType().Assembly.GetManifestResourceStream(cardResourcePath)) { using (var reader = new StreamReader(stream)) { var adaptiveCardTempalte = reader.ReadToEnd(); JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = DateTimeZoneHandling.Utc }; var dataJson = JsonConvert.SerializeObject(data, microsoftDateFormatSettings); var transformer = new AdaptiveTransformer(); var cardJson = transformer.Transform(adaptiveCardTempalte, dataJson); return(new Attachment() { ContentType = AdaptiveCards.AdaptiveCard.ContentType,// "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(cardJson), }); } } } catch (Exception ex) { throw; } }
private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // If the child dialog ("BookingDialog") was cancelled, the user failed to confirm or if the intent wasn't BookFlight // the Result here will be null. if (stepContext.Result is BookingDetails result) { // Now we have all the booking details call the booking service. // If the call to the booking service was successful tell the user. var timeProperty = new TimexProperty(result.TravelDate); var travelDateMsg = timeProperty.ToNaturalLanguage(DateTime.Now); var messageText = $"I have you booked to {result.Destination} from {result.Origin} on {travelDateMsg}"; var message = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput); var model = new FlightitineraryModel { Places = new Cards.Place[] { new Cards.Place { Name = result.Origin, Code = result.Origin, Id = 13554, Type = "Airport" }, new Cards.Place { Name = result.Destination, Code = result.Destination, Id = 11235, Type = "Airport" } }, Segments = new Segment[] { new Segment { Id = 1, ArrivalDateTime = DateTime.Parse(result.TravelDate), DepartureDateTime = DateTime.Parse(result.TravelDate), OriginStation = 13554, DestinationStation = 11235 }, new Segment { Id = 2, ArrivalDateTime = DateTime.Parse(result.TravelDate), DepartureDateTime = DateTime.Parse(result.TravelDate), OriginStation = 11235, DestinationStation = 13554 } }, Query = new Query { DestinationPlace = "11235", OriginPlace = "13554", InboundDate = result.TravelDate, OutboundDate = result.TravelDate, LocationSchema = "Default", CabinClass = "Economy", GroupPricing = false, Country = "GB", Currency = "GBP", Locale = "en-gb", Adults = 3, Children = 0, Infants = 0, }, BookingOptions = new Bookingoption[] { new Bookingoption { BookingItems = new Bookingitem[] { new Bookingitem { Price = new Random().Next(200, 5000), SegmentIds = new int[] { 1, 2 } } } } } }; var confirmationCard = CreateBookingConfimrationCardAttachment(model); message.Attachments.Add(confirmationCard); await stepContext.Context.SendActivityAsync(message, cancellationToken); } // Restart the main dialog with a different message the second time around var promptMessage = "What else can I do for you?"; return(await stepContext.ReplaceDialogAsync(InitialDialogId, promptMessage, cancellationToken)); }