Botbuilder-js: Send Typing Indicator Helper

Created on 9 Nov 2018  路  8Comments  路  Source: microsoft/botbuilder-js

Send Typing Indicator Helper
In the v3 SDK and in early iterations of the v4 SDK, there was a simple utility that allowed developers to have their bot send typing indicators. Albeit a minor user experience feature, it gives the end user of the bot the sense that they're communicating with a real agent that's actively typing.

Describe the solution you'd like
In the current iteration of the SDK there appears to be a showTypingMiddleware which sends typing indicators for every outgoing message. While this may be valuable for some bots, I'd like to see a solution that allows the developer to send typing messages themselves.

Additional context
While digging around the source code I found this comment that demonstrates how to send a typing indicator. It both seems like too much code, which could easily be abstracted into a helper function, and doesn't seem to work:

     * // Send a typing indicator without going through a middleware listeners.
     * const reference = TurnContext.getConversationReference(context.activity);
     * const activity = TurnContext.applyConversationReference({ type: 'typing' }, reference);
     * await context.adapter.sendActivities([activity]);

I also noted this bug, but was not able to use the resolution to send the indicator:

await dc.context.sendActivity({ type: ActivityTypes.Typing });

Note: I'm currently testing the typing in the emulator. It's entirely possible that the above code works in other channels, and that this is an emulator bug

[enhancement]

P2 triaged 4.3

Most helpful comment

Recently checked the documentation and find out about the SendActivities method.
Tried it and it worked!, in case someone writing on javascript runs with the same issue.

await context.sendActivities([
* { type: 'typing' },
* { type: 'delay', value: 2000 },
* { type: 'message', text: 'Hello... How are you?' }
* ]);

All 8 comments

Typing indicator is a very important feature for improving ux experience. SDKv3 was way easier than SDKv4, i couldnt make it work for SDKv4. Saw some examples for the dotnet sdk but none for javascript. Love to hear improvements on this topic

Recently checked the documentation and find out about the SendActivities method.
Tried it and it worked!, in case someone writing on javascript runs with the same issue.

await context.sendActivities([
* { type: 'typing' },
* { type: 'delay', value: 2000 },
* { type: 'message', text: 'Hello... How are you?' }
* ]);

Recently checked the documentation and find out about the SendActivities method.
Tried it and it worked!, in case someone writing on javascript runs with the same issue.

await context.sendActivities([

  • { type: 'typing' },
  • { type: 'delay', value: 2000 },
  • { type: 'message', text: 'Hello... How are you?' }
  • ]);

Great! Thanks! Your solution worked for me, though I introduced a little modification:

async sendTyping(context) {
    await context.sendActivities([
        { type: 'typing' },
        { type: 'delay', value: 2000 }
    ]);
}

We've talked this over, and I don't see us adding this, given the view lines of code above to implement the behavior.

Hi It worked for me also in localhost/emulator. but when i deployed in azure it is not working.
i can see there is delay in the response but typing is not coming

This is for node js. It should work..

await step.context.sendActivity({ type: ActivityTypes.Typing });

This will work on the web.

Which channel your bot is deployed.

yes, that work well, thanks!!, but how to add Typing Indicator whenever BOT have received a message and is processing? @sanjeevgaut thanks!!

yes, that work well, thanks!!, but how to add Typing Indicator whenever BOT have received a message and is processing? @sanjeevgaut thanks!!
Just add await step.context.sendActivity({ type: ActivityTypes.Typing }); in the next step.
or when any processing is hepening add below
step.context.sendActivity({ type: ActivityTypes.Typing });

it should work.

Was this page helpful?
0 / 5 - 0 ratings