How long can messages be when posting to a Microsoft Teams connector webhook?

拈花ヽ惹草 提交于 2019-12-11 05:32:55

问题


I am posting the results/logs of a CI/CD system to Microsoft Teams. While handling some failed builds with longer results, I stumbled upon the following error returned by the 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..

As I observe, this is caused by too long payload posted to the Teams webhook URL.

The initial complex message (sections, titles, subtitles, formatted links, <pre> formatted text, etc.) was failing when the JSON payload was a above 18000 characters.

Testing a bit with the payload I observed that the more formatting I remove from the raw JSON payload, the longer can the Teams message be. The longest message I could post had (according cu cURL): Content-Length: 20711. The JSON payload for this message was:

{"themeColor":"ED4B35","text":"a....a"}

whitespaces in the JSON format seem not to count (i.e. adding spaces will not decrease the maximum message length that I can sent to the Teams webhook).

For reference, the initial message was looking similar to this:

{
    "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>"
        }
    ]
}

What is the actual maximum lengths of the Microsoft Teams connector webhook posted message?

The official page does not mention it. In the Feedback section at the bottom there is still an open question regarding "Messages size limits?" with the feedback: "We are currently investigating this."


回答1:


From the tests I made so far, some limits observed (if this is independent of the server) are roughly, based on the JSON message payload (structure and formatting) between 18000 and 40000 (with length below 18000 never breaking and above 40000 always breaking).

  • Use case 18000: one long text for a section
  • Use case 40000: 600 facts with very short name and empty string as value

And removing a fragment of the JSON payload and adding an equal number of characters in another JSON value will not give you the same maximum.

I have observed a soft limit (message truncated, but no error) as well on the maximum number of sections: 10. The sections starting with the 11th are discarded.



来源:https://stackoverflow.com/questions/58474127/how-long-can-messages-be-when-posting-to-a-microsoft-teams-connector-webhook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!