Answer the question
In order to leave comments, you need to log in
Who has a working solution for the sendMediaGroup telegram bot in pure php without libraries?
As it turned out, finding a working example is very difficult.
I send one photo without problems, but with several I got stuck very much, and I tried this and that, but to no avail.
Searches on the net also did not lead to a positive result, I found such an example and tried to apply it, removing obvious errors (although it was said that it was working), but in the end nothing (
$url = "https://api.telegram.org/bot" . "TOKEN" . "/sendMediaGroup";
$postContent = [
'chat_id' => "ID",
'media' => json_encode([
['type' => 'photo', 'media' => 'attach://data.jpg' ],
['type' => 'photo', 'media' => 'attach://data.jpg' ],
]),
'data1.jpg' => new CURLFile(realpath("/var/www/html/data.jpg")),
'data.jpg' => new CURLFile(realpath("/var/www/html/data.jpg")),
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postContent);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
$result = curl_exec($curl);
curl_close($curl);
$url = "https://api.telegram.org/bot" . $api . "/sendMediaGroup";
$url_1 = $src_to_img . '1620919407-file_555.jpg';
$url_2 = $src_to_img . '1620919409-file_556.png';
$url_3 = $src_to_img . '1620919407-file_557.jpg';
$postContent = [
'chat_id' => $chat_id,
'media' => json_encode([
['type' => 'photo', 'media' => 'attach://1620919407-file_555.jpg' ],
['type' => 'photo', 'media' => 'attach://1620919409-file_556.png' ],
['type' => 'photo', 'media' => 'attach://1620919410-file_557.jpg' ]
]),
'1620919407-file_555.jpg' => new CURLFile(realpath($url_1)),
'1620919409-file_556.png' => new CURLFile(realpath($url_2)),
'1620919410-file_557.jpg' => new CURLFile(realpath($url_3))
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postContent);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
$result = curl_exec($curl);
curl_close($curl);
$src_to_img = "/var/www/www-root/data/www/mytelegrambot.club/escooter/img/users_img/";
Answer the question
In order to leave comments, you need to log in
"'Content-Type: multipart/form-data'" is set automatically when transferring files, and why are you suffering with an attachment? Sending it all the same from a web server would send links. And what you are passing is just the contents of the Message
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question