Search code examples
c#botframework

ShowTypingMiddleware keeps showing indicator even after the message is sent


Using The ShowTypingMiddleware in SDK V4 ,Can someone further explain in a real example how the delay and period work.
Ex: ShowTypingMiddleware(0, 2000)

Delay: Initial delay before sending first typing indicator
Period: Rate at which additional typing indicators will be sent

From what i understood:

  • Delay

    If the Delay is 0 then when the bot is about to send a message to the user, there should be no delays and the indicator should show immediately just before sending out the message.

  • Period

    [Considering a person typing example]

    Is that for example when someone pauses while writing a message than starts typing again?
    Meaning after the person starts typing it will wait 2000ms before sending out the typing indicator again?

    [Considering the bot example]

    How does that translates for the bot? The bot does not pause
    When will the Period indicator be effective for the bot?

The Main issue I am facing is that, the bot keeps showing the typing indicator even after the message is sent. So the user keeps waiting

This is happening on both Messenger and DirectLine Channels

Is that heppening because of me misunderstanding Period & Delay or is there something else ?

UPDATE: Check below GIF

(Watch all of it, about 50 seconds, Notice that it does not always happen)

enter image description here


Solution

  • Having an active typing indicator after the bot has sent a message might be related to: https://github.com/microsoft/botbuilder-dotnet/issues/3047

    If you have extra work in the OnTurnAsync method, the Cancellation of the ShowTypingMiddleware will not be called in time. Because of this, it will still be able to send out a typing indicator activity after your bot has sent a message activity.

    You could create a copy of the ShowTypingMiddleware and modify it so it checks if the bot has already responded when checking for the Cancellation. https://github.com/jvanderbiest/echo-bot-typing-indicator/blob/master/CustomShowTypingMiddleware.cs#L90