From bbf48a6088a38bbde9a15b886b286207669903a3 Mon Sep 17 00:00:00 2001 From: JhontSouth Date: Wed, 31 Jan 2024 12:17:26 -0500 Subject: [PATCH] show typing indicator before every message --- .../ShowTypingMiddleware.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libraries/Microsoft.Bot.Builder/ShowTypingMiddleware.cs b/libraries/Microsoft.Bot.Builder/ShowTypingMiddleware.cs index 86c15892dd..e51cd0c68c 100644 --- a/libraries/Microsoft.Bot.Builder/ShowTypingMiddleware.cs +++ b/libraries/Microsoft.Bot.Builder/ShowTypingMiddleware.cs @@ -66,19 +66,13 @@ public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, Cance var containsMessage = activities.Any(e => e.Type == ActivityTypes.Message); if (containsMessage) { - await FinishTypingTaskAsync(ctx).ConfigureAwait(false); + await ProcessTypingAsync(ctx).ConfigureAwait(false); } return await nextSend().ConfigureAwait(false); }); - // Start a timer to periodically send the typing activity (bots running as skills should not send typing activity) - if (!IsSkillBot(turnContext) && turnContext.Activity.Type == ActivityTypes.Message) - { - // Override the typing background task. - await FinishTypingTaskAsync(turnContext).ConfigureAwait(false); - StartTypingTask(turnContext); - } + await ProcessTypingAsync(turnContext).ConfigureAwait(false); await next(cancellationToken).ConfigureAwait(false); @@ -177,5 +171,19 @@ private async Task FinishTypingTaskAsync(ITurnContext turnContext) _tasks.TryRemove(turnContext.Activity.Conversation.Id, out _); } + + /// + /// Start a timer to periodically send the typing activity (bots running as skills should not send typing activity). + /// + /// The context object for this turn. + private async Task ProcessTypingAsync(ITurnContext turnContext) + { + if (!IsSkillBot(turnContext) && turnContext.Activity.Type == ActivityTypes.Message) + { + // Override the typing background task. + await FinishTypingTaskAsync(turnContext).ConfigureAwait(false); + StartTypingTask(turnContext); + } + } } }