如何从Bot手动向Microsoft Teams发送"conversationUpdate"? [英] How to send a 'conversationUpdate' to Microsoft Teams from bot manually?
问题描述
我有一个在机器人framework v4
的帮助下编写的机器人.该机器人与Microsoft Teams集成在一起.当用户安装机器人并加入1:1对话时,我想向用户发送欢迎消息.在团队中,conversationUpdate
仅被触发一次(这是当订户加入1:1对话时),然后对该用户不再触发.我的想法是编写一个由聊天消息触发的函数,以手动发送updateConversation
活动以调试欢迎消息.
I have a bot written with the help of bot framework v4
. The bot is integrated with Microsoft Teams. I want to send a welcome message to the user when the user installed the bot and joins the 1:1 conversation. In Teams the conversationUpdate
is fired exactly once (this is when the suer joins the 1:1 conversation) and then never again for that user. My idea was to write a function that is triggered by a chat message to send the updateConversation
activity manually to debug the welcome message.
我到目前为止失败了,得到了
I failed so far and got a
BadArgument:未知的活动类型异常.
BadArgument: Unknown activity type exception.
我已经尝试使用conversationUpdate
活动发送到对话.
I have tried using the Microsoft.Bot.Builder.Teams nuget using the ConnectorClient
to send the conversationUpdate
activity to the conversation.
我还设置了一个控制台应用程序,并尝试使用v3/directline/conversations/{conversationId}/activities
并出现了Forbidden
错误.
Also I set up a console application and tried using the v3/directline/conversations/{conversationId}/activities
and got a Forbidden
error.
private async Task SendConversationUpdateToTeamsAsync(ITurnContext turnContext, CancellationToken cToken = default)
{
var connectorClient = turnContext.TurnState.Get<IConnectorClient>();
var conversationUpdateMessage = new Activity
{
Type = ActivityTypes.ConversationUpdate,
Id = turnContext.Activity.Id,
ServiceUrl = turnContext.Activity.ServiceUrl,
From = turnContext.Activity.From,
Recipient = turnContext.Activity.Recipient,
Conversation = turnContext.Activity.Conversation,
ChannelData = turnContext.Activity.ChannelData,
ChannelId = turnContext.Activity.ChannelId,
Timestamp = turnContext.Activity.Timestamp,
MembersAdded = new List<ChannelAccount>
{
turnContext.Activity.From,
turnContext.Activity.Recipient
},
};
var result = await connectorClient.Conversations.SendToConversationAsync(conversationUpdateMessage, cToken);
}
我希望手动发送conversationUpdate
来调试Teams中的行为是可行的.在办公室门户中创建新用户并为他们安装自动调试程序以调试conversationUpdate
行为对我来说是不可行的,因为这很耗时.如果还有其他解决方法可以触发团队中的conversationUpdate
,请告诉我.
I expect that sending a conversationUpdate
manually to debug the behavior in Teams works. Creating new users in the office portal and installing the bot for them to debug the conversationUpdate
behavior is no option for me, because it is to time consuming. If there is another workaround to trigger the conversationUpdate
in Teams please let me know.
推荐答案
我不确定是否可以以您尝试的方式强制发送ConversationUpdate
的方法.相反,我只是在OnMessageAsync()
中扔这样的东西:
I'm not sure of a way to force a ConversationUpdate
to be sent in the way you're attempting to. Instead, I'd just throw something like this in OnMessageAsync()
:
if (turnContext.Activity.Text == "fakeConversationUpdate")
{
var fakeTurnContext = new TurnContext(turnContext.Adapter, MessageFactory.Text(string.Empty));
fakeTurnContext.Activity.AsConversationUpdateActivity();
fakeTurnContext.Activity.Type = ActivityTypes.ConversationUpdate;
fakeTurnContext.Activity.MembersAdded = new List<ChannelAccount>()
{
new ChannelAccount()
{
Id = "fakeUserId",
Name = "fakeUserName"
}
};
await OnConversationUpdateActivityAsync(new DelegatingTurnContext<IConversationUpdateActivity>(fakeTurnContext), cancellationToken);
}
然后进行调试,您只需在聊天室中将"fakeConversationUpdate"(您可以更改/自定义)写入机器人即可,它将通过OnConversationUpdateActivityAsync()
Then to debug, you just write "fakeConversationUpdate" (which you can change/customize) to the bot in chat and it will send your fakeTurnContext
(which you can change/customize) through OnConversationUpdateActivityAsync()
这篇关于如何从Bot手动向Microsoft Teams发送"conversationUpdate"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!