在 Desktop/Web 聊天视图中提及会议群组的机器人是空白的

Bot mentions to meetings groups are blank on Desktop/Web chat view

我们正在开发一个机器人,它可以在群聊中主动向人们发送消息。 Bot 提及在 Desktop/Web 聊天视图中显示为空白。有趣的是,在移动端和左侧的通知栏中,全文确实正确显示。

这个问题可能适用于其他聊天,但我没有测试过。

我通过构造提及项 object 使用与以下 Microsoft 指南类似的代码: https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/channel-and-group-conversations?tabs=dotnet#add-mentions-to-your-messages

是的,我试过在示例中对名称使用 XMLConvert,但是,这并没有什么区别,事实上,它将 XML 逐字放入发送的消息中由机器人。

我还在这里提交了错误报告,因为我怀疑这是 Teams 本身的错误(尽管我找不到任何其他提及此代码或其他类似示例代码的内容): https://microsoftteams.uservoice.com/forums/555103-public/suggestions/43922577-bot-mentions-to-meetings-groups-are-blank-on-deskt

相关C#代码:

...
using (ConnectorClient _client = new ConnectorClient(new Uri(groupChat.ServiceUrl), GetMicrosoftAppCredentials(), new HttpClient()))
{
    var theMessage = Activity.CreateMessageActivity();
    theMessage.Text = messageDto.Message;

    // Process the message text for <at>mentions</at>
    var textMentions = System.Text.RegularExpressions.Regex.Matches(theMessage.Text, "<at>(.*?)</at>");

    var mentionObjects = new List<Entity>(); // For storing the mentions

    foreach (var textMention in textMentions)
    {
        // The mentioned person should be between the tags
        var theName = textMention.ToString().Split(new string[] { "<at>", "</at>" }, StringSplitOptions.RemoveEmptyEntries)[0];
        if (!String.IsNullOrEmpty(theName))
        {
            // Find the teamsUser based on their name
            var teamsUser = _botContext.Users.FirstOrDefault(u => u.Name.Equals(theName));
            if (teamsUser != null)
            {
                var mention = new Mention
                {
                    Mentioned = new ChannelAccount(teamsUser.TeamsUserId),
                    Text = textMention.ToString()
                };

                mentionObjects.Add(mention);
            }
        }
    }

    theMessage.Entities = mentionObjects;

    try
    {
        var response = await _client.Conversations.SendToConversationAsync(groupChat.GroupChatId, (Activity)theMessage);
        return Ok(response.Id);
    }
    catch (Exception e)
    {}
}
...

桌面团队聊天:

Activity 显示名称正常:

移动应用看起来不错:

为保护隐私而编辑的图片

尝试在 ChannelAccount() 中也传递“用户名”,如下所示:

var mention = new Mention
               {
                        Mentioned = new ChannelAccount(
                            turnContext.Activity.From.Id,
                            **turnContext.Activity.From.Name,**
                            role: null, 
                            aadObjectId: null),
                        Text = textMention.ToString()
                    };

我试过上面的代码,它对我有用。