sendMediaGroup telegram PHP

Viewed 40

I am using telegram library

php telegram bot sdk

And I want to send some photos in message using sendMediaGroup

Like this:

$reply = "*photos*";
$telegram->sendMediaGroup([
     'chat_id' => $chat,
     'media' => [
      ['type' => 'photo', 'media' => 'attach://photo1' ],
      ['type' => 'photo', 'media' => 'attach://photo2' ],
  ],
     'photo1' => InputFile::create(file_get_contents("https://".$_SERVER['SERVER_NAME']."/newbot/screens/ctry/en1.jpg")),
     'photo2' => InputFile::create(file_get_contents("https://".$_SERVER['SERVER_NAME']."/newbot/screens/ctry/en2.jpg")),
     'caption'=> $reply,
     'parse_mode' => 'markdown'
     ]);

I used without json_encode and file_get_contents, but it doesn't worked too

1 Answers

Why do you use that library? Here's the normal solution:

$token = '   TOKEN   ';
$website = 'https://api.telegram.org/bot'.$token;
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$message = $update['message']['text'];
$id = $update['message']['from']['id'];
$name = $update['message']['from']['first_name'];
$surname = $update['message']['from']['last_name'];
$username = $update['message']['from']['username'];

function sendPhoto($id, $photo, $text = null){
    GLOBAL $token;
    $url = 'https://api.telegram.org/bot'.$token."/sendPhoto?chat_id=$id&photo=$photo&parse_mode=HTML&caption=".urlencode($text);
    file_get_contents($url);
}

I also put there some useful variable and the chance to put a caption (don't give that parameter if you don't want one)

Related