Cannot mention person in Adaptive Card using Teams PowerShell Module

Viewed 1053

I have registered an Incoming Messages Webhook in one of my Teams channels. I am using Microsoft Teams PowerShell to create an adaptive card and send it to a channel:

$SimpleCard = @{
    type = "message";
    attachments = @(@{
        contentType  = 'application/vnd.microsoft.card.adaptive';
        contentUrl = $null;
        content = @{
            '$schema' = 'http://adaptivecards.io/schemas/adaptive-card.json';
            type = 'AdaptiveCard';
            version = '1.2';
            body = @(@{
                type = 'TextBlock';
                text = "Hello <at>andrea.tino@mycompany.com</at>";
            })
        }
    });
    msteams = @{
        entities = @(@{
            type = 'mention';
            text = "<at>andrea.tino@mycompany.com</at>";
            mentioned = @{
                id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
                name = 'Andrea Tino';
            }
        })
    }
}

Invoke-RestMethod -Method post
                  -ContentType 'Application/Json'
                  -Body ($SimpleCard | ConvertTo-Json -Depth 10)
                  -Uri "https://myorg.webhook.office.com/webhookb2/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx@xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/IncomingWebhook/xxxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

The card is correctly sent but the mention is not correctly rendered.

Wrong ID?

It is worth mentioning that the doc makes explicit reference to a type of User ID:

{
  "type": "mention",
  "text": "<at>John Doe</at>",
  "mentioned": {
    "id": "29:123124124124",
    "name": "John Doe"
  }
}

You can see that the ID in the example is: "id": "29:123124124124" while mine is a GUID. I retrieved that User ID by means of Get-TeamUser.

What am I doing wrong?

2 Answers

Mention in adaptive card is supported only in context of bot and the available ways to get id are listed in the document - mention-support-within-adaptive-cards-v12

Concerned team is working to support user mention using AAD Object Id and UPN(use Graph API) in Incoming Webhook.

ID and Name can be fetched from the activity as follows

from: {
id: '29:15fREhoUuf6vVCOuaJYVH-AB6QXXX',
name: 'MOD Administrator',
aadObjectId: 'XXXX'
}

Giving a reference that will help - mention-support-within-adaptive-cards-v12

Related