【问题标题】:Microsoft flow adaptive card to mention teams user in teams微软流程自适应卡在团队中提及团队用户
【发布时间】:2019-10-19 14:24:57
【问题描述】:

我正在创建一个 Microsoft 流程,以在团队内 Flow 机器人发布的自适应卡片中提及用户。

这是我正在尝试使用的操作

这是我的 JSON 的简化版本

{
   "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"
}

不幸的是,这只是显示为&lt;at&gt;steve@example.com&lt;/at&gt;

如果我使用与发送给团队频道的消息相同的语法,那么用户就会被提及。

是否可以通过这种方式在自适应卡片中提及用户?

【问题讨论】:

标签: microsoft-teams adaptive-cards power-automate


【解决方案1】:

不过,仅在 1.2 版之后,提及功能才适用于 Adaptive Card。

官方文档: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 是一个userId 属性,取自https://graph.microsoft.com/v1.0/teams/#{team_id}/members

channelAccountID 是您应该从 SDK 获取的值 get_conversation_member

这是一个 python 示例:

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)

【讨论】:

    猜你喜欢
    • 2020-05-18
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 2021-03-08
    • 2021-10-09
    相关资源
    最近更新 更多