PSTeams
PSTeams copied to clipboard
Microsoft Teams endpoint returned HTTP error 500 not caught
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.
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.
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.
why not do WarningVariable/WarningAction then?
Every day's a school day - I had complete missed those parameters from any PowerShell I have done. That works perfectly, thanks.
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
We could probably add information in verbose about the current length limit.
As for the limits:
- https://stackoverflow.com/questions/58474127/how-long-can-messages-be-when-posting-to-a-microsoft-teams-connector-webhook
- https://github.com/microsoft/BotFramework-Services/issues/228
- https://docs.microsoft.com/en-us/microsoftteams/limits-specifications-teams#teams-and-channels
Not sure how accurate this is. Can't you simply split it into 2 separate API calls?
yeah done this already ..however some hint or INFO would be cool...probably yes add the number of characters to VERBOSE