rveachkc / pymsteams

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

How could we include images from our computer? #19

Open ManuMillenaar opened 6 years ago

ManuMillenaar commented 6 years ago

It's only possible to add images from a URL, right?

Also, the hero image in the center would be super cool to have, if possible.

Thanks so much!

kapkanov commented 2 years ago

You should encode image via base64

with open("path/to/image.jpg", "rb") as img_file: 
  encoded = base64.b64encode(img_file.read()).decode('ascii')
Session1.activityImage("data:image/jpeg;base64, "+str(encoded))
reesehopkins commented 2 years ago

Thanks @apolivin, this works for me. However, I get a 400 error when the image is too large. This might be related to #34

GitRon commented 2 years ago

The image within this activity is tiny. Is there a way to post a properly-sized image?

GitRon commented 2 years ago

OK, maybe you could update the docs that you can easily use HTML for larger images? 🙈 Thx for the great package!

LeonardoSanBenitez commented 2 years ago

You can include an image as HTML, in a text block, as follows:

myTeamsMessage.text("<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />")
GitRon commented 2 years ago

@LeonardoSanBenitez I know how to do it now but it's not mentioned in the docs 😃

chongjae commented 2 years ago

I want to attach about 119Kb png file. But, when i sent image, teams show below msg.

This message is too long to display here. Please visit the external source app to view the message.

How can i attach image?

rveachkc commented 2 years ago

I want to attach about 119Kb png file. But, when i sent image, teams show below msg.

This message is too long to display here. Please visit the external source app to view the message.

How can i attach image?

It's a limitation of the api. The error message is suggesting you make the image available via external service, then link to it.