EvotecIT / PSTeams

PSTeams is a PowerShell Module working on Windows / Linux and Mac. It allows sending notifications to Microsoft Teams via WebHook Notifications. It's pretty flexible and provides a bunch of options. Initially, it only supported one sort of Team Cards but since version 2.X.X it supports Adaptive Cards, Hero Cards, List Cards, and Thumbnail Cards. All those new cards have their own cmdlets and the old version of creating Teams Cards stays as-is for compatibility reasons.
MIT License
409 stars 41 forks source link

Microsoft Teams endpoint returned HTTP error 500 not caught #34

Closed nsleigh closed 3 days ago

nsleigh commented 3 years ago

First thanks for publishing this module, it has made Teams integration much easier.

I have found an issue with the code that would be useful to handle. If you send a message to Teams and the body is too large (>17000 characters) then you get this message:

WARNING: Send-TeamsMessage - Couldn't send message. Execute message: Webhook message delivery failed with error: Microsoft Teams endpoint returned HTTP error 500 with ContextId tcid=0,server=msgapi-production-neu-azsc4-2-88,aa=Oxdgc+LR2kAAqmLcffH/jg.0,MS-CV=Oadgc+LA1kAVqmLcffH/jg.0..

But it doesn't set any error variable that can be tested. I think this is because Invoke-RestMethod doesn't throw an error for HTTP status 500. Not sure how best to handle this but may be the code should "throw" on this status.

PrzemyslawKlys commented 3 years ago

If you will use Send-TeamsMessage -ErrorAction Stop it should stop. Basically, all errors are swallowed as Warnings by default, but you can decide to stop on all errors and handle them yourself. Try it out - maybe it works... if not I can check things out.

nsleigh commented 3 years ago

When I call the function I set "-ErrorVariable teamsError -ErrorAction SilentlyContinue" this allows me to review testsError for non-500 issues. If I set "-ErrorAction Stop" it prints a message but doesn't return anything that can be tested.

Guess this is a change of design in some respects, I am using the code for a long running process and want to be able to review a log if there are issues.

PrzemyslawKlys commented 3 years ago

why not do WarningVariable/WarningAction then?

nsleigh commented 3 years ago

Every day's a school day - I had complete missed those parameters from any PowerShell I have done. That works perfectly, thanks.

tomabg commented 3 years ago

Hi,

i also had some struggle with this limit but could avoid it finaly by another structure of the data.

Is there an easy to use possibility to count the characters of the message(i use Verbose and copy it to notepad++ and remove all spaces and then count it)

BR Thomas

PrzemyslawKlys commented 3 years ago

We could probably add information in verbose about the current length limit.

As for the limits:

Not sure how accurate this is. Can't you simply split it into 2 separate API calls?

tomabg commented 3 years ago

yeah done this already ..however some hint or INFO would be cool...probably yes add the number of characters to VERBOSE