Manage a long-running operation in MS Teams Bot

Copper Contributor

I am using the following sample / article to Manage a Long-running operation in MS Teams Bot.


In step 5, a DirectLineClient is being created and an Event Activity is sent to Bot using PostActivityAsync.


var responseActivity = new Activity("event");
responseActivity.Value = originalActivity;
responseActivity.Name = "LongOperationResponse";
responseActivity.From = new ChannelAccount("GenerateReport", "AzureFunction");
var directLineSecret = Environment.GetEnvironmentVariable("DirectLineSecret");
using(DirectLineClient client = new DirectLineClient(directLineSecret))
var conversation = await client.Conversations.StartConversationAsync();
await client.Conversations.PostActivityAsync(conversation.ConversationId, responseActivity);


However, I need the above sample to work for MS Teams Bot and not the DirectLineClient.

I used Microsoft.Bot.Connector.ConnectorClient but StartconversationAsync and PostActivityAsync methods are not available. I tried the methods available in Microsoft.Bot.Connector.ConnectorClient

connectorClient.ConversationsCreateDirectConversationAsync(botAccount, userAccount, (Activity)newActivity);
connectorClient.Conversations.SendToConversationAsync(conversationid, (Activity)newActivity);
But all the methods failed with Bad Requestwith the error as seen in the Response: {"error":{"code":"BadArgument","message":"Unknown activity type"}}

The newActivity is created as below:

var messagnewActivity = new Activity("event");
newActivity.Value = originalActivity;
newActivity.From = new ChannelAccount("GenerateReport", "AzureFunction");
newActivity.Type = "event";
newActivity.Conversation = new ConversationAccount { Id = originalActivity.Conversation.Id };
newActivity.ChannelId = originalActivity.ChannelId;



Can someone please suggest how do I pass the Activity (Event Activity type) to MS Teams Bot.



2 Replies

@gagsbhatnagar , Bot in MS Teams (if you have configured Microsoft Teams channel) send turnContext with that you can fetch the Activity, Teams Bot Activity is inbuilt. You just have to enable Teams channel to get the same

@gagsbhatnagar After following the How-To document, did you manage to get the example bot running locally in the emulator (as indicated in the "To test the bot" section)?  I think I must be missing something as I can't get the bot to output the initial dialog ("Please select a long operation test option") to the emulator.


Did you have to do something other than simply connect the emulator?