Microsoft flow adaptive card to mention teams user in teams

久未见 提交于 2020-12-30 08:35:21

问题


I'm creating a Microsoft flow to mention a user within an Adaptive card posted by the Flow bot within teams.

This is the action I'm trying to use

This is a simplified version of my JSON to do this

{
   "type": "AdaptiveCard",
   "body": [
      {
        "type": "Container",
        "items": [
            {
                "type": "TextBlock",
                "size": "Medium",
                "weight": "Bolder",
                "color": "Attention",
                "text": "Hey!"
            },
            {
                "type": "ColumnSet",
                "columns": [
                    {
                        "type": "Column",
                        "items": [
                            {
                                "type": "TextBlock",
                                "text": "<at>steve@example.com</at>",
                            }
                        ],
                        "width": "stretch"
                    }
                ]
            }
        ]
      },
   ],
   "actions": [
      {
        "type": "Action.OpenUrl",
        "title": "Teams Message",
        "url": "-teamsUrl-"
      }
   ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.0"
}

Unfortunately this just displays as <at>steve@example.com</at>

If I use the same syntax as a message to the teams channel then the user will get mentioned.

Is it possible to mention a user within an adaptive card in this way?


回答1:


Mentions do work for Adaptive Card, however, only since version 1.2.

Official docs: Mention support within Adaptive cards v1.2

{
  "version":"1.2",
  "type":"AdaptiveCard",
  "body":[
    {
       "type":"TextBlock",
       "text":"Ahoj <at>Michal Macejko</at>",
       "wrap":True
    }
  ],
  "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
  "msteams":{
    "entities":[
       {
         "additional_properties": {},
         "text": "<at>Michal Macejko</at>",
         "type": "mention",
         "mentioned": 
           {
             "additional_properties": {},
             "id": "channelAccountID",
             "name": "Michal Macejko",
             "aad_object_id": "userID"
           }
       }
    ]
  }
}

aad_object_id is a userId attribute, fetched from https://graph.microsoft.com/v1.0/teams/#{team_id}/members

channelAccountID is a value that you should get from the SDK get_conversation_member

Here's a python example:

from botbuilder.schema import Activity, ActivityTypes, Attachment, Mention
from pyadaptivecards.card import AdaptiveCard
from pyadaptivecards.components import TextBlock

connector_client = await ADAPTER.create_connector_client(service_url)
 text_block = TextBlock(text="Hey! <at>Michal Macejko<at>", wrap=True)
 entities = []
 channel_account = await connector_client.conversations.get_conversation_member(conversation_id=teams_channel_id, member_id=aad_object_id)
 mention_object = Mention(mentioned=channel_account, text="<at>Michal Macejko</at>", type='mention')
 entities.append(Mention().deserialize(mention_object.serialize()))

 card = AdaptiveCard(body=[text_block])
 card.version = '1.2'
 card_hash = card.to_dict()
 card_hash['msteams'] = { 'entities': entities }

 attachment = Attachment(content_type='application/vnd.microsoft.card.adaptive', content=card_hash)
 message = Activity(type=ActivityTypes.message, attachments=[attachment])
 await connector_client.conversations.send_to_conversation(teams_channel_id, message)


来源:https://stackoverflow.com/questions/56437390/microsoft-flow-adaptive-card-to-mention-teams-user-in-teams

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