Example #1
0
        public static Activity Inline(List <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 txt       = text ?? string.Empty;

            txt += " ";

            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 (opt.IncludeNumbers.Value)
                {
                    txt += "(" + (index + 1).ToString() + ") ";
                }
                txt += $"{title}";
                if (index == (choices.Count - 2))
                {
                    connector = (index == 0 ? opt.InlineOr : opt.InlineOrMore) ?? string.Empty;
                }
                else
                {
                    connector = opt.InlineSeparator ?? string.Empty;
                }
            }
            txt += "";

            // Return activity with choices as an inline list.
            return(MessageFactory.Text(txt, speak, InputHints.ExpectingInput));
        }
Example #2
0
 public static Activity Inline(List <string> choices, string text = null, string speak = null, ChoiceFactoryOptions options = null)
 {
     return(Inline(ToChoices(choices), text, speak, options));
 }
Example #3
0
        public static IMessageActivity ForChannel(string channelId, List <Choice> list, string text = null, string speak = null, ChoiceFactoryOptions options = null)
        {
            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 || (!hasMessageFeed && supportsCardActions)))
            {
                // 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));
            }
        }
Example #4
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));
 }
Example #5
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));
 }
Example #6
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));
        }