Microsoft Teams Webhook为自适应卡生成400

Gil*_*gan 7 microsoft-teams adaptive-cards

我有一个功能强大的webhook到Teams频道,我可以成功发布消息.我现在正试图将自适应卡发布到webhook.使用Postman并执行帖子到https://outlook.office.com/webhook/xyz,在标题中将Content-Type设置为application/json,并在正文中设置以下自适应卡片组.

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "speak": "Nothing to say.",
  "body": [
    {
      "type": "TextBlock",
      "text": "Hello Teams' user"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

有了这个,我收到400错误请求和"摘要或文本是必需的"消息.有没有人知道Teams webhooks是否支持自适应卡还是目前这是一项不受支持的任务?

chr*_*ris 19

我正在使用axios将自适应卡发送到 Teams 连接器,但遇到了同样的错误。就我而言,我能够通过将卡包装为此链接中显示的消息协议的“附件”来解决该问题(此处复制的语法以供参考)。

https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#send-adaptive-cards-using-an-incoming-webhook

{
   "type":"message",
   "attachments":[
      {
         "contentType":"application/vnd.microsoft.card.adaptive",
         "contentUrl":null,
         "content":{
            "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
            "type":"AdaptiveCard",
            "version":"1.4",
            "body":[
                {
                "type": "TextBlock",
                "text": "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)"
                }
            ]
         }
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

通过发送上述 JSON 作为请求正文(dataaxios 的参数),我成功地将自适应卡显示在我的团队频道中。

可以看到, 的值"content"就是Adaptive Card 结构。自适应卡遵循记录的语法,可在此处找到:

https://learn.microsoft.com/en-us/adaptive-cards/authoring-cards/getting-started

https://learn.microsoft.com/en-us/answers/questions/400502/adaptive-cards-with-incoming-webhooks-in-microsoft.html

但最终,我发现使用这个提供所见即所得界面的“设计器” https://www.adaptivecards.io/designer/更容易工作。

我将按照此处的说明将请求发送到我在 Teams 中创建的连接器:

https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#create-incoming-webhook-1

现在它响应 200 OK 并显示在频道中!


Bil*_*SFT 13

Webhooks还不支持自适应卡.我们计划在我们为机器人发布自适应卡后立即添加对自适应卡的支持.

  • 刚刚遇到这个问题 - 请添加对这些ASAP的支持,因为文档令人困惑,你可以和不能发送到webhook!一切都说"嘿,使用这些令人敬畏的新自适应卡!".`(` (8认同)
  • 好像2021年了还是没有支持???我刚刚尝试使用他们的示例模板并得到相同的错误。 (5认同)
  • 你知道微软团队什么时候不参加Beta测试吗? (4认同)
  • 厌倦了以下文档来结束这里. (3认同)
  • 究竟。从字面上复制并粘贴。微软走下坡路。 (2认同)

Ste*_*han 9

对于简单的用例,将其发布到 webhook url:

{
  "title": "Action News",
  "text": "not **much** happend (markdown)"
}
Run Code Online (Sandbox Code Playgroud)

对于高级用例,请尝试使用 MessageCard:https : //docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using

例子:

{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "Larry Bryant created a new task",
"sections": [{
    "activityTitle": "![TestImage](https://47a92947.ngrok.io/Content/Images/default.png)Larry Bryant created a new task",
    "activitySubtitle": "On Project Tango",
    "activityImage": "https://teamsnodesample.azurewebsites.net/static/img/image5.png",
    "facts": [{
        "name": "Assigned to",
        "value": "Unassigned"
    }, {
        "name": "Due date",
        "value": "Mon May 01 2017 17:07:18 GMT-0700 (Pacific Daylight Time)"
    }, {
        "name": "Status",
        "value": "Not started"
    }],
    "markdown": true
}],
"potentialAction": [{
    "@type": "ActionCard",
    "name": "Add a comment",
    "inputs": [{
        "@type": "TextInput",
        "id": "comment",
        "isMultiline": false,
        "title": "Add a comment here for this task"
    }],
    "actions": [{
        "@type": "HttpPOST",
        "name": "Add comment",
        "target": "http://..."
    }]
}, {
    "@type": "ActionCard",
    "name": "Set due date",
    "inputs": [{
        "@type": "DateInput",
        "id": "dueDate",
        "title": "Enter a due date for this task"
    }],
    "actions": [{
        "@type": "HttpPOST",
        "name": "Save",
        "target": "http://..."
    }]
}, {
    "@type": "ActionCard",
    "name": "Change status",
    "inputs": [{
        "@type": "MultichoiceInput",
        "id": "list",
        "title": "Select a status",
        "isMultiSelect": "false",
        "choices": [{
            "display": "In Progress",
            "value": "1"
        }, {
            "display": "Active",
            "value": "2"
        }, {
            "display": "Closed",
            "value": "3"
        }]
    }],
    "actions": [{
        "@type": "HttpPOST",
        "name": "Save",
        "target": "http://..."
    }]
}]
}
Run Code Online (Sandbox Code Playgroud)


小智 5

您实际上可以将自适应卡体发送到该结构的主体数组内:

{
"type": "message",
"attachments": [
    {
        "contentType": "application/vnd.microsoft.card.adaptive",
        "contentUrl": null,
        "content": {
            "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
            "type": "AdaptiveCard",
            "version": "1.4",
            "body": [
                
            ]
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

}

参考资料:微软