Answer the question
In order to leave comments, you need to log in
Telegram sendMediaGroup and inline_keyboard?
I'm trying to send a group of photos with inline_keyboard and a note, I
've seen this in many chats, but something doesn't work, tell me how to do it?!
here is the code
<?php
$filePath1 = '/content/1602452074-file_331.jpg';
$filePath2 = '/content/1602521432-file_335.jpg';
$filePath3 = '/content/1601938205-file_249.jpg';
define ('TOKEN', '1460003632:9w');
$url = 'https://api.telegram.org/bot' . TOKEN . '/sendMediaGroup';
$keyboard = array(
array (array('text'=>'Key1','callback_data'=>'data1')),
);
$replyMarkup = array('inline_keyboard' => $keyboard);
$response = [
'chat_id' => '-1001446550047',
'media' => json_encode([
['type' => 'photo', 'media' => 'attach://file1.png', 'caption' => 'Комментарий' ],
['type' => 'photo', 'media' => 'attach://file2.png'],
['type' => 'photo', 'media' => 'attach://file3.png'],
]),
'file1.png' => new CURLFile(realpath($filePath1)),
'file2.png' => new CURLFile(realpath($filePath2)),
'file3.png' => new CURLFile(realpath($filePath3)),
'reply_markup' => $replyMarkup1,
];
echo sendTelegram('sendMediaGroup', $response);
function sendTelegram($method, $response){
$ch = curl_init('https://api.telegram.org/bot' . TOKEN . '/' . $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $response);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
?>
Answer the question
In order to leave comments, you need to log in
Unfortunately, this telegram method does not support sending a keyboard.
Alternatively, you can try to send another message already with the keyboard, right after that
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question