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

只愿长相守 提交于 2020-03-05 06:04:44

问题


I'm trying to send an activity with an adaptive card attachment and include a mention to the user who created the post. From reading online I found you can't currently include mentions in adaptive cards. Is there a way to mention someone when sending the activity, for example in another attachment?. I have tried setting the activity.Text = mention, this works however it creates two posts, the first with the mention and then another post with the adaptive card as a separate message. I feel there must be a way to do this, else if you created a post and someone responded to you, you'd never know automatically on reply. Also note I'm not using Flow. Code Teams Post


回答1:


Have you thought about (a) sending the adaptive card and (b) sending a "Reply" message to the original Adaptive Card you sent? I haven't done this before, but I'm guessing the id that comes back from turnContext.SendActivityAsync (on the ResourceResponse instance) is the id you can use to "reply" to the message you just created.

Update: I got it working. This is -very- rough code but hopefully enough that you can figure out/adjust to your scenario:

 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);

So note, really important, you need to change your conversation id to add ";messageid=" to the end, and ADD the reference the message you just posted.

Here's a screenshot:

Hope that helps, and thanks for this - gave me a chance to learn something useful!




回答2:


Currently Adaptive Card @mention is in developer preview but you can achieve the @Mention in adaptive card with Adaptive card 1.2 version.

You can @Mention a user in adaptive card using following 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"

        }

      }

    ]

  }

} 

You need to specify channelID, and mentioned ID which you can fetch from the activity object itself



来源:https://stackoverflow.com/questions/60003127/how-to-add-a-mention-in-teams-alongside-an-adaptive-card-using-bot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!