dang
dang

Reputation: 2412

Typing indicator for bot framework in C#

I have a bot in Bot framework. Once user responds to the bot and bot is processing it, I want to show the typing indicator to the user in the meanwhile.

It is possible in Nodejs here - https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-typing-indicator

But how can I implement it in C#?

Upvotes: 7

Views: 4439

Answers (6)

Bloggrammer
Bloggrammer

Reputation: 1111

Here's another approach to send a typing indicator with a bot framework in C#, JavaScript, or Python.

Upvotes: 1

Kokul Jose
Kokul Jose

Reputation: 1742

For showing typing indicator while bot is processing just add in OnTurnAsync function before await base.OnTurnAsync(turnContext, cancellationToken); :

await turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing }, cancellationToken);

Upvotes: 1

Gagandeep Singh
Gagandeep Singh

Reputation: 11

If V4, following lines of code can help. Keep this code at such a place so that it gets executed everytime during the dialogue flow.

        IMessageActivity reply1 = innerDc.Context.Activity.CreateReply();
        reply1.Type = ActivityTypes.Typing;
        reply1.Text = null;
        await innerDc.Context.SendActivityAsync( reply1, cancellationToken: cancellationToken);
        await Task.Delay(1000);

Upvotes: -1

Sounten
Sounten

Reputation: 302

You can also create the message using context.MakeMessage if you need to instantly respond in MessageReceivedAsync of a dialog.

var typingMsg = context.MakeMessage();
typingMsg.Type = ActivityTypes.Typing;
typingMsg.Text = null;
await context.PostAsync(typingMsg);

The typing indicator is replaced by the next message sent (at least in the Bot Framework emulator). This doesn't seem to work in Slack.

Upvotes: 1

Flash2048
Flash2048

Reputation: 1

Try use this:

var reply = activity.CreateReply();
reply.Text = null;
reply.Type = ActivityTypes.Typing;

await context.PostAsync(reply);

Upvotes: 0

Nicolas R
Nicolas R

Reputation: 14619

You have to send an activity of type Typing.

You can do it like that:

// Send "typing" information
Activity reply = activity.CreateReply();
reply.Type = ActivityTypes.Typing;
reply.Text = null;
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);

Upvotes: 10

Related Questions