【问题标题】:Cannot mention person in Adaptive Card using Teams PowerShell Module无法使用 Teams PowerShell 模块在自适应卡片中提及人员
【发布时间】:2021-10-15 01:44:26
【问题描述】:

我在我的一个 Teams 频道中注册了Incoming Messages Webhook。 我正在使用Microsoft Teams PowerShell 创建自适应卡片并将其发送到频道:

$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"

卡片已正确发送,但提及未正确呈现。

ID 错误?

值得一提的是,the doc 明确引用了一种用户 ID:

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

您可以看到示例中的 ID 是:"id": "29:123124124124",而我的是 GUID。我通过Get-TeamUser 检索了那个用户ID。

我做错了什么?

【问题讨论】:

    标签: powershell microsoft-teams adaptive-cards


    【解决方案1】:

    ID 和名称可以从 Activity 中获取,如下所示

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

    提供有用的参考 - mention-support-within-adaptive-cards-v12

    【讨论】:

    • 我不明白您如何检索 ID 和姓名。您提到您可以从活动中检索它们。什么活动?如果您看到我的代码,我怎样才能得到您展示的那段代码?
    • 此外,您引用的文档没有告诉我如何检索该 ID,它告诉我如何提及...它有一个关于如何检索 ID 的部分,但这对我正在使用的 API
    • 请注意,您可以在自适应卡片正文中添加@mentions,用于机器人和消息传递扩展响应。 userId 对于您的机器人 ID 和特定用户是唯一的。根据文档,可以从机器人上下文中检索提到的 ID。
    • 我没有机器人上下文。我通过调用 REST API 并仅提供 PAT 来使用 powershell 命令。使用 Powershell 时如何检索该信息?
    【解决方案2】:

    仅在 bot 上下文中支持在自适应卡中提及,文档中列出了获取 id 的可用方法 - mention-support-within-adaptive-cards-v12

    相关团队正在努力支持在传入 Webhook 中使用 AAD 对象 ID 和 UPN(使用 Graph API)的用户提及。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-05
      • 2021-02-06
      • 1970-01-01
      • 2020-01-13
      • 2018-10-03
      • 2019-01-18
      • 2020-11-14
      • 2020-12-23
      相关资源
      最近更新 更多