Example #1
0
        /// <summary>
        /// AppendChoices is utility method to build up a message activity given all of the options.
        /// </summary>
        /// <param name="prompt">prompt.</param>
        /// <param name="channelId">channelId.</param>
        /// <param name="choices">choices to present.</param>
        /// <param name="style">listType.</param>
        /// <param name="options">options to control the choice rendering.</param>
        /// <param name="cancellationToken">cancellation Token.</param>
        /// <returns>bound activity ready to send to the user.</returns>
        protected virtual IMessageActivity AppendChoices(IMessageActivity prompt, string channelId, IList <Choice> choices, ListStyle style, ChoiceFactoryOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // Get base prompt text (if any)
            var text = prompt != null && !string.IsNullOrEmpty(prompt.Text) ? prompt.Text : string.Empty;

            // Create temporary msg
            IMessageActivity msg;

            switch (style)
            {
            case ListStyle.Inline:
                msg = ChoiceFactory.Inline(choices, text, null, options);
                break;

            case ListStyle.List:
                msg = ChoiceFactory.List(choices, text, null, options);
                break;

            case ListStyle.SuggestedAction:
                msg = ChoiceFactory.SuggestedAction(choices, text);
                break;

            case ListStyle.HeroCard:
                msg = ChoiceFactory.HeroCard(choices, text);
                break;

            case ListStyle.None:
                msg      = Activity.CreateMessageActivity();
                msg.Text = text;
                break;

            default:
                msg = ChoiceFactory.ForChannel(channelId, choices, text, null, options);
                break;
            }

            // Update prompt with text, actions and attachments
            if (prompt != null)
            {
                // clone the prompt the set in the options (note ActivityEx has Properties so this is the safest mechanism)
                prompt = JsonConvert.DeserializeObject <Activity>(JsonConvert.SerializeObject(prompt));

                prompt.Text = msg.Text;

                if (msg.SuggestedActions != null && msg.SuggestedActions.Actions != null && msg.SuggestedActions.Actions.Count > 0)
                {
                    prompt.SuggestedActions = msg.SuggestedActions;
                }

                if (msg.Attachments != null && msg.Attachments.Any())
                {
                    prompt.Attachments = msg.Attachments;
                }

                return(prompt);
            }
            else
            {
                msg.InputHint = InputHints.ExpectingInput;
                return(msg);
            }
        }
Example #2
0
        protected IMessageActivity AppendChoices(IMessageActivity prompt, string channelId, IList <Choice> choices, ListStyle style, ChoiceFactoryOptions options = null)
        {
            // Get base prompt text (if any)
            var text = prompt != null && !string.IsNullOrEmpty(prompt.Text) ? prompt.Text : string.Empty;

            // Create temporary msg
            IMessageActivity msg;

            switch (style)
            {
            case ListStyle.Inline:
                msg = ChoiceFactory.Inline(choices, text, null, options);
                break;

            case ListStyle.List:
                msg = ChoiceFactory.List(choices, text, null, options);
                break;

            case ListStyle.SuggestedAction:
                msg = ChoiceFactory.SuggestedAction(choices, text);
                break;

            case ListStyle.None:
                msg      = Activity.CreateMessageActivity();
                msg.Text = text;
                break;

            default:
                msg = ChoiceFactory.ForChannel(channelId, choices, text, null, options);
                break;
            }

            // Update prompt with text and actions
            if (prompt != null)
            {
                prompt.Text = msg.Text;
                if (msg.SuggestedActions != null && msg.SuggestedActions.Actions != null && msg.SuggestedActions.Actions.Count > 0)
                {
                    prompt.SuggestedActions = msg.SuggestedActions;
                }

                return(prompt);
            }
            else
            {
                msg.InputHint = InputHints.ExpectingInput;
                return(msg);
            }
        }