-
Notifications
You must be signed in to change notification settings - Fork 481
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
Typing middleware not working as expected in teams as well as web chat channel #6697
Comments
Thanks @deeptishashidharaiah, I'm investigating this issue. |
I'm not able to reproduce this issue. Environment:Sample: 57.teams-conversation-bot TypingActivityMiddlewareRecording.movIf the bot answers very fast, the "typing..." activity might show only for a very short time. Sometimes, it might be so quick that you don't see it. The 'typing' middleware in my testing bot works like this:
Sharing my code below. TypingMiddleware.cs:This code listens for user messages. When it gets a message, it shows the "typing..." message. using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
namespace Microsoft.BotBuilderSamples.Middlewares
{
public class TypingMiddleware : IMiddleware
{
public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken = default)
{
if (turnContext.Activity.Type == ActivityTypes.Message)
{
// send typing activity
var typingActivity = Activity.CreateTypingActivity();
await turnContext.SendActivityAsync(typingActivity, cancellationToken);
}
await next(cancellationToken);
}
}
} AdapterWithErrorHandler.cs:This is where I add the 'typing' middleware to the bot. So the bot knows it should show "typing" activity when it gets a message. using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.BotBuilderSamples.Middlewares;
using Microsoft.Extensions.Logging;
namespace Microsoft.BotBuilderSamples
{
public class AdapterWithErrorHandler : CloudAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<IBotFrameworkHttpAdapter> logger)
: base(auth, logger)
{
Use(new TypingMiddleware());
OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
// NOTE: In production environment, you should consider logging this to
// Azure Application Insights. Visit https://aka.ms/bottelemetry to see how
// to add telemetry capture to your bot.
logger.LogError($"Exception caught : {exception.Message}");
// Send a catch-all apology to the user.
await turnContext.SendActivityAsync("Sorry, it looks like something went wrong.");
// Send a trace activity, which will be displayed in the Bot Framework Emulator
await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
};
}
}
} TeamsActivityHandler:This is bot's main code. When it gets a message, it waits for 1 second ( protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
await Task.Delay(1000);
var userMessage = turnContext.Activity.Text;
var echo = $"You said: {userMessage}";
await turnContext.SendActivityAsync(MessageFactory.Text(echo, echo), cancellationToken);
} |
@ramfattah |
Hi @deeptishashidharaiah, thanks for the update. 1. Clarification on Middleware:The "TypingMiddleware" is a custom middleware class I created for demonstration purposes. It's not part of the official Bot Framework SDK. The SDK provides a built-in middleware called "ShowTypingMiddleware" that sends repeated "typing..." indicators at regular intervals until the bot sends its actual response. 2. Handling Multiple Responses:For your specific use case where you want to send multiple bot responses with "typing..." activities in between, it's more effective to manually send the "typing..." activity within the TypingActivity.movHere's a code snippet for reference: protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
await Task.Delay(1000);
await turnContext.SendActivityAsync(Activity.CreateTypingActivity(), cancellationToken);
await Task.Delay(2000);
var userMessage = turnContext.Activity.Text;
var echo = $"You said: {userMessage}";
await turnContext.SendActivityAsync(MessageFactory.Text(echo, echo), cancellationToken);
await Task.Delay(3000);
await turnContext.SendActivityAsync(Activity.CreateTypingActivity(), cancellationToken);
await Task.Delay(2000);
var secondEcho = $"Second Echo: You said: {userMessage}";
await turnContext.SendActivityAsync(MessageFactory.Text(secondEcho, secondEcho), cancellationToken);
} With this approach, you don't need to use the custom TypingMiddleware I shared earlier. I hope this clears things up. Please let me know if you have further questions or if there's anything else I can assist with. |
Thanks for your response and suggestions.
Hope to know what's the change that introduced between these versions. |
Thanks @deeptishashidharaiah, Interesting, from my end I used version 4.21.0 to do the tests. are you able to share a minimal reproducible .zip bot? |
please give it a try here: https://polarisbot-test.microsoft.com/ |
Thanks @deeptishashidharaiah, I was referring to the bot code. are you able to share a zipped file of your bot that I could test from my end? If so, please be sure to remove any secrets/keys beforehand. |
Cant share entire code here but please reach out to me on teams/outlook, will arrange a call |
@ramfattah any update? |
@ramfattah gentle ping! please update |
@ceciliaavila Can your team help with this? Related to the "New Teams" issue? |
Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.
Version
What package version of the SDK are you using.
->4.21.0
Describe the bug
Give a clear and concise description of what the bug is.
->The latest version 'typing' middle ware is only able to send "typing" for first response and its missing in all other subsequent responses for a single question in bot framework.
Earlier we were using 4.18.0, and it was working as expected as in typing was thrown before all responses.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Give a clear and concise description of what you expected to happen.
->It should be able to send "typing" for first response and as well all other subsequent responses
Screenshots
If applicable, add screenshots to help explain your problem.
-> attached video example
Additional context
Add any other context about the problem here.
Recording 2023-10-09 161456.zip
The text was updated successfully, but these errors were encountered: