Skip to content

Commit

Permalink
show typing indicator before every message
Browse files Browse the repository at this point in the history
  • Loading branch information
JhontSouth committed Jan 31, 2024
1 parent 2e8a6f8 commit bbf48a6
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions libraries/Microsoft.Bot.Builder/ShowTypingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -177,5 +171,19 @@ private async Task FinishTypingTaskAsync(ITurnContext turnContext)

_tasks.TryRemove(turnContext.Activity.Conversation.Id, out _);
}

/// <summary>
/// Start a timer to periodically send the typing activity (bots running as skills should not send typing activity).
/// </summary>
/// <param name="turnContext">The context object for this turn.</param>
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);
}
}
}
}

0 comments on commit bbf48a6

Please sign in to comment.