turt2live / matrix-bot-sdk

TypeScript/JavaScript SDK for Matrix bots
MIT License
194 stars 68 forks source link

What's the best way to include images in messages? #329

Closed nukeop closed 1 year ago

nukeop commented 1 year ago

Currently, I'm using uploadContent, and then convert the resulting mxc to a https link, and let the bot include it in the message content.

It used to just open the image in a new tab, but after a synapse update, these links now download the images by default. I see no way to revert it to the previous behavior.

However, they're displayed as an inline preview in mobile clients, so it's possible in principle.

Is it possible to make all clients show an inline preview? Is it possible to let the bot use markdown to hide the ugly, long link?

Example link: https://server.matrix.org/_matrix/media/v3/download/matrix.org/some_long_id

turt2live commented 1 year ago

The MXC URI that's returned from uploadContent should go into your m.room.message event, which sendMessage() should allow you to send. If the room is encrypted then you'll have to do a bit more work - see the example: https://github.com/turt2live/matrix-bot-sdk/blob/4c7207be2e7e5780037eb9d508783f860bb53e8b/examples/encryption_bot.ts#L71

General usage questions are best asked in the room: #matrix-bot-sdk:t2bot.io