微软流量自适应卡片在团队中提及团队用户 [英] Microsoft flow adaptive card to mention teams user in teams

查看:82
本文介绍了微软流量自适应卡片在团队中提及团队用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我尝试使用的操作

这是我的 JSON 的简化版本,用于执行此操作

<代码>{"type": "AdaptiveCard",身体": [{"type": "容器",项目": [{"type": "TextBlock","size": "中","weight": "大胆","颜色": "注意",文本":嘿!"},{"type": "列集",列": [{"type": "列",项目": [{"type": "TextBlock","text": "<at>steve@example.com</at>",}],宽度":拉伸"}]}]},],行动":[{"type": "Action.OpenUrl","title": "团队信息","url": "-teamsUrl-"}],"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",版本":1.0"}

不幸的是,这只是显示为

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

解决方案

提及"确实适用于 Adaptive Card,但是,仅从 1.2 版开始.

官方文档:提及自适应卡片 v1.2 中的支持

<代码>{版本":1.2",类型":AdaptiveCard",身体":[{类型":文本块",文本":Ahoj Michal Macejko",包裹":真}],$schema":http://adaptivecards.io/schemas/adaptive-card.json",msteams":{实体":[{additional_properties":{},文本":<at>Michal Macejko</at>",类型":提及",提及":{additional_properties":{},id":channelAccountID",名称":Michal Macejko",aad_object_id":用户ID"}}]}}

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从 pyadaptivecards.card 导入 AdaptiveCard从 pyadaptivecards.components 导入 TextBlockconnector_client = await ADAPTER.create_connector_client(service_url)text_block = TextBlock(text=嘿!<at>Michal Macejko<at>", wrap=True)实体 = []channel_account = await connector_client.conversations.get_conversation_member(conversation_id=teams_channel_id, member_id=aad_object_id)提及对象=提及(提及=频道帐户,文本=Michal Macejko",类型=提及")entity.append(Mention().deserialize(mention_object.serialize()))card = AdaptiveCard(body=[text_block])card.version = '1.2'card_hash = card.to_dict()card_hash['msteams'] = { 'entities': 实体 }附件 = 附件(content_type='application/vnd.microsoft.card.adaptive', content=card_hash)message = Activity(type=ActivityTypes.message,attachments=[attachment])等待connector_client.conversations.send_to_conversation(teams_channel_id,消息)

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?

解决方案

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)

这篇关于微软流量自适应卡片在团队中提及团队用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆