3
votes

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
One of the key observation here is that Webhook end point returns status code 200 and these error message are part of the response body . Even in case of rate limit as well (docs.microsoft.com/en-us/microsoftteams/platform/…) in the Rate limit section there is code snippet which says we need to check the content bodyDevesh

1 Answers

5
votes

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.