rveachkc / pymsteams

Format messages and post to Microsoft Teams.
https://pypi.org/project/pymsteams/
Apache License 2.0
422 stars 78 forks source link

Not getting expected response from connectorcard::send #75

Closed stmoody closed 4 years ago

stmoody commented 4 years ago

Describe the bug When the content of a message being sent is too large the message won't be posted to Teams, but send still return True.

To Reproduce This seems to be caused by the amount of chars\bytes sent in the message. I've repro'd it by forming card sections with bulleted strings of notes (between 48-52 chars).

Expected behavior I would like to get enough information from a bad http request so that if the message is too large to send, I can break it into multiple smaller messages that will send.

rveachkc commented 4 years ago

To fix the root cause, Microsoft would need respond with a code indicating the failure. Because of this, i'm going to go ahead and close the issue.

If you can uncover the exact max message length and care to submit a pull request limiting this in code, I'd be happy to review.

stmoody commented 4 years ago

I did use a script to verify the size constraints, and I'll detail it below if it's interesting, but I talked with the Teams team and believe I found a better way.

It seems the reason for the 200 status in cases where the message doesn't send is due to 3rd party connectors, incorrectly, handling errors by deleting the configuration.

tl;dr The team let me know that the content of the response will be '1' when the message is sent successfully. So I propose updating the check before returning in send from if r.status_code == requests.codes.ok: to if r.status_code == requests.codes.ok and r.text == '1': end tl;dr

teams_uri = <<webhook>>
import pymsteams

# x = 20811 # stops sending at 20,812
x = 20827 # stops sending w\o title at 20,828
crd = pymsteams.cardsection()
crd.text('x' * x)
msg = pymsteams.connectorcard(teams_uri)
# msg.title(x)
msg.summary('0') # adding characters stops it
msg.addSection(crd)
msg.send()

It's seemingly the combined data size sent that effects it Without a summary, I get an exception so I'm using a single char for that (more characters would then mean removing others from the cardsection text or title, but it's not 1-for-1 i.e. a summary of '00' won't work if a "bare text message" is sent w\ 20826 characters With a title that was the count of characters sent, the limit is 20,811 chars W\o a title the limit bumps up to 20,827

rveachkc commented 4 years ago

Fair enough. I've re-opened it, and can look at this when I get a chance. Honestly, it might be a bit, so pull requests are welcome.

stmoody commented 4 years ago

I've created the change locally and added a test. Do I need certain permissions to create a PR\branch? I'm getting a 403 error. Sorry, first time I'm contributing to someone else's GitHub project

rveachkc commented 4 years ago

This is now merged and released under v0.1.14. Thanks!