示例#1
0
        public override void Apply <T>(ref IMessageActivity message, string prompt, IReadOnlyList <T> options, IReadOnlyList <string> descriptions = null, string speak = null)
        {
            SetField.CheckNull(nameof(prompt), prompt);
            SetField.CheckNull(nameof(options), options);
            message.Speak     = speak;
            message.InputHint = InputHints.ExpectingInput;
            if (descriptions == null)
            {
                descriptions = (from option in options select option.ToString()).ToList();
            }
            switch (PromptStyle)
            {
            case PromptStyle.Auto:
            case PromptStyle.Keyboard:
                if (options != null && options.Any())
                {
                    if (PromptStyle == PromptStyle.Keyboard)
                    {
                        message.SuggestedActions = new SuggestedActions(actions: GenerateButtons(options, descriptions));
                        message.Text             = prompt;
                    }
                    else
                    {
                        var heroCard = new HeroCard(text: prompt, buttons: GenerateButtons(options, descriptions));
                        message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                        message.Attachments      = new List <Attachment>()
                        {
                            (isAdaptiveCard) ? heroCard.ToAdaptiveCard().ToAttachment() : heroCard.ToAttachment()
                        };
                    }
                }
                else
                {
                    message.Text = prompt;
                }
                break;

            case PromptStyle.AutoText:
                Apply(ref message, prompt, options, options?.Count() > 4 ? PromptStyle.PerLine : PromptStyle.Inline, descriptions);
                break;

            case PromptStyle.Inline:
                //TODO: Refactor buildlist function to a more generic namespace when changing prompt to use recognizers.
                message.Text = $"{prompt} {Microsoft.Bot.Builder.FormFlow.Advanced.Language.BuildList(descriptions, Resources.DefaultChoiceSeparator, Resources.DefaultChoiceLastSeparator)}";
                break;

            case PromptStyle.PerLine:
                message.Text = $"{prompt}{Environment.NewLine}{Microsoft.Bot.Builder.FormFlow.Advanced.Language.BuildList(descriptions.Select(description => $"* {description}"), Environment.NewLine, Environment.NewLine)}";
                break;

            case PromptStyle.None:
            default:
                message.Text = prompt;
                break;
            }
        }