コード例 #1
0
        public static Activity Inline(IList <Choice> choices, string text = null, string speak = null, ChoiceFactoryOptions options = null)
        {
            choices = choices ?? new List <Choice>();
            options = options ?? new ChoiceFactoryOptions();

            var opt = new ChoiceFactoryOptions
            {
                InlineSeparator = options.InlineSeparator ?? ", ",
                InlineOr        = options.InlineOr ?? " or ",
                InlineOrMore    = options.InlineOrMore ?? ", or ",
                IncludeNumbers  = options.IncludeNumbers ?? true,
            };

            // Format list of choices
            var connector  = string.Empty;
            var txtBuilder = new StringBuilder(text)
                             .Append(' ');

            for (var index = 0; index < choices.Count; index++)
            {
                var choice = choices[index];

                var title = choice.Action != null && choice.Action.Title != null ? choice.Action.Title : choice.Value;


                txtBuilder.Append(connector);
                if (opt.IncludeNumbers.Value)
                {
                    txtBuilder
                    .Append('(')
                    .Append(index + 1)
                    .Append(") ");
                }

                txtBuilder.Append(title);
                if (index == (choices.Count - 2))
                {
                    connector = (index == 0 ? opt.InlineOr : opt.InlineOrMore) ?? string.Empty;
                }
                else
                {
                    connector = opt.InlineSeparator ?? string.Empty;
                }
            }

            // Return activity with choices as an inline list.
            return(MessageFactory.Text(txtBuilder.ToString(), speak, InputHints.ExpectingInput));
        }
コード例 #2
0
        public static IMessageActivity ForChannel(string channelId, IList <Choice> list, string text = null, string speak = null, ChoiceFactoryOptions options = null)
        {
            channelId = channelId ?? string.Empty;

            list = list ?? new List <Choice>();

            // Find maximum title length
            var maxTitleLength = 0;

            foreach (var choice in list)
            {
                var l = choice.Action != null && !string.IsNullOrEmpty(choice.Action.Title) ? choice.Action.Title.Length : choice.Value.Length;
                if (l > maxTitleLength)
                {
                    maxTitleLength = l;
                }
            }

            // Determine list style
            var supportsSuggestedActions = Channel.SupportsSuggestedActions(channelId, list.Count);
            var supportsCardActions      = Channel.SupportsCardActions(channelId, list.Count);
            var maxActionTitleLength     = Channel.MaxActionTitleLength(channelId);
            var hasMessageFeed           = Channel.HasMessageFeed(channelId);
            var longTitles = maxTitleLength > maxActionTitleLength;

            if (!longTitles && !supportsSuggestedActions && supportsCardActions)
            {
                // SuggestedActions is the preferred approach, but for channels that don't
                // support them (e.g. Teams, Cortana) we should use a HeroCard with CardActions
                return(HeroCard(list, text, speak));
            }
            else if (!longTitles && supportsSuggestedActions)
            {
                // We always prefer showing choices using suggested actions. If the titles are too long, however,
                // we'll have to show them as a text list.
                return(SuggestedAction(list, text, speak));
            }
            else if (!longTitles && list.Count <= 3)
            {
                // If the titles are short and there are 3 or less choices we'll use an inline list.
                return(Inline(list, text, speak, options));
            }
            else
            {
                // Show a numbered list.
                return(List(list, text, speak, options));
            }
        }
コード例 #3
0
        public static Activity List(IList <Choice> choices, string text = null, string speak = null, ChoiceFactoryOptions options = null)
        {
            choices = choices ?? new List <Choice>();
            options = options ?? new ChoiceFactoryOptions();

            var includeNumbers = options.IncludeNumbers ?? true;

            // Format list of choices
            var connector  = string.Empty;
            var txtBuilder = new StringBuilder(text)
                             .Append("\n\n   ");

            for (var index = 0; index < choices.Count; index++)
            {
                var choice = choices[index];

                var title = choice.Action != null && choice.Action.Title != null ? choice.Action.Title : choice.Value;

                txtBuilder.Append(connector);
                if (includeNumbers)
                {
                    txtBuilder
                    .Append(index + 1)
                    .Append(". ");
                }
                else
                {
                    txtBuilder.Append("- ");
                }

                txtBuilder.Append(title);
                connector = "\n   ";
            }

            // Return activity with choices as a numbered list.
            return(MessageFactory.Text(txtBuilder.ToString(), speak, InputHints.ExpectingInput));
        }
コード例 #4
0
 public static Activity List(IList <string> choices, string text = null, string speak = null, ChoiceFactoryOptions options = null)
 {
     return(List(ToChoices(choices), text, speak, options));
 }
コード例 #5
0
        public static Activity List(List <Choice> choices, string text = null, string speak = null, ChoiceFactoryOptions options = null)
        {
            choices = choices ?? new List <Choice>();
            options = options ?? new ChoiceFactoryOptions();

            bool includeNumbers = options.IncludeNumbers ?? true;

            // Format list of choices
            var connector = string.Empty;
            var txt       = (text ?? string.Empty);

            txt += "\n\n   ";

            for (var index = 0; index < choices.Count; index++)
            {
                var choice = choices[index];

                var title = choice.Action != null && choice.Action.Title != null ? choice.Action.Title : choice.Value;

                txt += connector;
                if (includeNumbers)
                {
                    txt += (index + 1).ToString() + ". ";
                }
                else
                {
                    txt += "- ";
                }
                txt      += title;
                connector = "\n   ";
            }

            // Return activity with choices as a numbered list.
            return(MessageFactory.Text(txt, speak, InputHints.ExpectingInput));
        }
コード例 #6
0
 public static IMessageActivity ForChannel(string channelId, List <string> choices, string text = null, string speak = null, ChoiceFactoryOptions options = null)
 {
     return(ForChannel(channelId, ToChoices(choices), text, speak, options));
 }
コード例 #7
0
 public static IMessageActivity ForChannel(ITurnContext context, List <string> choices, string text = null, string speak = null, ChoiceFactoryOptions options = null)
 {
     return(ForChannel(Channel.GetChannelId(context), ToChoices(choices), text, speak, options));
 }