Skip to content

Commit

Permalink
tt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
singhk97 committed Dec 30, 2024
1 parent b7c8bd0 commit d670820
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -20,6 +21,11 @@ internal class TypingTimer : IDisposable
/// </summary>
private bool _disposedValue = false;

/// <summary>
/// The send "typing" activity task
/// </summary>
private Task _lastSend = Task.CompletedTask;

/// <summary>
/// Constructs a new instance of the <see cref="TypingTimer"/> class.
/// </summary>
Expand Down Expand Up @@ -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);
Expand All @@ -115,21 +122,22 @@ private async void SendTypingActivity(object state)
}
}

private Task<ResourceResponse[]> StopTimerWhenSendMessageActivityHandlerAsync(ITurnContext turnContext, List<Activity> activities, Func<Task<ResourceResponse[]>> next)
private async Task<ResourceResponse[]> StopTimerWhenSendMessageActivityHandlerAsync(ITurnContext turnContext, List<Activity> activities, Func<Task<ResourceResponse[]>> next)
{
if (_timer != null)
{
foreach (Activity activity in activities)
{
if (activity.Type == ActivityTypes.Message)
{
await _lastSend;
Dispose();
break;
}
}
}

return next();
return await next();
}
}
}

0 comments on commit d670820

Please sign in to comment.