From d670820933bbcd36020f1d77d4944651a092b7a7 Mon Sep 17 00:00:00 2001 From: Kavin Date: Mon, 30 Dec 2024 15:51:12 -0800 Subject: [PATCH] tt fix --- .../Microsoft.TeamsAI/TypingTimer.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs index 853b73c1b..250e5b74d 100644 --- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs +++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs @@ -1,6 +1,7 @@ using Microsoft.Teams.AI.Utilities; using Microsoft.Bot.Schema; using Microsoft.Bot.Builder; +using Microsoft.Identity.Client; namespace Microsoft.Teams.AI { @@ -20,6 +21,11 @@ internal class TypingTimer : IDisposable /// private bool _disposedValue = false; + /// + /// The send "typing" activity task + /// + private Task _lastSend = Task.CompletedTask; + /// /// Constructs a new instance of the class. /// @@ -100,7 +106,8 @@ private async void SendTypingActivity(object state) try { - await turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing }); + _lastSend = turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing }); + await _lastSend; if (IsRunning()) { _timer?.Change(_interval, Timeout.Infinite); @@ -115,7 +122,7 @@ private async void SendTypingActivity(object state) } } - private Task StopTimerWhenSendMessageActivityHandlerAsync(ITurnContext turnContext, List activities, Func> next) + private async Task StopTimerWhenSendMessageActivityHandlerAsync(ITurnContext turnContext, List activities, Func> next) { if (_timer != null) { @@ -123,13 +130,14 @@ private Task StopTimerWhenSendMessageActivityHandlerAsync(IT { if (activity.Type == ActivityTypes.Message) { + await _lastSend; Dispose(); break; } } } - return next(); + return await next(); } } }