如何从Bot手动向Microsoft Teams发送"conversationUpdate"? [英] How to send a 'conversationUpdate' to Microsoft Teams from bot manually?

查看:107
本文介绍了如何从Bot手动向Microsoft Teams发送"conversationUpdate"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在机器人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.

我已经尝试使用 nuget来使用 Microsoft.Bot.Builder.Teams nuget >将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆