unreal4u / telegram-api

Complete async capable Telegram bot API implementation for PHP7
https://github.com/unreal4u/telegram-api/wiki
MIT License
784 stars 172 forks source link

EditMessageMedia method not working #112

Open MrDarkest opened 4 years ago

MrDarkest commented 4 years ago

Which version are you using?

3.5.0

Description of problem

EditMessageMedia method doesn't work.

I've tried with this code:

$editMessageMedia = new EditMessageMedia();
$editMessageMedia->chat_id = "@channelname"
$editMessageMedia->message_id = $message_id;
$photo = new Photo();
$photo->media = "https://my-host/image.png"
$photo->caption = "A caption";
$photo->parse_mode = "Markdown";
$editMessageMedia->media = $photo;
$promise = $tgLog->performApiRequest($editMessageMedia);
$promise->then(
    function () {
        },
        function (\Exception $exception) {
           error_log($exception->getMessage());
       }
);
$loop->run();

But it always fails with the error: "Bad Request: can't parse InputMedia: Media is not specified".

With the same parameters the classic POST call to telegram api with a JSON body works fine.

$boturl = "https://api.telegram.org/bot".TELEGRAM_BOT_KEY."/editMessageMedia";
$bodyobj = ["chat_id" => $chat_id, "message_id" => $message_id, "media" => ["type" => "photo", "media" => $url, "caption" => $caption, "parse_mode" => "Markdown"]];
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,            $boturl );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST,           1 );
curl_setopt($ch, CURLOPT_POSTFIELDS,     json_encode($bodyobj) ); 
curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: application/json')); 

$result=curl_exec ($ch);
unreal4u commented 4 years ago

This should work right out of the box. Will take a look at it once my pc is fixed.

Thanks!