Ejemplo n.º 1
0
        /// <summary>
        /// Method which renders the prompt to the user given the current input state.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <param name="state">Dialog <see cref="InputState"/>.</param>
        /// <param name="cancellationToken">Optional, the <see cref="CancellationToken"/> that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Activity to send to the user.</returns>
        protected override async Task <IActivity> OnRenderPromptAsync(DialogContext dc, InputState state, CancellationToken cancellationToken = default)
        {
            var locale = DetermineCulture(dc);
            var prompt = await base.OnRenderPromptAsync(dc, state, cancellationToken).ConfigureAwait(false);

            var channelId     = dc.Context.Activity.ChannelId;
            var choiceOptions = ChoiceOptions?.GetValue(dc.State) ?? DefaultChoiceOptions[locale];
            var options       = dc.State.GetValue <ChoiceInputOptions>(ThisPath.Options);

            return(AppendChoices(prompt.AsMessageActivity(), channelId, options.Choices, Style.GetValue(dc.State), choiceOptions));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method which renders the prompt to the user given the current input state.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <param name="state">Dialog <see cref="InputState"/>.</param>
        /// <param name="cancellationToken">Optional, the <see cref="CancellationToken"/> that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Activity to send to the user.</returns>
        protected override async Task <IActivity> OnRenderPromptAsync(DialogContext dc, InputState state, CancellationToken cancellationToken = default)
        {
            var locale = DetermineCulture(dc);
            var prompt = await base.OnRenderPromptAsync(dc, state, cancellationToken).ConfigureAwait(false);

            var channelId     = dc.Context.Activity.ChannelId;
            var choiceOptions = ChoiceOptions?.GetValue(dc.State) ?? DefaultChoiceOptions[locale];

            var(choices, error) = Choices.TryGetValue(dc.State);
            if (error != null)
            {
                throw new InvalidOperationException(error);
            }

            return(AppendChoices(prompt.AsMessageActivity(), channelId, choices, Style.GetValue(dc.State), choiceOptions));
        }