Created
August 29, 2019 17:16
-
-
Save rob-derosa/f46b4becab6f5f463a8602bc5c0d32b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright (c) Microsoft Corporation. All rights reserved. | |
| // Licensed under the MIT License. | |
| using System; | |
| using System.Collections.Generic; | |
| using System.IO; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using Microsoft.Bot.Builder; | |
| using Microsoft.Bot.Builder.Dialogs; | |
| using Microsoft.Bot.Builder.Dialogs.Choices; | |
| using AdaptiveCards; | |
| using Microsoft.Bot.Schema; | |
| using Newtonsoft.Json; | |
| using System.Linq; | |
| namespace Microsoft.BotBuilderSamples | |
| { | |
| public class UserProfileDialog : ComponentDialog | |
| { | |
| // private readonly IStatePropertyAccessor<UserProfile> _userProfileAccessor; | |
| public UserProfileDialog(UserState userState) | |
| : base(nameof(UserProfileDialog)) | |
| { | |
| // _userProfileAccessor = userState.CreateProperty<UserProfile>("UserProfile"); | |
| // This array defines how the Waterfall will execute. | |
| var waterfallSteps = new WaterfallStep[] | |
| { | |
| TransportStepAsync, | |
| AskForPhotoAsync, | |
| NameConfirmStepAsync, | |
| }; | |
| // Add named dialogs to the DialogSet. These names are saved in the dialog state. | |
| AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps)); | |
| AddDialog(new TextPrompt(nameof(TextPrompt))); | |
| AddDialog(new AttachmentPrompt(nameof(AttachmentPrompt))); | |
| AddDialog(new ChoicePrompt(nameof(ChoicePrompt)) { Style = ListStyle.None }); | |
| // The initial child Dialog to run. | |
| InitialDialogId = nameof(WaterfallDialog); | |
| } | |
| private static async Task<DialogTurnResult> TransportStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) | |
| { | |
| Activity reply = stepContext.Context.Activity.CreateReply(); | |
| reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; | |
| var choices = new[] { "1", "2", "3", "4" }; | |
| var json = File.ReadAllText("RestaurantCard.json"); | |
| for (int i = 1; i < 5; i++) | |
| { | |
| var str = json.Replace("{{Value}}", i.ToString()); | |
| var result = AdaptiveCard.FromJson(str); | |
| Attachment attachment = new Attachment() | |
| { | |
| ContentType = AdaptiveCard.ContentType, | |
| Content = result.Card | |
| }; | |
| reply.Attachments.Add(attachment); | |
| } | |
| return await stepContext.PromptAsync(nameof(ChoicePrompt), | |
| new PromptOptions | |
| { | |
| Choices = ChoiceFactory.ToChoices(choices), | |
| Prompt = reply | |
| }, cancellationToken); | |
| } | |
| private async Task<DialogTurnResult> AskForPhotoAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) | |
| { | |
| return await stepContext.PromptAsync(nameof(AttachmentPrompt), new PromptOptions | |
| { | |
| Prompt = MessageFactory.Text($"Can you upload a file?"), | |
| }); | |
| } | |
| private async Task<DialogTurnResult> NameConfirmStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) | |
| { | |
| // var selected = ((FoundChoice)stepContext.Result).Value; | |
| // await stepContext.Context.SendActivityAsync($"You selected {selected}"); | |
| return await stepContext.EndDialogAsync(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment