在MS Teams Bot中管理长期运行的操作 [英] Manage a long-running operation in MS Teams Bot
问题描述
我正在使用以下示例/文章来管理MS Teams Bot中的长时间运行的操作.
I am using the following sample / article to Manage a Long-running operation in MS Teams Bot.
在步骤5中,正在创建DirectLineClient,并使用PostActivityAsync将事件活动发送到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);
}
但是,我需要以上示例可用于MS Teams Bot而非DirectLineClient.
However, I need the above sample to work for MS Teams Bot and not the DirectLineClient.
我使用了Microsoft.Bot.Connector.ConnectorClient,但是StartconversationAsync和PostActivityAsync方法不可用.我尝试了Microsoft.Bot.Connector.ConnectorClient
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.Conversations.CreateConversationAsync(conversationparameters)
- connectorClient.ConversationsCreateDirectConversationAsync(botAccount,userAccount,(Activity)newActivity);
- connectorClient.Conversations.SendToConversationAsync(conversationid,(Activity)newActivity);
但是,所有方法均因Bad Request失败而出现错误,如响应所示:{错误":{代码":"BadArgument",消息":未知活动类型"}}
But all the methods failed with Bad Requestwith the error as seen in the Response: {"error":{"code":"BadArgument","message":"Unknown activity type"}}
newActivity的创建如下:
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;
有人可以建议我如何将活动(事件活动类型)传递给MS Teams Bot.
Can someone please suggest how do I pass the Activity (Event Activity type) to MS Teams Bot.
谢谢加甘
推荐答案
我对Direct Line并不是很熟悉,但我认为它实际上是Team的一种替代类型的bot,因此,如果您要尝试这样做在团队内部,它解释了这个问题.原则上,基本思想很简单:
I'm not really familiar with Direct Line, but I think it's effectively an -alternative- type of bot to Teams, so if you're trying to do this inside Teams, it explains the issue. In principle, the basic idea is quite simple though:
- 您以某种方式存储状态(例如在内存或数据库中)以指示用户正在进行长时间运行的操作
- 长时间运行的过程完成后,您的代码(可以驻留在您的机器人外部,例如,在Azure函数中)可以向用户发送消息(如果它是机器人)-这称为主动消息传递,您可以在 https://docs.microsoft.com/上了解有关此内容的更多信息.zh-CN/graph/teams-proactive-messaging .
这篇关于在MS Teams Bot中管理长期运行的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!