Skylar-Tech / node-red-contrib-matrix-chat

Matrix chat server support for Node-RED
GNU General Public License v3.0
31 stars 10 forks source link

[Question] Send image and text in one message #43

Closed hillbicks closed 2 years ago

hillbicks commented 2 years ago

Hey there,

I'm struggling to send a message with text and a picture to a matrix chat. I tried to send the mail as HTML formatted, but apparently there is an open issue that this doesn't work at the moment. Well, it kinda works, but only in the android client it seems. Both element desktop and web clients are not showing the images.

Is there a way to send (formatted) text alongside a picture with this addon for node-red?

PS: I hope it's ok I opened up an issue for a question, but since there is no discussion tab available, I figured I ask here.

skylord123 commented 2 years ago

You can't attach a message to the image, you will need to use a send message node either before or after the image sends. I have this attached to my security system and what I do is send a message of the event (example: Front door opened at 6:00AM) then I send the nearest security camera image to the room.

You can set msg.filename or msg.body on the input of the send image node. In practice the body gets used for both the filename and as text that renders in the client but only if the image is replied to:

If you reply to an image with a body set it will display the body next to the image when replying like so (in this case msg.body was set to "this is the test body"): image And once it is posted it looks like this: image

But as you can see the body didn't render on the initial image and only on replies. In this case I also set the filename to filename.png but if you download the image from element it auto fills the name as "this is the body.png". The filename is only used for naming the file in the Matrix storage (and is pretty much useless because of this but I left it anyways).

According to the Matrix Spec the body is:

A textual representation of the image. This could be the alt text of the image, the filename of the image, or some kind of content description for accessibility e.g. ‘image attachment’.

Hope this answers your question :)