Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C#] fix: Typing indicator is "stuck" #2250

Open
wants to merge 1 commit into
base: dotnet-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}
Loading