signal-cli-rest-api icon indicating copy to clipboard operation
signal-cli-rest-api copied to clipboard

Sending a image

Open SaschMie opened this issue 2 years ago • 4 comments

The problem

Actual im trying this docker and try to send a json like this:

{ "message": "{{event}} \n{{subject}} \n{{message}} \n{{image}}", "number": "+0000", "recipients": [ "+000000" ] }

The image is a url to a JPG and it just shows the url and not the image. How to get the image shown in the message ?

Are you using the latest released version?

  • [x] Yes

Have you read the troubleshooting page?

  • [x] Yes

What type of installation are you running?

signal-cli-rest-api Docker Container

In which mode are you using the docker container?

Native Mode

What's the architecture of your host system?

x86-64

Additional information

No response

SaschMie avatar Feb 28 '23 09:02 SaschMie

Do you add the base64 encoded image data to the JSON payload?

bbernhard avatar Mar 01 '23 22:03 bbernhard

No the image is there ist just a url with a JPEG, so it needs to be a base64 ?

SaschMie avatar Mar 02 '23 08:03 SaschMie

yeah, it needs to be base64 encoded.

bbernhard avatar Mar 03 '23 15:03 bbernhard

I'm trying to figure out signal-cli-rest-api and it's taking a lot of time, I'm failing a lot, this is a new area for me. Therefore, I will try to write in the discussion everything that I succeeded and did not succeed, so that it would be easier for other people. Moreover, some of the official examples are non-working. In particular, I was unable to send a picture, as indicated in the example: https://github.com/bbernhard/signal-cli-rest-api/blob/master/doc/EXAMPLES.md Send a message with a base64 encoded attachment e.g: TMPFILE="$(base64 SignalsPictures/flow.png)" curl -X POST -H "Content-Type: application/json" -d '{"message": "Test image", "base64_attachments": ["' "${TMPFILE}"'"], "number": "+123456789012", "recipients": ["+123456789012"]}' 'http://localhost:8080/v2/send' Answer: "error":"Couldn't process request - invalid request"

I decided to send another file: TMPFILE="$(base64 SignalsPictures/1.jpg)" curl -X POST -H "Content-Type: application/json" -d '{"message": "Test image", "base64_attachments": ["'"$ {TMPFILE}"'"], "number": "+123456789012", "recipients": ["+123456789012"]}' 'http://localhost:8080/v2/send' Answer: /bin/sh: 47: curl: Argument list too long

Send a message (+ base64 encoded attachment) to multiple recipients curl -X POST -H "Content-Type: application/json" -d '{"message": "", "base64_attachments": [""], "number": "", "recipients": ["", ""]}' 'http://127.0.0.1:8080/v2/send' curl -X POST -H "Content-Type: application/json" -d '{"message": "Test Message", "base64_attachments": ["SignalsPictures/1.jpg"], "number": "+123456789012" , "recipients": ["+123456789012"]}' 'http://localhost:8080/v2/send' Answer: "error":"illegal base64 data at input byte 17"

I thought the file must be encoded and found this question on Stackoverflows: https://stackoverflow.com/questions/75420538/base64-conversion-in-context-with-curl docker terminal

  1. base64 "SignalsPictures/flow.png" --wrap=0 > "1_crc.png"
  2. curl -X POST -H "Content-Type: application/json" -d '{"message": "Test image", "base64_attachments": ["1_crc.png"], "number": "+123456789012" , "recipients": ["+123456789012"]}' 'http://localhost:8080/v2/send' Answer: "error":"illegal base64 data at input byte 1"

I eventually found this discussion thread and tried sending the encoded file: TMPFILE="$(base64 1_crc.png)" && echo '{"message": "Test message", "base64_attachments": ["'"$TMPFILE"'"], "number": "+123456789012", "recipients ": ["+123456789012"]}' | curl -X POST -H "Content-Type: application/json" -d @- 'http://localhost:8080/v2/send' Answer: I received the file, but with the name 93a81d4a-...-f5e9613e18ce.txt and the value (content) of this file has been changed.

Thanks to user @UliEi, I was able to easily send an image to a group via Docker Terminal: TMPFILE="$(base64 SignalsPictures/flow.png)" && echo '{"message": "Test message", "base64_attachments": ["'"$TMPFILE"'"], "number": "+123456789012", "recipients": ["group.e..0="]}' | curl -X POST -H "Content-Type: application/json" -d @- 'http://localhost:8080/v2/send'

Forgive me for my French.

StanisGit avatar Jul 03 '23 15:07 StanisGit