Exemplo n.º 1
0
        public static async Task RespondAsMultipleMessagesAsync(
            this IEnumerable <IBotResponse> responses,
            ITurnContext context,
            SurveyState surveyState,
            BotSettings botSettings,
            FeatureToggles features,
            CancellationToken cancellationToken)
        {
            foreach (IBotResponse r in responses)
            {
                if (r is ConditionalBotResponse conditionalResponse && !conditionalResponse.IsValid(surveyState))
                {
                    continue;
                }

                if (features != null && features.RealisticTypingDelay)
                {
                    await context.SendTypingActivityAsync(
                        r.Prompt,
                        botSettings.Typing.CharactersPerMinute,
                        botSettings.Typing.ThinkingTimeDelay);
                }

                await context.SendActivityAsync(r.Prompt, InputHints.IgnoringInput, cancellationToken : cancellationToken);
            }
        }
Exemplo n.º 2
0
        public static async Task RespondAsSingleMessageAsync(
            this IEnumerable <IBotResponse> responses,
            ITurnContext context,
            SurveyState surveyState,
            BotSettings botSettings,
            FeatureToggles features,
            CancellationToken cancellationToken)
        {
            var sb = new StringBuilder();

            foreach (var r in responses)
            {
                if (r is ConditionalBotResponse conditionalResponse && !conditionalResponse.IsValid(surveyState))
                {
                    continue;
                }

                sb.AppendLine(r.Prompt);
            }

            var response = sb.ToString();

            if (features != null && features.RealisticTypingDelay)
            {
                await context.SendTypingActivityAsync(
                    response,
                    botSettings.Typing.CharactersPerMinute,
                    botSettings.Typing.ThinkingTimeDelay);
            }

            var activity = new Activity()
            {
                Id        = context.Activity.Id,
                Type      = ActivityTypes.Message,
                InputHint = InputHints.IgnoringInput,
                Text      = response
            };

            await context.SendActivityAsync(activity, cancellationToken : cancellationToken);
        }