Reputation: 10844
I'm trying to add a Typing activity to a long-running action in my bot, but I keep getting a "BadGateway" error. Most of the samples I've found seem to be for bot framework v3, so the types or methods don't appear any more, and I've tried a few options for v4 (using C#), like the following:
await turnContext.SendActivityAsync(new Activity() { Type = ActivityTypes.Typing });
or
var typingActivity = new Activity()
{
Type = ActivityTypes.Typing
//RelatesTo = turnContext.Activity
};
typingActivity.ApplyConversationReference(typingActivity.GetConversationReference());
or
var act2 = MessageFactory.Text(null);
act2.Type = ActivityTypes.Typing;
await turnContext.SendActivityAsync(act2);
all of these result in a BadGateway error.
Can someone guide me on where I'm going wrong?
Upvotes: 1
Views: 1545
Reputation: 3024
The answer of Steven Kanberg has the right code, but unfortunately this is a service issue at the moment, as confirmed in this issue on Github.
When the issue is resolved, it should be posted in the Github issue above.
Upvotes: 1
Reputation: 6393
Your implementation is close, but needs a couple minor adjustments. Also, the text property is optional. If it's not needed, then you can simply remove it (same for the delay). This is what I use which adheres to the documentation (variable is used to match your code). You can reference the docs here.
var typingActivity = new Activity[] {
new Activity { Type = ActivityTypes.Typing },
new Activity { Type = "delay", Value= 3000 },
//MessageFactory.Text("Some message", "Some message"),
};
await turnContext.SendActivitiesAsync(typingActivity, cancellationToken);
Hope of help!
Upvotes: 2
Reputation: 2124
Please try out this code to send a typing activity from your bot:
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
var typingActivity = MessageFactory.Text(string.Empty);
typingActivity.Type = ActivityTypes.Typing;
await turnContext.SendActivityAsync(typingActivity);
}
Upvotes: 0