Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft flow adaptive card to mention teams user in teams

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 PostAdaptiveCardAsFlowBot

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>[email protected]</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>[email protected]</at>

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

PostMessageAsFlowBot

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

like image 447
Java Devil Avatar asked Nov 07 '22 16:11

Java Devil


1 Answers

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)
like image 136
Michal Macejko Avatar answered Dec 09 '22 13:12

Michal Macejko