Telegram: Send files using InputFile(binary data) [GOT CREATED]

As far as I know, you can send to the file to telegram not only with file_id or URL link to the file.
To send binary data according to the documentation, you need to use InputFile.

InputFile
This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser.

Example Curl query:

curl --location --request POST 'https://api.telegram.org/bot-key/sendPhoto' \
--header 'Content-Type: application/json' \
--form '[email protected]"/home/image.png"' \
--form 'chat_id="chat_id"'

Can this feature be added to the following methods?

  • sendPhoto
  • sendDocument
  • sendAudio
  • sendVideo

Can you tell me how difficult it is to make this improvement?
Now I have to use S3 to send files, and it is very expensive.

I had a quick look and it’s not difficult. It’s most about available time.

1 Like

Hi!
You can’t get it in the near future to refine it?

Keeping an S3 server to send files to the cart is quite wasteful…

@a1ekseev
Please consider these options: MinIO and Wasabi.

They both use S3 compatible API but MinIO is self hosted and Wasabi.com is about 80% cheaper than S3! with free egress. At last look It’s $5.99/TB/m

Wasabi is fantastic and super fast, MinIO is easy to setup and I believe Linode (and other providers) have one-click options for it, as well as their own S3 type storage called Object Storage (and an API).

I do not see the point of keeping a repository of files, just to send binary data to the chat telegram.

There could be another option…

@pemontto put this together the other day, it just needs to be checked and merged and you will be good to go: https://github.com/n8n-io/n8n/pull/2247

2 Likes

I just reviewed the PR that @jon mentioned and made some changes. It will probably be available in the next release.

1 Like

Thank you!
Very much looking forward to it.

Hey I had the same issue as you so wrote the PR. However as a workaround you can still perform the binary upload with an HTTP Request node. Try this:

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://api.telegram.org/bot<BOT KEY>/sendPhoto",
        "jsonParameters": true,
        "options": {
          "bodyContentType": "multipart-form-data"
        },
        "sendBinaryData": true,
        "binaryPropertyName": "photo:<BINARY PARAMETER>",
        "queryParametersJson": "={\n    \"chat_id\": \"<CHAT ID>\",\n    \"caption\": \"xyz\"\n}"
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        90,
        700
      ],
      "alwaysOutputData": false,
      "notesInFlow": true,
      "notes": "Send photo to Telegram"
    }
  ],
  "connections": {}
}
4 Likes

Thanks very much for the contribution @pemontto. Good to see you here in the community.

1 Like

Got released with [email protected]

1 Like

Just convert it once it arrives?

Try this, ignore the IMAP part, but it’s about turning a file into Binary: