hello everyone I was tring to send files using my bot like http://api.telegram.org/botTOKEN/sendDocument?document=http://my_path&chat_id
but it ain't support .txt .docx..... and other formats..... any help please
Asked
Active
Viewed 1,573 times
0

user13396528
- 11
- 1
-
What exactly do you mean under "pure HTTP"? – VSMent May 17 '20 at 06:47
-
I mean without using any library – user13396528 May 17 '20 at 07:24
-
Without any library but still with some programming (if so depends on language) or pure HTTP i.e. web browser / something like postman? – VSMent May 17 '20 at 12:50
-
Pure HTTP, I would like to know the basics (am asking this for learning purpose)..... to be more clear, am coding PHP and am using file_get_contents("http://api.telegram.org/botTOKEN/").... but I don't know what to put next in order to support all kinds of files – user13396528 May 18 '20 at 14:30
-
I have updated my answer with some code from existing telegram PHP library I use. There might be your answer – VSMent May 20 '20 at 16:09
1 Answers
0
According to https://core.telegram.org/bots/api#sending-files
Sending by URL In sendDocument, sending by URL will currently only work for gif, pdf and zip files.
You may try to use this approach
Post the file using multipart/form-data in the usual way that files are uploaded via the browser. 10 MB max size for photos, 50 MB for other files.
This answer might give you some ideas on how to do that.
UPDATE
It is also good idea to use someone's library to understand how it works there.
For example, I use longman/telegram-bot
from this repo. There is encodeFile
method in Request class.
Method is follows:
public static function encodeFile($file)
{
$fp = fopen($file, 'rb');
if ($fp === false) {
throw new TelegramException('Cannot open "' . $file . '" for reading');
}
return $fp;
}
Which means simple fopen
method with 'rb'
parameter is enough to convert file.

VSMent
- 376
- 4
- 11