我正在将 CI/CD 系统的结果/日志发布到 Microsoft Teams。在处理一些具有较长结果的失败构建时,我偶然发现了 webhook URL 返回的以下错误https://outlook.office.com/webhook/bb6bfee7-1820-49fd-b9f9-f28f7cc679ff@<uuid1>/IncomingWebhook/<id>/<uuid2>
:
Webhook message delivery failed with error: Microsoft Teams endpoint returned HTTP error 413 with ContextId tcid=3626521845697697778,server=DB3PEPF0000009A,cv=BmkbJ1NdTkv1EDoqr7n/rg.0..
据我观察,这是由于发布到 Teams webhook URL 的负载过长造成的。
最初的复杂消息(部分、标题、副标题、格式化链接、<pre>
当 JSON 有效负载超过 18000 个字符时,格式化文本等)会失败。
对有效负载进行了一些测试,我发现从原始 JSON 有效负载中删除的格式越多,Teams 消息就越长。我可以发布的最长消息有(根据 cu cURL):Content-Length: 20711
。此消息的 JSON 有效负载为:
{"themeColor":"ED4B35","text":"a....a"}
JSON 格式中的空格似乎不算数(即添加空格不会减少我可以发送到 Teams webhook 的最大消息长度)。
作为参考,最初的消息看起来与此类似:
{
"themeColor": "ED4B35",
"summary": "iris-shared-libs - shared-library-updates - failure",
"sections": [
{
"activityTitle": "Job: [iris-shared-libs](https://my.concourse.net/teams/hsm/pipelines/iris-shared-libs) - [shared-library-updates #89](https://my.concourse.sccloudinfra.net/teams/hsm/pipelines/iris-shared-libs/jobs/shared-library-updates/builds/89) (FAILURE)",
"activityImage": "https://via.placeholder.com/200.png/ED4B35/FFFFFF?text=F",
"facts": [
{
"name": "Failed step",
"value": "update-shared-libraries"
}
]
},
{
"text": "Trying a new strategy with gated versioned releases",
"facts": [
{
"name": "Repository",
"value": "[iris-concourse-resources](https://my.git.com/projects/IRIS/repos/iris-concourse-resources)"
},
{
"name": "Commit",
"value": "[2272145ddf9285c9933df398d63cbe680a62f2b7](https://my.git.com/projects/IRIS/repos/iris-concourse-resources/commits/2272145ddf9285c9933df398d63cbe680a62f2b7)"
},
{
"name": "Author",
"value": "[email protected] /cdn-cgi/l/email-protection"
}
]
},
{
"activityTitle": "Job failed step logs part 1",
"text": "<pre>...very long log text goes here ...</pre>"
}
]
}
Microsoft Teams 连接器 Webhook 发布消息的实际最大长度是多少?
The 官方网站 https://learn.microsoft.com/en-us/microsoftteams/limits-specifications-teams没有提到它。在底部的反馈部分中,仍然有一个关于“消息大小限制?”的悬而未决的问题。反馈:“我们目前正在调查此事。”