Effortlessly upload and fetch files from Telegram 🚀
-
Clone The Repository
git clone https://github.com/TeaByte/telegram-upload-api cd telegram-upload-api
-
Edit The config.json File
In the
config.json
file, update the following fields with your Telegram credentials and bot information:{ "apiId": 143..., "apiHash": "bd4fed...", "chatId": -10021442..., "botToken": "1234585269:AAGL9o....", "serverPort": 8080 }
- Replace
your_api_id
andyour_api_hash
with your Telegram credentials from https://my.telegram.org/auth. - Obtain a bot token from @BotFather and replace
your_bot_token
. chatId
is the ID of a Telegram group where files will be saved ( You can get it from @WhatChatIDBot ).
- Replace
-
Start The Server
deno task start
-
Test The Server Endpoints
deno task test
The Telegram Upload API provides the following endpoints:
- Endpoint:
/upload
- Method:
POST
- Parameters:
file
: The file to be uploaded (multipart form data)
curl -X POST -F "file=@/path/to/file.txt" http://localhost:8080/upload
{
"message": "File uploaded successfully",
"fileId": "the_file_id",
"file": {
"size": 12345,
"name": "file.txt"
}
}
- Endpoint:
/fetch
- Method:
GET
- Parameters:
fileId
: The unique identifier for the file recordmainFileName
(Optional): The name to use when downloading the file
curl http://localhost:8080/fetch?fileId=the_file_id
The file content is streamed back as a download.