Answer the question
In order to leave comments, you need to log in
Is it possible to send a file to telegram through the site form?
There was an idea to send files from the site's feedback form to the telegram bot. There is a text sending script, is it possible to implement sending files to telegrams? and how, in php I'm not strong.
<?php
$email = $_POST['user_email'];
$message = $_POST['text'];
$txt = "";
$token = "XXXXXXXXXXXXXXXXXXXXXXX";
$chat_id = "XXXXXXX";
$arr = array(
'Email' => $email,
'Сообщение' => $message,
);
foreach($arr as $key => $value) {
$txt .= "<b>".$key."</b> ".$value."%0A";
};
$sendToTelegram = fopen("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&parse_mode=html&text={$txt}","r");
if ($sendToTelegram) {
header('Location: thank-you.html');
} else {
echo "Error";
}
?>
Answer the question
In order to leave comments, you need to log in
Yes, you can. Use the sendDocument method from bot api. Everything is similar to how you use sendMessage now .
https://core.telegram.org/bots/api#senddocument
https://core.telegram.org/bots/api#inputfile
https://core.telegram.org/bots/api#sending-files
Upload limit files via
bot -api -
50Mb .madelineproto.xyz/docs/FILES.html#upl...
If, in principle, there is no understanding of how to initially accept the file sent through the form, then read about
https://www.w3schools.com/php/php_file_upload.asp
What does " send {...} to telegram bot " mean? What is this bot, where is it running (on the same machine as the site; or somewhere else on a machine accessible via the network)?
In general, a file can be converted to text (conversion methods - Base64, UUEncode). The data sent to the bot can be formatted in such a way that it can understand where everything is (for example, MIME). The methods mentioned in the answer are used in email and HTTP.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question