Bot Framework Typing Activity – Let users know your bot is responding (and know when they are too)

In the recent major update to the Microsoft Bot Framework (v3), a new type of Activity was introduced, a Typing activity.  This Activity type sites along side others, such as Message activity which is the most commonly used activity to represent most communications between a bot and a user.

So, what is the Typing activity for and how do you use it?

We are all very used to chatting with people in online scenarios, from Facebook to Skype, it is something that you no doubt do every day.  One of the features that is now pretty much standard across chat platforms is the ability to see when the other person is typing.  The knowledge that they are typing gives us reassurance that we are not just staring at a screen waiting for something to happen and that they are responding to our message.

However, what happens when you are talking with a bot?  No, a  bot doesn’t actually type anything, but there will be times that bots that you build need to call off to external services or perform some form of calculation that prevents an immediate response. Previously, in v1 of the Bot Framework, people chatting with our bot were left wondering if their message had been received at all.  This is why the new Typing Activity type has been introduced.

Using the Typing Activity you can do two things;

Firstly, we can give the users of our bots the confidence that our bot is doing something and has received their message by sending a Typing activity as a reply to a users message before we continue to process that message.  You can achieve this by making a small addition to the Post method within the MessagesController class.  In the code below you can see how I create a new Activity object (called isTypingReply) and then set its type so that it is a Typing Activity. Finally we use our connector client to send this new activity as a reply to the conversation.

typingactivity

Secondly, you can detect when a user is typing to your bot and respond in some way or trigger a background task. For example, when a user starts typing to your bot, you might want to check a cache to ensure it hasn’t expired and if it has start to preempt your users request by re-hydrating it. Below shows the default method that is contained in the MessagesController class created using the Bot Application template, and shows you where you can put your code to respond to the user typing.
handlesystemmessage

So there you have it, a very straightforward way to make the conversational experience through your bots even better and more natural and a very welcome addition to the Bot Framework.

11 thoughts to “Bot Framework Typing Activity – Let users know your bot is responding (and know when they are too)”

  1. Hi,
    thank you for the tip!

    However I don’t know if it’s a Facebook Messenger bug but, in the Messenger Android App, the typing action never disappear… even after a new reply.

    1. Hi, thanks for reading! I am not sure what the issue is here, but my understanding is that the length of time that the typing message is shown is specific to each channel and not controlled by the bot. However, you can try raising an issue over at https://github.com/Microsoft/BotBuilder. Folks there are pretty responsive and happy to help!

  2. Hi,

    I tried this but my bot emulator shows “TYPING” animation even though I have set my own reply message then also it shows “TYPING”. I have written below code inside post method in MessageController.
    ConnectorClient connector = new ConnectorClient(new System.Uri(activity.ServiceUrl));
    Activity isTypingReply = activity.CreateReply(“Shuttlebot is typing…”);
    isTypingReply.Type = ActivityTypes.Typing;
    isTypingReply.Text = “Shuttlebot is typing…”;
    await connector.Conversations.ReplyToActivityAsync(isTypingReply);

    How do I overcome and show my message.

    1. Hi. I’m afraid this isn’t possible. The typing animation is specific to and controlled by the channel, not the bot framework. i.e. slack will have it’s own animation and skype will have it’s own. You cannot control the text yourself. Hope that helps.

      1. Hey,
        is that possible to control typing … time cause currently its vanished after 3 second if the response is come or not!!!
        How to fix it?

        1. You cannot control the length of time that the typing indicator is shown. You could resend the typing indicator if your task has not completed, but unless you are running some form of long running task I would question the benefit vs effort of doing this.

  3. Hey, it is possible to check user status. I mean-
    1. if bot has asked a question and user didn’t respond it in next 1 hour or so, then bot should ask user to give the answer of the questions.
    2. Bot should ask user to answer the question when he is online, not when he is away or offline.

    Any idea about this?

  4. Hi, How do I control the response time of my bot? For example the user asks me something and I want the bot to take 2 or 3 seconds to respond. Thank you.

    1. You could just use Thread.Sleep as you would in any other .NET application. Put this in your MessagesController if you want the delay to be standard across your messages.

Leave a Reply

Your email address will not be published. Required fields are marked *