【发布时间】:2019-10-21 00:28:50
【问题描述】:
我将 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 的有效负载过长造成的。
当 JSON 负载超过 18000 个字符时,初始复杂消息(部分、标题、副标题、格式化链接、<pre> 格式化文本等)失败。
对有效负载进行一些测试后发现,我从原始 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": "me@company.com"
}
]
},
{
"activityTitle": "Job failed step logs part 1",
"text": "<pre>...very long log text goes here ...</pre>"
}
]
}
Microsoft Teams 连接器 webhook 发布消息的实际最大长度是多少?
official page 没有提及。在底部的反馈部分中,仍有一个关于“邮件大小限制?”的悬而未决的问题。反馈:“我们目前正在对此进行调查。”
【问题讨论】:
-
这里的一个关键观察是 Webhook 端点返回状态代码 200 并且这些错误消息是响应正文的一部分。即使在速率限制部分的速率限制(docs.microsoft.com/en-us/microsoftteams/platform/…)的情况下,也有代码 sn-p 表示我们需要检查内容正文
标签: json limit webhooks microsoft-teams payload