Microsoft Teams Webhook为自适应卡生成400

时间:2018-06-08 03:47:54

标签: microsoft-teams adaptive-cards

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

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

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

4 个答案:

答案 0 :(得分:10)

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

答案 1 :(得分:5)

对于简单用例,请将其发布到webhook网址:

user:{SHA}qUqP5cyxm6YcTAhz05Hph5gvu9M=

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

示例:

{
  "title": "Action News",
  "text": "not **much** happend (markdown)"
}

答案 2 :(得分:0)

最近,我遇到了同样的问题,正在寻找解决方案。好消息是MS团队现在支持自适应卡 youtube video to explain how it can be implemented

Github link to track the progress on the issue

我成功地将消息发送到了Teams频道。

答案 3 :(得分:0)

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

https://docs.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.2",
            "body":[
                {
                "type": "TextBlock",
                "text": "For Samples and Templates, see [https://adaptivecards.io/samples](https://adaptivecards.io/samples)"
                }
            ]
         }
      }
   ]
}

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

如您所见,"content" 的值是自适应卡片结构。 Adaptive Card 遵循文档化的语法,可在此处找到:

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

但最终,我发现与这位“设计师”合作更容易https://www.adaptivecards.io/designer/ 提供所见即所得的界面。

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

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

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

相关问题