public MainDialog(ILogger <MainDialog> logger) : base(nameof(MainDialog)) { _logger = logger; // combine path for cross platform support string[] paths = { ".", "Resources", "MainDialog.LG" }; string mainDialogLGFile = Path.Combine(paths); paths = new string[] { ".", "Resources", "Cards.LG" }; string cardsLGFile = Path.Combine(paths); string[] lgFiles = { mainDialogLGFile, cardsLGFile }; // For simple LG resolution, we will call the TemplateEngine directly. _lgEngine = new TemplateEngine().AddFiles(lgFiles); _activityGenerator = new TextMessageActivityGenerator(); _lgGenerator = new TemplateEngineLanguageGenerator(_lgEngine); AddDialog(new ChoicePrompt(nameof(ChoicePrompt))); AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[] { ChoiceCardStepAsync, ShowCardStepAsync, })); // The initial child Dialog to run. InitialDialogId = nameof(WaterfallDialog); }
public MainDialog(ILogger <MainDialog> logger) : base(nameof(MainDialog)) { _logger = logger; // combine path for cross platform support string[] paths = { ".", "Resources", "MainDialog.LG" }; string mainDialogLGFile = Path.Combine(paths); paths = new string[] { ".", "Resources", "Cards.LG" }; string cardsLGFile = Path.Combine(paths); string[] lgFiles = { mainDialogLGFile, cardsLGFile }; // For simple LG resolution, we will call the TemplateEngine directly. _lgEngine = TemplateEngine.FromFiles(lgFiles); // Resource explorer helps load all .lg files for this project. // TextMessageActivityGenerator is used to transform chatdown style cards into full blown activity. var resourceExplorer = ResourceExplorer.LoadProject(Directory.GetCurrentDirectory(), ignoreFolders: new string[] { "models" }); _activityGenerator = new TextMessageActivityGenerator(new LGLanguageGenerator(resourceExplorer)); AddDialog(new ChoicePrompt(nameof(ChoicePrompt))); AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[] { ChoiceCardStepAsync, ShowCardStepAsync, })); // The initial child Dialog to run. InitialDialogId = nameof(WaterfallDialog); }
private async Task <DialogTurnResult> ShowCardStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { _logger.LogInformation("MainDialog.ShowCardStepAsync"); // Reply to the activity we received with an activity. var reply = stepContext.Context.Activity.CreateReply(); // Cards are sent as Attachments in the Bot Framework. // So we need to create a list of attachments on the activity. reply.Attachments = new List <Attachment>(); // Get the text from the activity to use to show the correct card var text = stepContext.Context.Activity.Text.ToLowerInvariant().Split(' ')[0]; // Decide which type of card(s) we are going to show the user if (text.StartsWith("hero")) { // Display a HeroCard. await stepContext.Context.SendActivityAsync(TextMessageActivityGenerator.CreateActivityFromText(_lgEngine.EvaluateTemplate("HeroCard", null))); } else if (text.StartsWith("thumb")) { // Display a ThumbnailCard. await stepContext.Context.SendActivityAsync(TextMessageActivityGenerator.CreateActivityFromText(_lgEngine.EvaluateTemplate("ThumbnailCard", null))); } else if (text.StartsWith("sign")) { // Display a SignInCard. await stepContext.Context.SendActivityAsync(TextMessageActivityGenerator.CreateActivityFromText(_lgEngine.EvaluateTemplate("SigninCard", null))); } else if (text.StartsWith("animation")) { // Display an AnimationCard. await stepContext.Context.SendActivityAsync(TextMessageActivityGenerator.CreateActivityFromText(_lgEngine.EvaluateTemplate("AnimationCard", null))); } else if (text.StartsWith("video")) { // Display a VideoCard await stepContext.Context.SendActivityAsync(TextMessageActivityGenerator.CreateActivityFromText(_lgEngine.EvaluateTemplate("VideoCard", null))); } else if (text.StartsWith("audio")) { // Display an AudioCard await stepContext.Context.SendActivityAsync(TextMessageActivityGenerator.CreateActivityFromText(_lgEngine.EvaluateTemplate("AudioCard", null))); } else if (text.StartsWith("receipt")) { // Display a ReceiptCard. reply.Attachments.Add(Cards.GetReceiptCard().ToAttachment()); // Send the card(s) to the user as an attachment to the activity await stepContext.Context.SendActivityAsync(reply, cancellationToken); } else if (text.StartsWith("adaptive")) { reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment()); // Send the card(s) to the user as an attachment to the activity await stepContext.Context.SendActivityAsync(reply, cancellationToken); } else { // Display a carousel of all the rich card types. await stepContext.Context.SendActivityAsync(TextMessageActivityGenerator.CreateActivityFromText(_lgEngine.EvaluateTemplate("AllCards", null))); } // Give the user instructions about what to do next await stepContext.Context.SendActivityAsync(MessageFactory.Text(_lgEngine.EvaluateTemplate("CardStartOverResponse", null)), cancellationToken); return(await stepContext.EndDialogAsync()); }