1

I am developing a bot in Microsoft bot framework 4 and would like to introduce a delay and show the "typing" icon between two messages. I have two statements as follows:

await turnContext.SendActivityAsync(MessageFactory.Text(statement.Body), cancellationToken);
await turnContext.SendActivityAsync(MessageFactory.Carousel(GetCarousel(statement)), cancellationToken);

I would like to show the "typing" or "....." between these two messages.

How can this be done?

user1144596
  • 2,068
  • 8
  • 36
  • 56

1 Answers1

0

This answer has a couple of methods. Many people have found the delay activity type to work for them, but for some reason it didn't work for me.

Instead, I've found awaiting a promise to be the best method. If you just add the typing activity without the promise, it will skip right to the next activity. You might try using the typing activity with the delay activity in the above linked answer, but below is what I have done and it works for me. Just add these lines in between your activity.

await step.context.sendActivity({ type: ActivityTypes.Typing });
await new Promise(resolve => setTimeout(resolve, process.env.DIALOG_DELAY));

I set my delay (in ms) in my app settings. I strongly recommend that, or at least defining it globally, in case you decide to adjust the delay later.

billoverton
  • 2,705
  • 2
  • 9
  • 32