4

The official docs for Microsoft bot-framework SDK v4 do not demonstrate how to send a typing indicator (whereas v3 has these instructions). I'm using DirectLine and botframework-webchat.

How do I do this? Thanks!

Robbie
  • 447
  • 1
  • 6
  • 19

3 Answers3

14

You can send a typing indicator by sending an activity with the typing type. Read more about how to send a typing indicator.

await context.sendActivities([
            { type: ActivityTypes.Typing },
            { type: 'delay', value: 3000 },
            { type: ActivityTypes.Message, text: 'Finished typing' }
        ]);

Also the showTypingMiddleware can be used to automatically send the typing indicator. This snippet will also show how to send a typing indicator, if you are looking for more sample code.

Mick
  • 2,946
  • 14
  • 19
5

I believe you should do something like this

await context.sendActivities([
    { type: 'typing' },
    { type: 'delay', value: 2000 },
    { type: 'message', text: 'Your message here' }
]);
Han
  • 3,272
  • 3
  • 24
  • 39
  • 1
    hi @Han it worked in local but when i deployed the bot in azure typing (....) is not coming. it delayed for 3 second as mentioned in code.await step.context.sendActivities([ { type: 'typing' }, { type: 'delay', value: 3000 }, ]); – Sanjeev Gautam Oct 23 '19 at 08:09
  • I used this on heroku server and skype. It works perfectly – Han Oct 25 '19 at 09:07
  • @ Hans i have changed webSocket: true, and it solved the issue. https://stackoverflow.com/questions/58518661/typing-indicator-in-chatbot/58547986#58547986 – Sanjeev Gautam Oct 25 '19 at 10:16
2

I think you can just add in OnTurnAsync function before await base.OnTurnAsync(turnContext, cancellationToken); :

await turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing }, cancellationToken);
Kokul Jose
  • 1,384
  • 2
  • 14
  • 26