azurebotframeworkchatbotweb-chat

Show the "TypingIndicator" when the Microsoft Bot is processing any requests


I am trying to show the "sendTypingIndicator" when the chatBot (Microsoft Bot Framework) is processing any requests. I added sendTypingIndicator: true and sendTyping: true but still it does not show any animation, I searched in Microsoft documentation but i didn't find any specific. This what I have:

window.WebChat.renderWebChat(
        {
          directLine: window.WebChat.createDirectLine({
            token: conversationInfo.token,
          }),
          store: store,
          styleOptions,
          sendTypingIndicator: true,
          sendTyping: true
        },
        document.getElementById("powerVAwebchat")
      );

Is there a way to automatically have the typing animation for all requests or do I have to dynamically add it for each request? Could you guide me to a solution?

thanks


Solution

  • so what you need is sending a typing activity from the bot when it receives a message request.

    There's the ShowTypingMiddleware middleware that does just that.

    You just have to add it in the adapter like this:

    public class AdapterWithErrorHandler : BotFrameworkHttpAdapter
    {
        public AdapterWithErrorHandler(
            IConfiguration configuration,
            ILogger<BotFrameworkHttpAdapter> logger,
            IStorage storage,
            UserState userState,
            ConversationState conversationState)
            : base(configuration, logger)
        {
            Use(new ShowTypingMiddleware());
    
            //...
        }
    
    }
    

    Just be aware that if the bot replies "fast" you'll not see the typing indicator on the chat. You can always simulate it, for example, adding an await Task.Delay(5000) in the bot.