コード例 #1
0
        private async Task <DialogTurnResult> PromptWithAdaptiveCardAsync(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken)
        {
            // Define choices
            var choices = new[] { "One", "Two", "Three" };

            // Create card
            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                // Use LINQ to turn the choices into submit actions
                Actions = choices.Select(choice => new AdaptiveSubmitAction
                {
                    Title = choice,
                    Data  = choice, // This will be a string
                }).ToList <AdaptiveAction>(),
            };

            // Prompt
            return(await stepContext.PromptAsync(
                       CHOICEPROMPT,
                       new PromptOptions
            {
                Prompt = (Activity)MessageFactory.Attachment(new Attachment
                {
                    ContentType = AdaptiveCard.ToString(),
                    // 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));
        }