如何使用 Bot Framework 在 Teams 中添加提及以及自适应卡片

How to add a mention in Teams alongside an adaptive card using Bot Framework

我正在尝试发送带有自适应卡片附件的 activity,并提及创建 post 的用户。通过在线阅读,我发现您目前无法在自适应卡片中包含提及。有没有办法在发送 activity 时提及某人,例如在另一个附件中?我已经尝试设置 activity.Text = 提及,这有效但是它创建了两个 post,第一个带有提及,然后另一个 post 带有自适应卡作为单独的消息。我觉得一定有办法做到这一点,否则如果你创建了一个 post 并且有人回复了你,你永远不会自动知道回复。 另请注意,我没有使用 Flow。 Code Teams Post

您是否考虑过 (a) 发送自适应卡和 (b) 向您发送的原始自适应卡发送 "Reply" 消息?我以前没有这样做过,但我猜从 turnContext.SendActivityAsync(在 ResourceResponse 实例上)返回的 id 是您可以用于 "reply" 到您刚创建的消息的 id。

更新:我成功了。这是 - 非常 - 粗略的代码,但希望足以让您可以根据您的场景计算 out/adjust:

 var result = connector.Conversations.SendToConversationAsync([your conversation id], activity).Result;

// I'm re-using the same activity just as a test, you can do whatever (e.g. create a new one)
activity.Text = "Msg 2";
var conversationReference = activity.GetReplyConversationReference(result);
conversationReference.Conversation.Id = conversationReference.Conversation.Id + ";messageid=" + result.Id;
activity.ApplyConversationReference(conversationReference);

connector.Conversations.SendToConversationAsync(conversationReference.Conversation.Id, activity);

所以请注意,非常重要,您需要更改您的对话 ID 以在末尾添加“;messageid=”,然后ADD 引用您刚刚发布的消息。

截图如下:

希望对您有所帮助,感谢您 - 让我有机会学习有用的东西!

目前 Adaptive Card @mention 处于开发者预览阶段,但您可以使用 Adaptive card 1.2 版本在自适应卡片中实现 @Mention。

您可以使用以下方式在自适应卡片中@提及用户 JSON

{

  "type": "AdaptiveCard",

  "body": [

    {

      "type": "TextBlock",

      "size": "Medium",

      "weight": "Bolder",

      "text": "Hi <at>Mention_Name</at> This is new feature in Adaptive Card version 1.2 Please test..."

    }

  ],

  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",

  "version": "1.0",

  "channelId": {

    "entities": [

      {

        "type": "mention",

        "text": "<at>Name</at>",

        "mentioned": {

          "id": "29:124124124124",

          "name": "Mungo"

        }

      }

    ]

  }

} 

您需要指定 channelID,并提到您可以从 activity 对象本身获取的 ID